【发布时间】:2016-01-14 12:17:07
【问题描述】:
我正在尝试为 ComboBox 设置禁用项目,我有我的项目模型:
public class PermissionsViewItem
{
public string Title { get; set; }
public bool IsEnabled { get; set; }
}
并定义了 ComboBox:
<ComboBox Background="WhiteSmoke" Margin="65,308,0,0" BorderThickness="0" Width="220" Padding="0" Foreground="#FF7B7A7F" ItemsSource="{Binding PermissionsViewItems}" >
<ComboBox.ItemTemplate>
<DataTemplate x:DataType="local:PermissionsViewItem">
<StackPanel >
<Grid>
<Border Background="{x:Null}" BorderThickness="0" HorizontalAlignment="Left" VerticalAlignment="Center">
<TextBlock Text="{x:Bind Title}" FontWeight="SemiBold" />
</Border>
</Grid>
</StackPanel>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
但是似乎没有办法手动设置禁用项目,但是生成了具有 IsEnabled 属性的 ComboBoxItem 元素(我可以在 LiveVisualTree 中看到它)并且它可以工作。我可以通过样式访问它
<ComboBox.ItemContainerStyle>
<Style TargetType="ComboBoxItem" >
<Setter Property="IsEnabled" Value="False"/>
</Style>
</ComboBox.ItemContainerStyle>
这会禁用每个项目,但不幸的是 ItemContainerStyle 没有绑定到项目,因为它有 ComboBox 的上下文而不是 PermissionsViewItem 所以我不能在这里使用 PermissionsViewItem.IsEnabled 属性。
有没有什么方法可以禁用特定的项目(即使是 hacky 方式就足够了)?
【问题讨论】:
标签: c# xaml winrt-xaml win-universal-app