5
在我的用户控件我有这样的特性:我怎么能一个字段绑定到用户控件
public static DependencyProperty FooListProperty = DependencyProperty.Register(
"FooList", typeof(List<Problem>), typeof(ProblemView));
public List<Problem> FooList
{
get
{
return (List<Problem>)GetValue(FooListProperty);
}
set
{
SetValue(FooListProperty, value);
}
}
protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e)
{
base.OnPropertyChanged(e);
if (e.Property == FooListProperty)
{
// Do something
}
}
而且,由于另一扇窗,我正尝试设置最后一个用户控件的值:
<local:ProblemView HorizontalAlignment="Center"
VerticalAlignment="Center" FooList="{Binding list}" />
而在负载该窗口包含:
public List<Problem> list;
private void Window_Loaded(object sender, RoutedEventArgs e)
{
// Some processes and it sets to list field
list = a;
}
但在XAML代码,结合它不工作。不要传递数据。我错了什么?
感谢百万Meleak,它的工作。事实上,这是我问过你的同一个问题。我真的很喜欢你的帮助。 –