Windows Phone - Button with Disabled Button

here I am again with another question about Windows Phone.

I created some custom buttons and used them as backgrounds on my buttons. I also created a greyed out button to show it as a disabled button.

But if I disable using the button button.isEnabled = false, the background disappears

Searching the net I found a way to use the Style tag, but I've never used it before. I tried but, this always gives me back the problem, can someone give me an 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 it possible to style it in Windows Phone 8.1 or another way to set a custom background on a button using IsDisabled = false?

+3


source to share


2 answers


Further, since I know the style triggers are WPF and not WP8.1 / WIN8.1

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

You want to change the Disable State of the button to 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 this new style as the button style, you get what you want.

+3


source


In the French interface

Document structure on the left side of VS2013. Find your button, right click> Modify Template -> Modify Copy



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

0


source







All Articles