在
UserControl
(
TaskView1
)我把几个布尔值绑定到
RadioButtons
:
<StackPanel>
<RadioButton Content="Spell" IsChecked="{Binding IsSpell}" />
<RadioButton Content="Movement" IsChecked="{Binding IsMovement}"/>
<RadioButton Content="Action" IsChecked="{Binding IsAction}" />
<RadioButton Content="Find" IsChecked="{Binding IsFind}"/>
</StackPanel>
这
用户控件
(
任务视图1
)用于显示选定的
Task
在一个
TreeView
(注意,我有两个
DataTemplate
因为有两种不同类型的
任务
我希望每个人都有不同的观点)。
<GroupBox Header="Selected Task">
<GroupBox.Resources>
<DataTemplate DataType="{x:Type local:Task1}">
<local:TaskView1/>
</DataTemplate>
<DataTemplate DataType="{x:Type local:Task2}">
<local:TaskView2/>
</DataTemplate>
</GroupBox.Resources>
<Grid HorizontalAlignment="Left">
<ScrollViewer DataContext="{Binding SelectedItem, ElementName=TaskTreeView}" Content="{Binding}"/>
</Grid>
</GroupBox>
当我更改树中任务的选择时,会出现问题。由于单选按钮是排他性的,我经常发现
Task1Instance1
在树中选择时已更改
Task1Instance2
.
例子:
在树中选择任务A。这是一个
Movement
.
然后用户选择任务B,它是
Spell
. 发生的情况是,任务A的数据以某种方式发生了更改
IsMovement
为false,因此如果用户再次选择任务A,则不会选择单选按钮。
问题:
这是WPF中的常见问题还是我只是搞砸了什么?