我正在创建一个包含ContentPresenter的UserControl。我使用Datagrid将contentPresenter填充到窗口中,将itemsSource绑定到列表,但不起作用。在ContentPersenter中绑定ItemsSource Datagrid
我的Datagrid是空的。但是当我将DataGrid移出UserControl时,我得到了Inside数据。
我的用户 XAML:
<UserControl Name="Instance" ...>
<Grid>
<ScrollViewer>
<ContentPresenter Content="{Binding Path=AdditionnalContent, ElementName=Instance}" />
</ScrollViewer>
</Grid>
</UserControl>
C#:
public Object AdditionnalContent
{
get { return (object)GetValue(ContentProperty); }
set { SetValue(ContentProperty, value); }
}
public static readonly DependencyProperty AdditionnalContentProperty = DependencyProperty.Register("AdditionnalContent", typeof(object), typeof(MyUserControl),
new PropertyMetadata(null));
我的窗口
<Window Name="win" ...>
<Grid>
<my:MyUserControl>
<my:MyUserControl.AdditionnalContent>
<!-- Datagrid is empty -->
<DataGrid ItemsSource="{Binding LIST, ElementName=win}" AutoGenerateColumns="True" />
</my:MyUserControl.AdditionnalContent>
</my:MyUserControl>
<!-- Datagrid have content -->
<DataGrid ItemsSource="{Binding LIST, ElementName=win}" AutoGenerateColumns="True" />
</Grid>
</Window>
C#:
public partial class MainWindow : Window
{
public List<Object> LIST
{
get;
private set;
}
public MainWindow()
{
fillList();
InitializeComponent();
}
}
感谢
下载snoopwpf.codeplex.com。您可以使用此工具在应用程序运行时检查UI,并发现绑定错误。 – 2014-10-16 19:13:27
我在电脑上工作,我不是管理员,我不能安装程序... – Northik 2014-10-16 19:36:38