Xaml Stackedlayout绑定中的Stackedlayout可见
我有一个xaml视图,它是一个简单的listview,单元格中有两个stackedlayouts,还有一些简单的模型绑定:Xaml Stackedlayout绑定中的Stackedlayout可见,xaml,xamarin,xamarin.forms,Xaml,Xamarin,Xamarin.forms,我有一个xaml视图,它是一个简单的listview,单元格中有两个stackedlayouts,还有一些简单的模型绑定: <?xml version="1.0" encoding="utf-8" ?> <ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:directory="clr-namespace:Directory;assembly=Directory"
xmlns:d="http://xamarin.com/schemas/2014/forms/design"
xmlns:models="clr-namespace:Directory.Models"
xmlns:controls="clr-namespace:ImageCircle.Forms.Plugin.Abstractions;assembly=ImageCircle.Forms.Plugin.Abstractions"
xmlns:viewModels="clr-namespace:Directory.ViewModels;assembly=Directory"
x:Class="Directory.Views.DirectoryList">
<ContentPage.BindingContext>
<viewModels:MasterViewModel/>
</ContentPage.BindingContext>
<ListView Margin="0,10"
ItemTapped="ListViewItem_Tabbed"
ItemsSource="{Binding PeopleCollectionGrouped}"
IsGroupingEnabled="True"
GroupDisplayBinding="{Binding Key}"
GroupShortNameBinding="{Binding Key}"
HasUnevenRows="True"
BackgroundColor="White">
<ListView.ItemTemplate>
<DataTemplate x:DataType="models:People">
<ViewCell>
<Grid
Padding="10"
ColumnSpacing="10"
RowSpacing="10">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<controls:CircleImage
Aspect="AspectFill"
BorderColor="Black"
BorderThickness="3"
HeightRequest="66"
HorizontalOptions="CenterAndExpand"
Source="{Binding PhotoUrl}"
VerticalOptions="CenterAndExpand"
WidthRequest="66" />
<StackLayout Grid.Column="1" VerticalOptions="Center">
<Label Text="{Binding FullName}" />
<Label Text="{Binding Location}" />
<StackLayout IsVisible="{Binding IsVisible}"
Orientation="Horizontal"
Margin="0,0,80,0">
<Button Text="Place Order"
WidthRequest="110"
FontSize="15"
BackgroundColor="Chocolate"
TextColor="White"/>
</StackLayout>
</StackLayout>
</Grid>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
如果我更改了Xaml,使IsVisible属性没有绑定,只是设置为“True”,那么它将编译并加载
我不知道为什么这不起作用,因为模型中的其他值已正确绑定
以下是“PeopleCollectionGrouped”的人员模型:
如果有人能发现我哪里出了问题,这会有所帮助我真的认为这是一个更深层次的问题,您提供的代码应该可以工作。无效的IL代码不是由错误绑定引起的。您确定在调试时,
PeopleCollectionGrouped
collection中的每个人员实例都正确填充了IsVisible吗?@iSpain17 IsVisible在PeopleCollectionGroup集合中填充。如果我将布局更改为这样更简单的内容:那么它将绑定correctly@jaymarvels,我将您的示例减少了一点,以便在我这方面实现模拟数据,并且它工作正常(当设置为false时,人员对象的IsVisible属性按钮不会显示,如预期的那样)。你能不能减少你的问题,在问题仍然存在的地方制作一个尽可能简单的样本?(也许在你自己意识到实际问题是什么的过程中:P)但是当设置IsVisible属性后调试它时,你看到了什么?@jaymarvels嗨,你应该为Xaml
绑定ViewModel
。从共享代码中,找不到关于ListView
的ItemSource
的代码。
System.InvalidProgramException: Invalid IL code
public class People
{
[JsonProperty("photo_url")]
public string PhotoUrl { get; set; }
[JsonProperty("location")]
public string Location { get; set; }
[JsonProperty("id")]
public string Id { get; set; }
[JsonProperty("first_name")]
public string FirstName { get; set; }
[JsonProperty("middle_name")]
public string MiddleName { get; set; }
[JsonProperty("last_name")]
public string LastName { get; set; }
public string FullName => $"{FirstName} {LastName}";
public string NameSort
{
get
{
if (string.IsNullOrWhiteSpace(FullName) || FullName.Length == 0)
{
return "?";
}
return FullName[0].ToString().ToUpper();
}
}
public bool IsVisible { get; set; }
}