【问题标题】:I can't run applicaton when using '<ViewCell.ContextActions>' on Xamarin Form (PCL)?在 Xamarin Form (PCL) 上使用“<ViewCell.ContextActions>”时无法运行应用程序?
【发布时间】:2017-08-12 06:57:47
【问题描述】:

严重性代码描述项目文件行抑制状态 错误位置 37:61。在 xmlns http://schemas.microsoft.com/winfx/2009/xaml Course_3 中找不到类型 Regerence

<ViewCell>
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="100"></ColumnDefinition>
                                <ColumnDefinition Width="*"></ColumnDefinition>
                            </Grid.ColumnDefinitions>

                            <Grid Grid.Column="0">
                                <Image Source="{Binding PhotoUrl}" HeightRequest="70"></Image>
                            </Grid>

                            <StackLayout Grid.Column="1" Padding="5">
                                <Label Text="{Binding FullName}" FontSize="15" TextColor="Black" Margin="0,5"></Label>
                                <Label Text="{Binding City}" FontSize="10" TextColor="Black" Margin="0,5"></Label>
                                <Label Text="{Binding JobTitle}" FontSize="10" TextColor="#CCCCCC" Margin="0,5"></Label>
                            </StackLayout>
                            <ViewCell.ContextActions>
                                <MenuItem Text="Edit" Command="{Binding Source={x:Reference Root}, Path=BindingContext.EditCommand}"
                                          CommandParameter="{Binding}"></MenuItem>
                                <MenuItem Text="Delete" Command="{Binding Source={x:Regerence Root},Path=BindingContext.DeleteCommand}"
                                          CommandParameter="{Binding}"></MenuItem>
                            </ViewCell.ContextActions>
                        </Grid>

                    </ViewCell>

【问题讨论】:

  • 如果对您有帮助,也请考虑对答案进行投票。谢谢。

标签: c# xamarin xamarin.forms


【解决方案1】:

您应该将&lt;ViewCell.ContextActions&gt; 部分移到Grid 控件之外。它必须是ViewCell 的直接子代。不知道这是否是您也在代码中创建的类型,但将第二个菜单项的 {x:Regerence Root} 更改为 {x:Reference Root}。此外,您的问题可能会受益于一些编辑以提高其整体质量。

<ViewCell> 
    <ViewCell.ContextActions>
        <MenuItem Text="Edit" Command="{Binding Source={x:Reference Root}, Path=BindingContext.EditCommand}"
                  CommandParameter="{Binding}"></MenuItem>
        <MenuItem Text="Delete" Command="{Binding Source={x:Reference Root},Path=BindingContext.DeleteCommand}"
                  CommandParameter="{Binding}"></MenuItem>
    </ViewCell.ContextActions>
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="100"></ColumnDefinition>
            <ColumnDefinition Width="*"></ColumnDefinition>
        </Grid.ColumnDefinitions>

        <Grid Grid.Column="0">
            <Image Source="{Binding PhotoUrl}" HeightRequest="70"></Image>
        </Grid>

        <StackLayout Grid.Column="1" Padding="5">
            <Label Text="{Binding FullName}" FontSize="15" TextColor="Black" Margin="0,5"></Label>
            <Label Text="{Binding City}" FontSize="10" TextColor="Black" Margin="0,5"></Label>
            <Label Text="{Binding JobTitle}" FontSize="10" TextColor="#CCCCCC" Margin="0,5"></Label>
        </StackLayout>
    </Grid>

</ViewCell>

【讨论】:

  • 没关系,但是 ListView 项目源绑定是 ItemsSource="{Binding Acquaintances}" => 当我单击菜单项时,该属性为空。
猜你喜欢
  • 2017-01-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-11-29
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多