【发布时间】:2014-12-04 06:21:03
【问题描述】:
我有一个模型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 中的控件与model3 的属性绑定。我知道这看起来太混乱了,但我被困住了。救命!
【问题讨论】:
-
问题不清楚。
-
@EldarDordzhiev 检查现在是否有意义。
-
把你的完整xaml
-
@MatDev8 添加了更多代码。
-
那么,第一个问题 => 当你启动应用程序时,你有什么东西显示在屏幕上吗?你的清单上装满了物品? model3 需要是一个列表。
标签: c# xaml windows-phone-7 windows-phone-8