English 中文(简体)
WPF 财产多重价值
原标题:
  • 时间:2009-06-05 11:06:59
  •  标签:

我想对《进步的巴塞罗那》作一个风格,因为在某些价值观之间,风格应当改变。

<Style x:Key="ProBar" TargetType="{x:Type ProgressBar}">    
      <Style.Triggers>
        <Trigger Property="Value" Value="<10">
          <Setter Property="Foreground">
            <Setter.Value>
              <!--OrangeColour-->
              <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                <GradientStop Color="#FFFFFFFF" Offset="0" />
                <GradientStop Color="#FFFDDF97" Offset="0.992" />
                <GradientStop Color="#FFF7DCAB" Offset="0.02" />
                <GradientStop Color="#FFFFDC9E" Offset="0.5" />
                <GradientStop Color="#FFFDA564" Offset="0.513" />
              </LinearGradientBrush>
            </Setter.Value>
          </Setter>
        </Trigger>      
      </Style.Triggers>
    </Style>

这样做是否可行?

问题回答

1. 使用数据交换器、电压器和四射电传机

<DataTrigger Binding="{Binding Value, Converter={StaticResource IsMyValueLowEnoughConverter}}" Value="True">

Converter:

public class IsMyValueLowEnoughConverter : IValueConverter
{
    public object Convert(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        return ((int)value) < 10;
    }

    public object ConvertBack(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        throw new System.NotImplementedException();
    }
}

1. 确信在您的原Xaml档案中将变换者置于其资源之下:

<IsMyValueLowEnoughConverter x:Key="IsMyValueLowEnoughConverter" />




相关问题
热门标签