我正在使用以下模板创建选中的列表框:
<Style x:Key="CheckBoxListStyle" TargetType="{x:Type ListBox}">
<Setter Property="SelectionMode" Value="Multiple"></Setter>
<Setter Property="ItemContainerStyle">
<Setter.Value>
<Style TargetType="{x:Type ListBoxItem}" >
<Setter Property="Margin" Value="2" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListBoxItem}">
<CheckBox IsChecked="{Binding Path=xxxxxxxxxxx,RelativeSource={RelativeSource TemplatedParent},Mode=TwoWay}"> <ContentPresenter></ContentPresenter>
</CheckBox>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Setter.Value>
</Setter>
</Style>
<ListBox Style="{StaticResource CheckBoxListStyle}" ItemsSource="{Binding Path=Configuration.ProductTypes}" DisplayMemberPath="ProductName" />
我的问题是,我从数据库中获取所有产品类型并将其绑定到列表框项目源。我有一个产品类,其中包含它所属的产品类型列表。我需要根据产品的产品类型列表设置复选框的 IsChecked 属性。通常我需要设置一个或多个复选框 IsChecked 属性。产品可能属于一种或多种产品类型。选择模式是多选。如果用户选中其他产品类型复选框..我需要获取总选中列表框并将它们保存到数据库中......这是一个 MVVM WPF 应用程序......关于如何解决这种情况的任何想法......
在控制模板 IsChecked 的路径是什么?
谢谢雷伊
让我简单化我的问题:我需要一个带有复选框和文本块的列表框。文本块数据上下文不同,复选框数据上下文不同。我的意思是他们从不同的对象获取数据。不知道如何实现这一目标......