gpt4 book ai didi

.net - 当 IsEnabled=False 和 IsEditable = False 时,WPF 组合框选择的项目文本不会变灰

转载 作者:行者123 更新时间:2023-12-04 16:00:04 25 4
gpt4 key购买 nike

使用以下代码,组合框所选项目的文本正常显示(即黑色)。当控件被禁用时,我希望它变灰。但是,如果我设置 IsEditable=True 然后它会变灰,但我不希望它是可编辑的。

<Window x:Class="WpfApp1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<ComboBox Width="150" Height="23" IsEnabled="False" SelectedIndex="0" IsEditable="False">
<TextBlock>Hello</TextBlock>
<TextBlock>World</TextBlock>
</ComboBox>
</Grid>
</Window>

最佳答案

要在禁用时将组合框项目颜色固定为灰色,请执行以下操作,这将修复 UI 中的所有组合框。

将此粘贴​​到您的 <Window.Resources> 代码中的 Xaml 标记内:

<Style TargetType="{x:Type ComboBox}">
<Style.Triggers>
<Trigger Property="IsEnabled"
Value="False">
<Setter Property="Foreground"
Value="Gray"/>
</Trigger>
</Style.Triggers>
</Style>

关于.net - 当 IsEnabled=False 和 IsEditable = False 时,WPF 组合框选择的项目文本不会变灰,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50773743/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com