[英]WPF Binding: How to databind to Grid?
我创建了一个班级Account
。
接下来,我创建了另一个类ReorderWindowController
,它具有类型为Account
的字段/属性SelectedAccount
。
最后,我编写了ReorderWindow
WPF窗口xaml文件:
<Window ...
<Window.Resources>
<contollers:ReorderWindowController x:Key="WindowController" />
<DataTemplate DataType="{x:Type entities:Account}">
<Grid Width="140" Height="50" Margin="5">
<TextBlock Text="Some awesome text" />
<TextBlock Text="{Binding Name}" />
<TextBlock Text="Even more awesome text" />
</Grid>
</DataTemplate>
</Window.Resources>
<Grid>
<Grid
Name="AccountGrid"
DataContext="{Binding Source={StaticResource ResourceKey=WindowController},
Path=SelectedAccount}">
</Grid>
</Grid>
</Window>
当我运行我的代码时, AccountGrid
没有显示任何内容。 为什么? 如何使对象数据绑定到Grid
,如何使其使用我的数据模板? 谢谢。
而不是网格使用这样的ContentPresenter:
<Grid>
<ContentPresenter
Name="AccountGrid"
Content="{Binding Source={StaticResource ResourceKey=WindowController}, Path=SelectedAccount}">
</ContentPresenter>
</Grid>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.