我有一个ListBox
,其中包含由RadioButtons
组成的项目。它们是通过为其提供ItemsSource
动态创建的。下面是ListBox
的XAML:已禁用RadioButton仍然可以选择
<ListBox
Margin="20,5,0,0"
Width="Auto"
Background="Transparent"
BorderThickness="0"
BorderBrush="Transparent"
DisplayMemberPath="DisplayValue"
SelectedValuePath="Value"
SelectedItem="{Binding Path=SingleAnswer}"
ItemsSource="{Binding Path=AnswerOptions}">
<!-- KLG Score ItemsSource converter to filter out 'Unable to Assess' -->
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.Resources>
<Style TargetType="{x:Type ListBoxItem}">
<Setter Property="Margin" Value="0,0,25,0" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListBoxItem}">
<Border Background="Transparent" BorderThickness="0" BorderBrush="Transparent">
<Border.IsEnabled>
<MultiBinding Converter="{StaticResource RadioButtonToEnabledConverter}" >
<Binding Mode="OneWay" ElementName="this" Path="ParentForm.ImagesExist"/>
<Binding Mode="OneWay" Path="." />
</MultiBinding>
</Border.IsEnabled>
<RadioButton Focusable="False" IsHitTestVisible="False" IsChecked="{Binding Path=IsSelected, RelativeSource={RelativeSource TemplatedParent}, Mode=TwoWay}" Click="KLGScoreRadioButton_Click" >
<RadioButton.IsEnabled>
<MultiBinding Converter="{StaticResource RadioButtonToEnabledConverter}" >
<Binding Mode="OneWay" ElementName="this" Path="ParentForm.ImagesExist"/>
<Binding Mode="OneWay" Path="." />
</MultiBinding>
</RadioButton.IsEnabled>
<ContentPresenter />
</RadioButton>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ListBox.Resources>
</ListBox>
现在,答案应该不能够由用户选择,只应自动填充这取决于商业逻辑指定。
为此,我为RadioButton.IsEnabled
属性创建了一个转换器,以始终将指定的RadioButton
设置为禁用状态。这有效;在应用程序中它被适当地禁用。但是,如果用户点击禁用选项,它仍然允许它被选中。我也尝试在父项Border
上使用相同的转换器(如上面的xaml所示),但行为不变。
我也试过在的Click
事件中添加一个侦听器,如果它们选择禁用选项,将其设置为处理,但该事件由于某种原因未被触发。
无论如何不允许用户选择此选项吗?
为什么downvote ...? – Saggio
您是否尝试在触发器中将IsHitTestVisible设置为false? – whoisthis