我想定义一个从其他资源获取颜色的画笔。就是这样
<Color x:Key="MyColor">#003C83</Color>
<Brush x:Key="MyColor.Brush" Color="{StaticResource MyColor}" />
我该怎么做?
答案 0 :(得分:2)
您应该使用特定类型的Brush,因为它是@elgonzo所说的抽象类...这是一个SolidColorBrush
的简单示例:
<Window x:Class="XAMLTest.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:XAMLTest"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Window.Resources>
<Color x:Key="MyColor">#003C83</Color>
<SolidColorBrush x:Key="MyColor.Brush" Color="{StaticResource MyColor}" />
</Window.Resources>
<Grid>
<Border BorderBrush="{StaticResource MyColor.Brush}" BorderThickness="5" Background="Yellow" Height="20" Width="100" HorizontalAlignment="Center"/>
</Grid>
</Window>
结果:
请尝试在MSDN上阅读WPF Brushes Overview ...