Windows Phone - Disabled Button Background

妖精的绣舞 提交于 2019-12-12 15:14:47

问题


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.

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

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>

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?


回答1:


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

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.




回答2:


In french interface

Document Outline on the left side of VS2013. Find your button, right click > Edit Template -> Edit a Copy

Menu Format / Modifier le modèle / Modifier une copie. Cela rajoute dans le xaml le

来源:https://stackoverflow.com/questions/26248346/windows-phone-disabled-button-background

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!