WPF:绑定定制列表框&;列表<;T>;:PropertyChanged始终为空
我已在XAML中声明自定义列表框:WPF:绑定定制列表框&;列表<;T>;:PropertyChanged始终为空,wpf,data-binding,inotifypropertychanged,Wpf,Data Binding,Inotifypropertychanged,我已在XAML中声明自定义列表框: <ListBox x:Name="uicMDSQonfServer"> <ListBox.ItemTemplate> <DataTemplate> <StackPanel Orientation="Horizontal" Margin="0,5,0,5"> <CheckBox IsChecked="{Binding Relative
<ListBox x:Name="uicMDSQonfServer">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal"
Margin="0,5,0,5">
<CheckBox IsChecked="{Binding RelativeSource={TemplatedParent},
Path=Activated}" />
<ContentPresenter Content="{Binding RelativeSource={TemplatedParent},
Path=Content}"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
QonfBase是非常简单的基类:
public class QonfBase
{
private int id;
public int ID { get; set; }
}
当我以编程方式打开激活属性时,复选框不更改状态。调试:PropertyChanged=null。有人知道什么是错误的吗?一个显而易见的问题出现了:
TemplatedParent
用于ControlTemplate
s。由于您使用的是数据模板
,因此应该可以:
<CheckBox IsChecked="{Binding Activated}" />
<ContentPresenter Content="{Binding Content}"/>
我没有注意到C#有任何问题。是否检查输出窗口?有绑定错误吗?谢谢你,雷!我已经删除了显式相对资源,现在它的工作!
<CheckBox IsChecked="{Binding Activated}" />
<ContentPresenter Content="{Binding Content}"/>