3

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?

Chubosaurus Software
  • 8,133
  • 2
  • 20
  • 26
  • You can also create custom button classes, and you can set the disabled view state there. Check out the styles for different controls here: http://blogs.msdn.com/b/flaviencharlon/archive/2012/12/04/default-styles-and-templates-of-xaml-controls-for-windows-store-apps.aspx –  Oct 08 '14 at 03:53

2 Answers2

3

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.

Chubosaurus Software
  • 8,133
  • 2
  • 20
  • 26
0

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