2017-04-10 39 views
0

有一个边框,我想同时更改它的边框颜色和背景颜色。 所以,我定义了一个风格波纹管wpf风格,如何将边框的borderbrush引用到背景

<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变化。

回答

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> 
+0

是的,我想要一个不透明度 –

1

使与RelativeSource Self绑定:

<Setter Property="Background" 
     Value="{Binding Path=BorderBrush, RelativeSource={RelativeSource Self}"/> 
+0

谢谢,这真的有帮助 –