我有一个具有differents属性的ComboBox样式,我有一个Validation.errortemplate,它以红色显示边框和文本块以在屏幕上显示错误。
我想将前景的文本块绑定到我的comboBox的Background属性。
我尝试了不同的方法,但是没有成功...
这是我的代码的一部分:
<Style x:Name="comboBoxSB" x:Key="ComboBoxStyle" TargetType="{x:Type ComboBox}">
<Setter Property="Background" Value="{Binding Background,Converter={StaticResource BackgroundToBrushConverter}}"/>
<Setter Property="FontFamily" Value="{Binding Font,Converter={StaticResource ScreenBoxFontToFontFamilyConverter}}"/>
<Setter Property="FontSize" Value="{Binding TailleDuTexte}"/>
<Setter Property="Foreground" Value="{Binding Foreground,Converter={StaticResource BackgroundToBrushConverter}}"/>
<Setter Property="FontWeight" Value="{Binding EstGras,Converter={StaticResource ResourceKey=BooleanToFontWeightConverter}}"/>
<Setter Property="Width" Value="{Binding Largeur,Converter={StaticResource NullReferenceConverter}}"/>
<Setter Property="Height" Value="{Binding Hauteur,Converter={StaticResource NullReferenceConverter}}"/>
<Setter Property="FontStyle" Value="{Binding EstItalic,Converter={StaticResource ResourceKey=BoolToItalicFontStyle}}"/>
<Setter Property="HorizontalAlignment" Value="{Binding HorizontaleAlignement,Converter={StaticResource HorizontalAlignmentConverter}}"/>
<Setter Property="VerticalAlignment" Value="{Binding VerticaleAlignement,Converter={StaticResource VerticalAlignmentConverter}}"/>
<Setter Property="Margin" Value="{Binding Marge,Converter={StaticResource ThicknessConverter}}"/>
<Setter Property="ItemsSource" Value="{Binding Source}"/>
<Setter Property="SelectedIndex" Value="{Binding IndexParDefaut}"/>
<Setter Property="BorderThickness" Value="{Binding Bordure.Epaisseur,Converter={StaticResource ThicknessConverter}}"/>
<Setter Property="BorderBrush" Value="{Binding Bordure.Foreground,Converter={StaticResource BackgroundToBrushConverter}}"/>
<Setter Property="IsTabStop" Value="False"/>
<Setter Property="Validation.errortemplate">
<Setter.Value>
<ControlTemplate >
<StackPanel>
<Border BorderBrush="Red" BorderThickness="3" >
<AdornedElementPlaceholder/>
</Border>
HERE I WOULD LIKE TO BIND THE FOREGROUND'S TEXTBLOCK TO MY COMBOBOX'S BACKGROUND PROPERTY.
<TextBlock Name="txtError" Text="{Binding [0].ErrorContent}" Foreground="Red" FontSize="20"/>
</StackPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="SelectedItem">
<Setter.Value>
<Binding Path="ItemSelected" ValidatesOnNotifyDataErrors="True" >
<!--On ne passe pas par la validation rules pour le moment,mais on laisse cette partie du code commentée-->
<!--<Binding.ValidationRules>
<visualViewItems2:ValidationComboRules ValidatesOnTargetUpdated="False"/>
</Binding.ValidationRules>-->
</Binding>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="Validation.HasError" Value="False">
<Setter Property="ToolTip" Value="{Binding RelativeSource={RelativeSource Self},Path=(Validation.Errors)[0].ErrorContent}"/>
</Trigger>
</Style.Triggers>
</Style>
我尝试了这个但没有效果:
Foreground="{Binding RelativeSource={RelativeSource TemplatedParent},Path=Background}"
或
Foreground="{Binding Content.Background,RelativeSource={RelativeSource TemplatedParent}}
有人对此有任何想法吗?
谢谢