有一个边框,我想同时更改它的边框颜色和背景颜色。 所以,我定义了一个风格
<Style x:Key="EoE" TargetType="{x:Type Border}">
<Setter Property="BorderBrush" Value="{StaticResource LightGreen}"/>
<Setter Property="Background">
<Setter.Value>
<SolidColorBrush Color="{Binding Path=BorderBrush }" Opacity="1"/>
</Setter.Value>
</Setter>
<Setter Property="Effect">
<Setter.Value>
<DropShadowEffect ShadowDepth="0" Color="White" Opacity="0.5" BlurRadius="10"/>
<!--<BlurEffect Radius="3" RenderingBias="Quality"/>-->
</Setter.Value>
</Setter>
<Setter Property="BorderThickness" Value="2"></Setter>
我想在运行时更改的是borderbrush,然后我想要同时更改背景solidcolorbrush。
答案 0 :(得分:1)
与RelativeSource Self
:
<Setter Property="Background"
Value="{Binding Path=BorderBrush, RelativeSource={RelativeSource Self}"/>
答案 1 :(得分:1)
如果你真的想为边框的Opacity
属性定义另一个带有Background
的另一个画笔,你可以试试这个:
<Style x:Key="EoE" TargetType="{x:Type Border}">
<Style.Resources>
<SolidColorBrush x:Key="bgBrush" Color="{Binding Path=BorderBrush.(SolidColorBrush.Color), RelativeSource={RelativeSource AncestorType=Border}}" Opacity="0.7"/>
</Style.Resources>
<Setter Property="BorderBrush" Value="{StaticResource LightGreen}"/>
<Setter Property="Background" Value="{StaticResource bgBrush}" />
<Setter Property="Effect">
<Setter.Value>
<DropShadowEffect ShadowDepth="0" Color="White" Opacity="0.5" BlurRadius="10"/>
</Setter.Value>
</Setter>
<Setter Property="BorderThickness" Value="2"></Setter>
</Style>
如果您只想将Background
设置为与BorderBrush
完全相同的笔刷,则可以使用@ASh提供的解决方案:
<Style x:Key="EoE" TargetType="{x:Type Border}">
<Setter Property="BorderBrush" Value="{StaticResource LightGreen}"/>
<Setter Property="Background" Value="{Binding Path=BorderBrush, RelativeSource={RelativeSource Self}}"/>
<Setter Property="Effect">
<Setter.Value>
<DropShadowEffect ShadowDepth="0" Color="White" Opacity="0.5" BlurRadius="10"/>
</Setter.Value>
</Setter>
<Setter Property="BorderThickness" Value="2"></Setter>
</Style>