DataTrigger not firing

后端 未结 1 481
我在风中等你
我在风中等你 2020-12-01 17:00

I have the following xaml:

    
    
        
        

        
相关标签:
1条回答
  • 2020-12-01 17:16

    The issue here is Property Value Precedence.

    You are currently setting the Background to blue directly on the DockPanel. This explicit property will override any value set by the trigger.

    Instead, you must set the original "Background" as a setter in the style.

    <DockPanel DockPanel.Dock="Left" Width="10">
        <DockPanel.Style>
            <Style>  
                <Setter Property="DockPanel.Background" Value="Blue" /> 
                <Style.Triggers>                    
                    <DataTrigger Binding="{Binding Path=Test}" Value="True">                        
                        <Setter Property="DockPanel.Background" Value="Yellow" />                       
                    </DataTrigger>
                </Style.Triggers>            
            </Style>        
        </DockPanel.Style>    
    </DockPanel></DockPanel>
    
    0 讨论(0)
提交回复
热议问题