【问题标题】:WPF Xaml ComboBox and DataPicker - How to change BorderBrush with MultiDataTriggerWPF Xaml ComboBox 和 DataPicker - 如何使用 MultiDataTrigger 更改 BorderBrush
【发布时间】:2020-05-26 19:11:52
【问题描述】:

我想用 MultiDataTrigger 更改我的 DataPicker 和 ComboBox 的 BorderBrush。我有3个条件。 它适用于 TextBox 和 TextBlock,但相同的代码不适用于我的 DatePicker 和 ComboBox。请问你知道为什么吗?我的代码:

 <ComboBox.Style>
      <Style TargetType="ComboBox">
      <Setter Property="BorderBrush" Value="Transparent" />
      <Style.Triggers>
          <MultiDataTrigger>
             <MultiDataTrigger.Conditions>
                <Condition Binding="{Binding ElementName=ProgramNameComboBox, Path=IsEnabled}" Value="True" />
                <Condition Binding="{Binding ElementName=ProgramNameComboBox, Path=SelectedItem}" Value="" />
                <Condition Binding="{Binding ElementName=SaveLabel, RelativeSource={RelativeSource Self}, Path=Content}" Value="Save" />
             </MultiDataTrigger.Conditions>
             <Setter Property="BorderBrush" Value="Red" />
          </MultiDataTrigger>
      </Style.Triggers>
      </Style>
</ComboBox.Style>


<DatePicker x:Name="StartDateDataPicker" IsEnabled="{Binding IsRowEnabled}" SelectedDate="{Binding StartDate, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" >     <!--BorderBrush="{Binding StartDateBorderBrushColor}"-->
    <DatePicker.Style>
        <Style TargetType="DatePicker">
            <Setter Property="BorderBrush" Value="Transparent" />
            <Style.Triggers>
                <MultiDataTrigger>
                    <MultiDataTrigger.Conditions>
                        <Condition Binding="{Binding ElementName=StartDateDataPicker, Path=IsEnabled}" Value="True" />
                        <Condition Binding="{Binding ElementName=StartDateDataPicker, Path=SelectedDate}" Value="null" (I also tried : "01/01/0001") />
                        <Condition Binding="{Binding ElementName=SaveLabel, Path=Content}" Value="Save" />
                    </MultiDataTrigger.Conditions>
                    <Setter Property="BorderBrush" Value="Red" />
                </MultiDataTrigger>
            </Style.Triggers>
        </Style>
    </DatePicker.Style>
</DatePicker>

谢谢

【问题讨论】:

标签: c# wpf xaml


【解决方案1】:

null 在 XAML 中表示为 {x:Null}

<Condition Binding="{Binding ElementName=StartDateDataPicker, Path=SelectedDate}"
           Value="{x:Null}" />

然而,更改ComboBox 的边框需要more work。您需要按照建议的here 定义自己的ControlTemplate

【讨论】:

  • 谢谢,但即使我只留下一个条件它也不起作用,我认为对于组合框和 Datepicker 它的工作方式不同,但是.. 怎么样? ://
  • 因为他们有不同的控件模板。查看我的编辑。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-11-18
  • 2017-05-14
  • 1970-01-01
  • 1970-01-01
  • 2016-06-04
  • 1970-01-01
  • 2014-05-28
相关资源
最近更新 更多