Trigger based on text property not working
问题 Here is the xaml that I am working on: <TextBlock Text="{Binding Title}" Margin="10,0,0,0" VerticalAlignment="Center"> <TextBlock.Resources> <Style TargetType="{x:Type TextBlock}"> <Style.Triggers> <Trigger Property="Text" Value=""> <Setter Property="Margin" Value="0" /> </Trigger> </Style.Triggers> </Style> </TextBlock.Resources> </TextBlock> When text = "" I want to clear up the margin. But somehow it does not work. 回答1: You must move Margin="10,0,0,0" from TextBlock to setter of Style :