[英]Binding to a property of a list element of a model
我有一个模型Model1
,其属性为List<Model2> model2;
。
Model1.cs
//Other Properties
public List<Model2> model2List {get; set;}
在Model2
我有这个属性Model3 model3;
Model2.cs
// Other Properties
public Model3 model3 {get; set;}
Model3.cs
// Other Properties
public string Name {get; set;}
现在我有两个用户控件View1
和View2
与View2
中定义View1
View1.xaml用户控件
<Grid x:Name="LayoutRoot">
<!-- Some properties here bind to those of model1 and model2 -->
<views:View2 Name="view2"></views:View2>
</Grid>
View2.xaml用户控件
<Grid x:Name="LayoutRoot" Background="{StaticResource PhoneChromeBrush}">
<phone:LongListSelector
ItemsSource="{Binding Path=model3, Mode=OneWay}">
<phone:LongListSelector.ItemTemplate>
<DataTemplate>
<StackPanel>
<Border
BorderBrush="{StaticResource PhoneBackgroundBrush}"
BorderThickness="3"
Margin="0,12">
<Grid>
<TextBlock Text={Binding Path=Name, Mode=OneWay}>
</TextBlock>
</Border>
<views:View3 Name="view3">
</views:View3>
</StackPanel>
</DataTemplate>
</phone:LongListSelector.ItemTemplate>
</phone:LongListSelector>
</Grid>
我试图在View2.xaml绑定TextBlock的物业名称Model3
。 从我的CS我已将DataContext设置为
view2.DataContext = model1Object.model2List;
似乎没有用。 另外,我需要将view2
定义的view3
控件与view3
属性model3
。 我知道这看起来太混乱了,但是我被卡住了。 救命!
这些不是财产。 那是领域 。 您无法绑定到字段。
通过使用自动属性定义将字段更改为属性。
public Model3 Model3 {get;set;} // PascalCase for property names, thx
这可能不是唯一的问题,但是尝试绑定字段绝对是不正确的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.