首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ToggleButton样式;覆盖IsEnabled

ToggleButton样式;覆盖IsEnabled
EN

Stack Overflow用户
提问于 2015-09-02 02:04:31
回答 1查看 684关注 0票数 0

选中ToggleButton后,应将按钮设置为disabled,并且应更改前景颜色。以下代码不起作用:

代码语言:javascript
复制
      <Window x:Class="WpfApplication1.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>
    <ToggleButton  Content="Hallo" Margin="113,97,72,46" >
        <ToggleButton.Style>
            <Style TargetType="{x:Type ToggleButton}">
                <Setter Property="Foreground" Value="Blue"/>
                <Setter Property="IsEnabled" Value="True"/>
                <Setter Property="IsChecked" Value="False"/>
                <Style.Triggers>
                    <Trigger Property="IsChecked" Value="True">
                        <Setter Property="IsEnabled" Value="False"/>
                    </Trigger>
                    <Trigger Property="IsEnabled" Value="False">
                        <Setter Property="Foreground" Value="Green"/>
                    </Trigger>

                </Style.Triggers>
            </Style>
        </ToggleButton.Style>
    </ToggleButton>

</Grid>

我该怎么做呢?

EN

回答 1

Stack Overflow用户

发布于 2015-09-02 08:25:48

禁用控件的外观在不同的windows版本和不同的Windows帐户设置等方面是不同的,这就是为什么它适用于其他人而不是您。一般来说,您应该遵守这些设置,但是如果您确实很坚持,那么您将需要显式地覆盖模板,如this question中所示

代码语言:javascript
复制
<Setter Property="Template">
    <Setter.Value>
        <ControlTemplate TargetType="{x:Type ToggleButton}">
            <Grid Background="{TemplateBinding Background}">
                <ContentPresenter x:Name="MyContentPresenter" Content="{TemplateBinding Content}"
                        HorizontalAlignment="Center" 
                        VerticalAlignment="Center" />
            </Grid>
        </ControlTemplate>
    </Setter.Value>
</Setter>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32338180

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档