绑定文本未以xamarin形式显示

时间:2018-12-11 09:38:46

标签: xamarin xamarin.forms

内部列表项按钮ActionText在Button上添加BindingContext后未显示。 从Button移除BindingContext之后显示ActionText,但是在按钮上单击事件不起作用。

BufferedImage newImage = new BufferedImage(image.getWidth()+2*w, image.getHeight(), 
image.getType());

Graphics g = newImage.getGraphics();

g.setColor(Color.white);
g.fillRect(0,0,image.getWidth()+2*w,image.getHeight());
g.drawImage(image, w, 0, null);
g.dispose();

这是我的PageModel

<ListView x:Name="ShipmentData" 
    HasUnevenRows="True" ItemsSource="{Binding ShipmentData}" SelectedItem="{Binding SelectedShippedItem}"
    BackgroundColor="White">
        <ListView.ItemTemplate>
            <DataTemplate>
                <ViewCell>
                    <Grid Margin="0" Padding="5" x:Name="Item">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="*"/>
                        </Grid.RowDefinitions>
                        <Label Text="{Binding ShipTransId}" Grid.Row="0" IsVisible="False"/>
                        <Label Text="{Binding LabelUri}" Grid.Row="0" IsVisible="False"/>
                        <Label Text="{Binding OrderNumber}" Grid.Row="0" Grid.Column="0" HorizontalTextAlignment="Center"/>
                        <Label Text="{Binding ShippingId}" Grid.Row="0" Grid.Column="1" HorizontalTextAlignment="Center"/>
                        <Label Text="{Binding Status}" Grid.Row="0" Grid.Column="2" 
                               HorizontalTextAlignment="Center" HorizontalOptions="Center" VerticalOptions="Center"/>
                        <Button Text="{Binding ShipmentData.ActionText}" VerticalOptions="Center" 
                        HorizontalOptions="Center" BorderRadius="10"
                        Command="{Binding PrintLabel}" Grid.Row="0" Grid.Column="3" Margin="5,0,0,0"
                        BindingContext="{Binding Source={x:Reference ShipmentData}, Path=BindingContext}"
                        CommandParameter="{Binding Source={x:Reference Item}, Path=BindingContext}"/>
                    </Grid>
                </ViewCell>
            </DataTemplate>
        </ListView.ItemTemplate>
        <ListView.Behaviors>
             <eventToCommand:EventToCommandBehavior EventName="ItemTapped" Command="ShippedItemTapped"/>
        </ListView.Behaviors>
</ListView>

如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

尝试如下修改您的Xaml代码,

删除以下项目

Command="{Binding PrintLabel}" BindingContext="{Binding Source={x:Reference ShipmentData}, Path=BindingContext}" CommandParameter="{Binding Source={x:Reference Item}, Path=BindingContext}"

并使用以下代码进行更新,为您的页面命名并在“命令”中提及

 Command="{Binding Source={x:Reference yourPageName}, Path=BindingContext.PrintLabel}"
                                                        CommandParameter="{Binding .}"

在后面的代码中,如下所示更改您的PrintLabel命令属性,

Command printLabel;
    public Command PrintLabel
    {
        get
        {
            return printLabel ?? (printLabel = new Command<ShowShipmentData>(ExecuteSelected));
        }
    }

    private void ExecuteSelected(ShowShipmentData selectedItem)
    {

    }