goyo
goyo

Reputation: 57

How can i use a custom style with setters and triggers?

I would like to do something like this, but obviously I cannot have 2 style properties specified. I cant figure out the syntax for adding the style resource to the "<Button.Style>" attribute.

<Button x:Name="CreateProductButton" Style="{StaticResource GoldButton}" Content="Add Product" Click="CreateProductButton_Click" TabIndex="4">
        <Button.Style>
            <Style TargetType="{x:Type Button}">
                <Setter Property="IsEnabled" Value="false" />
                <Style.Triggers>
                    <MultiDataTrigger>
                        <MultiDataTrigger.Conditions>
                            <Condition Binding="{Binding ElementName=OperatorId, Path=(Validation.HasError)}" Value="false" />
                            <Condition Binding="{Binding ElementName=NewProductId, Path=(Validation.HasError)}" Value="false" />
                            <Condition Binding="{Binding ElementName=NewYearId, Path=(Validation.HasError)}" Value="false" />
                        </MultiDataTrigger.Conditions>
                        <Setter Property="IsEnabled" Value="true" />
                    </MultiDataTrigger>
                </Style.Triggers>
            </Style>
        </Button.Style>
    </Button>

Upvotes: 0

Views: 23

Answers (1)

NextInLine
NextInLine

Reputation: 2204

If you're trying to use an existing style with a few additions or changes, used Style.BasedOn. That is:

<Style x:Key="MyDerivedButtonStyle"
       TargetType="{x:Type Button}"
       BasedOn="{StaticResource GoldButton}">
    <Setter Property="IsEnabled" Value="false" />
    <Style.Triggers>
        ...
    </Style.Triggers>
</Style>

Then set your Button's style as Style={StaticResource MyDerivedButtonStyle}.

Upvotes: 1

Related Questions