Bor*_*ris 5 data-binding wpf grid binding
我创建了一个类Account.
接下来,我创建了另一个ReorderWindowController具有SelectedAccount类型的字段/属性的类Account.
最后,我编写了ReorderWindowWPF窗口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>
Run Code Online (Sandbox Code Playgroud)
当我运行我的代码时,AccountGrid没有显示任何内容.为什么?如何将对象数据绑定到,Grid以及如何使用我的数据模板?谢谢.
而不是网格使用这样的ContentPresenter:
<Grid>
<ContentPresenter
Name="AccountGrid"
Content="{Binding Source={StaticResource ResourceKey=WindowController}, Path=SelectedAccount}">
</ContentPresenter>
</Grid>
Run Code Online (Sandbox Code Playgroud)