使用现有画笔设置背景

时间:2012-05-30 10:04:23

标签: wpf xaml

想象一下,我有这个画笔:

<SolidColorBrush x:Key="MySolidDarkBackground" Color="{DynamicResource DarkBackgroundColorTop}" />

如何将此画笔用于滚动查看器背景但具有不同的不透明度?

<ScrollViewer VerticalScrollBarVisibility="Auto" Grid.Row="1">
            <ScrollViewer.Background>
                < ??? >
            </ScrollViewer.Background>
</ScrollViewer>

1 个答案:

答案 0 :(得分:1)

您必须创建第二个Brush资源并使用它:

<SolidColorBrush x:Key="MyTransparentDarkBackground" Opacity="0.5" Color="{DynamicResource DarkBackgroundColorTop}" />
<ScrollViewer Background="{DynamicResource MyTransparentDarkBackground}" />

或者您可以重复使用动态Color资源:

<ScrollViewer>
  <ScrollViewer.Background>
    <SolidColorBrush Opacity="0.5" Color="{DynamicResource DarkBackgroundColorTop}" />
  </ScrollViewer.Background>
</ScrollViewer>