Windows Phone - 禁用按钮背景 [英] Windows Phone - Disabled Button Background

查看:16
本文介绍了Windows Phone - 禁用按钮背景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里我又问了一个关于 Windows Phone 的问题.

here I'm once more with another question about Windows Phone.

我刚刚创建了一些自定义按钮并将它们用作按钮的背景.我还创建了一个灰色按钮以显示为禁用按钮.

I just created some custom buttons and use they as background on my buttons. I also created a grayed button to show as disabled button.

但是如果我禁用使用 button1.isEnabled = false,背景就会消失

But if I disable using the button1.isEnabled = false, the background disappear

在网上搜索我找到了一种使用 Style 标签的方法,但我以前从未使用过.我试过了,但是,它给我带来了一个问题,有人能给我举个例子吗?我的代码:

Searching on the net I found a way using a Style tag, but I never used before. I tried but, it's aways returns me a problem, can someone give me a example? My Code:

<Button x:Name="btSalvar" Content="Salvar Cor" Margin="68,477,70,0" VerticalAlignment="Top" BorderBrush="{x:Null}" BorderThickness="0" Height="100" Click="btSalvar_Click" ClickMode="Press" IsEnabled="True" Foreground="White">
    <Button.Style>
        <Style.Triggers>
            <Trigger Property="IsEnabled" Value="false">
                <Setter Property="Background" Value="/Imagens/Buttons/ButtonGray01.png"/>
            </Trigger>
        </Style.Triggers>
    </Button.Style>
</Button>

有没有办法在 Windows Phone 8.1 中使用 Style 或以其他方式在 IsDisabled = false 的按钮上设置自定义背景?

Is there a way to use Style in Windows Phone 8.1 or another way to set a custom background on button with IsDisabled = false?

推荐答案

据我所知 Style Triggers 是 WPF 的东西,不是 WP8.1/WIN8.1

Far as I know Style Triggers are a WPF thing not WP8.1/WIN8.1

因此,您必须使用 Visual State Manager 来完成您想要执行的操作.因此,转到 UI 设计器,然后转到 VS2013 左侧的文档大纲.找到您的按钮,右键单击> 编辑模板-> 编辑副本.这将为该特定按钮创建自定义样式.

So you will have to use the Visual State Manager for what you want to do. So go to the UI Designer then go to the Document Outline on the left side of VS2013. Find your button, right click > Edit Template -> Edit a Copy. This will create a custom style for that specific button.

您想更改按钮的禁用状态,因此将其更改为......

You want to change the Disable State of the button so change that to.....

...
<VisualState x:Name="Disabled">
    <Storyboard>
        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="ContentPresenter">
            <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource ButtonDisabledForegroundThemeBrush}"/>
        </ObjectAnimationUsingKeyFrames>
        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="BorderBrush" Storyboard.TargetName="Border">
            <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource ButtonDisabledBorderThemeBrush}"/>
        </ObjectAnimationUsingKeyFrames>

        <!-- here is where we need to change -->
        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(Border.Background).(ImageBrush.ImageSource)" Storyboard.TargetName="Border">
            <DiscreteObjectKeyFrame KeyTime="0" Value="Assets/YOUR_IMAGE.png"/>
        </ObjectAnimationUsingKeyFrames>

    </Storyboard>
</VisualState>
....

<小时>

现在,如果您将新样式设置为按钮的样式,您将得到您想要的.


Now if you set that new style as the style of the button, you will get what you want.

这篇关于Windows Phone - 禁用按钮背景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆