从xaml页面中的代码传输值以更改扩展器前景

时间:2015-09-08 08:56:35

标签: c# xaml expander

<Expander x:Name="exp" 
          IsExpanded="True"
          Background= "White"
          Foreground="Black">
    <Expander.Header>
        <TextBlock Text="{Binding Name}" />
    </Expander.Header>
        <ItemsPresenter />
</Expander>

我想在基于if条件的c#代码后面更改Foreground值..如何从后面的代码中传输值以在xaml页面中访问它?

2 个答案:

答案 0 :(得分:0)

Code Behind将是

exp.Foreground = new SolidColorBrush(Color.Red);

exp.Foreground = Brushes.Blue;

exp.Foreground = new SolidColorBrush(Color.FromArgb(0xFF, 0xFF, 0, 0);

exp.Foreground = System.Windows.SystemColors.ControlLightColor;

答案 1 :(得分:0)

如果将来有人需要这个,我使用触发器完成了它:

        <Style TargetType="DataGridCell">
            <Style.Triggers>
                <DataTrigger Binding="{Binding Path=Result}" Value="F">
                    <Setter Property="Foreground" Value="Red" />
                    <Setter Property="FontWeight" Value="DemiBold" />
            </DataTrigger>
            </Style.Triggers>
        </Style>

当Result =“F”时,这将改变整个数据网格行前景。

相关问题