Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Style DataTrigger Setter in Button Content is invalid

Tags:

wpf

<StackPanel>
    <TextBox Text="" x:Name="input"/>
    <Button Content="DataTrigger Before">
        <Button.Style>
            <Style TargetType="Button">
                <Style.Triggers>
                    <DataTrigger Binding="{Binding ElementName=input, Path=Text}" Value="1">
                        <Setter Property="Content" Value="Changed"></Setter>
                    </DataTrigger>
                </Style.Triggers>
            </Style>
        </Button.Style>
    </Button>
</StackPanel>

Style DataTrigger Setter in Button Content is invalid

Thanks

like image 336
JerryBaxia Avatar asked Oct 25 '12 03:10

JerryBaxia


1 Answers

Your DataTrigger is not change the value of the Content property because you set it inside the Button declaration. So, once setted, it will never changed. To allow changing, you have to set the value inside the Style.

This will works (I've tried):

<StackPanel>
    <TextBox Name="input"/>
    <Button>
        <Button.Style>
            <Style TargetType="Button">
                <Setter Property="Content" Value="DataTrigger Before"></Setter>
                <Style.Triggers>
                    <DataTrigger Binding="{Binding ElementName=input, Path=Text}" Value="1">
                        <Setter Property="Content" Value="Changed"></Setter>
                    </DataTrigger>
                </Style.Triggers>
            </Style>
        </Button.Style>
    </Button>
</StackPanel>
like image 195
stukselbax Avatar answered Oct 15 '22 16:10

stukselbax