WPF绑定:如何将数据绑定到网格?
我已经创建了一个类WPF绑定:如何将数据绑定到网格?,wpf,data-binding,grid,binding,Wpf,Data Binding,Grid,Binding,我已经创建了一个类帐户 接下来,我创建了另一个类ReorderWindowController,它有一个类型为Account的字段/属性SelectedAccount 最后,我编写了ReorderWindowwpfwindowxaml文件: <Window ... <Window.Resources> <contollers:ReorderWindowController x:Key="WindowController" />
帐户
接下来,我创建了另一个类ReorderWindowController
,它有一个类型为Account
的字段/属性SelectedAccount
最后,我编写了ReorderWindow
wpfwindowxaml文件:
<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>
使用ContentPresenter代替网格,如下所示:
<Grid>
<ContentPresenter
Name="AccountGrid"
Content="{Binding Source={StaticResource ResourceKey=WindowController}, Path=SelectedAccount}">
</ContentPresenter>
</Grid>
您是否对帐户和ReorderWindowController类实现了INotifyPropertyChanged?数据绑定依赖System.ComponentModel.INotifyPropertyChanged来接收更改通知,这会导致绑定检索值。是的,我这样做了。虽然我面临的问题与变更通知无关,但感谢您的提醒。