【发布时间】:2016-10-21 22:23:08
【问题描述】:
我在列表框中使用单选按钮,无法禁用它们。 搜索后,我找到了有关 IsEnabled 和 IsHitTestVisible 的链接。当我将 IsEnabled 设置为 false 时,按钮和文本变为灰色,但它仍然可以点击。设置 IsHitTestVisible 并没有改变这一点。我的 XAMLcode 如下所示:
<ListBox ItemsSource="{Binding Source}" BorderThickness="0" VerticalAlignment="Stretch" Background="Transparent" SelectedItem="{Binding SelectedSource, Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" >
<ListBox.ItemTemplate>
<DataTemplate>
<RadioButton IsHitTestVisible="{Binding IsEnabled}" IsEnabled="{Binding IsEnabled}" Margin="0 2 0 0" FontSize="12" FontFamily="Segoe UI Regular" Content="{Binding name}" GroupName="GroupList" >
<RadioButton.Style>
<Style TargetType="{x:Type RadioButton}">
<Setter Property="IsChecked" Value="{Binding Path=IsSelected, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListBoxItem}}}" />
</Style>
</RadioButton.Style>
</RadioButton>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
c# 中计算并返回 bool 的属性。
public bool IsEnabled
{
get
{
IsEnabledCalculate();
return isEnabled;
}
}
关于如何禁用选择的任何想法?
【问题讨论】:
-
INotifyPropertyChange 实施在哪里?如果没有它,此属性将永远不会通知 UI 有更改。