开发者

wpf Treeview CheckBox Item ForeGround Color cannot Change when it is disabled?

This is the my xaml style for Treeview CheckBox Item. I'm using Syncfusion Treeview.

<Style x:Key="contractListItemContainerStyle" TargetType="{x:Type syncfusion:TreeViewItemAdv}">
    <Setter Property="IsExpanded" Value="True" />
    <Setter Property="IsSelected" Value="{Binding IsInitiallySelected, Mode=OneTime}" />
    <Setter Property="KeyboardNavigation.AcceptsReturn" Value="True" />
    <Setter P开发者_如何学Goroperty="IsEditable" Value="False" />

    <Setter Property="IsEnabled" Value="{Binding Enable}" />
    <Setter Property="Foreground" Value="Red" />
    <Style.Triggers>
        <Trigger Property="IsEnabled" Value="True">
            <Setter Property="Foreground" Value="Green" />
        </Trigger>
        <Trigger Property="IsEnabled" Value="False">
            <Setter Property="Foreground" Value="Red" />
        </Trigger>
    </Style.Triggers>
</Style>

<HierarchicalDataTemplate x:Key="selectedContractsDataTemplate" ItemsSource="{Binding Children}" >
    <StackPanel Orientation="Horizontal">
        <CheckBox Margin="2,0,2,0"
             Focusable="False"
             IsChecked="{Binding Content.IsChecked}"
             VerticalAlignment="Center"  />
        <ContentPresenter Content="{Binding}" Margin="2,0"  />
    </StackPanel>
</HierarchicalDataTemplate>

If I set Enable to False from ViewModel, The Color doesn't change to red but If I set to true, it changes to Green. Why? Pelase advise.


The code should work, see/try this:

<StackPanel>
    <CheckBox Name="chk" Content="check this...">
        <CheckBox.Style>
            <Style>
                <Setter Property="CheckBox.Foreground" Value="Red" />
                <Style.Triggers>
                    <Trigger Property="CheckBox.IsEnabled" Value="True">
                        <Setter Property="CheckBox.Foreground" Value="Green" />
                    </Trigger>
                    <Trigger Property="CheckBox.IsEnabled" Value="False">
                        <Setter Property="CheckBox.Foreground" Value="Red" />
                    </Trigger>
                </Style.Triggers>
            </Style>
        </CheckBox.Style>
    </CheckBox>
    <Button Content="press" Click="Button_Click"/>
</StackPanel>

Probably something is wrong with the binding?


Try this

  <Setter Property = "Foreground" Value = "Red"/>
   <Style.Triggers>
       <Trigger Property="IsEnabled" Value="True">
             <Setter Property="Foreground" Value="Green" />
       </Trigger>
    </Style.Triggers>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜