我不明白为什么这个 XAML 代码不起作用。使用 TemplateBinding(见下文)时,未设置背景颜色。但是当我使用正常的颜色字符串(即“红色”)时,它可以正常工作。
<ControlTemplate x:Key="InstanceButtonTemplate" TargetType="{x:Type Control}">
<Grid>
<Rectangle>
<Rectangle.Fill>
<SolidColorBrush Color="{TemplateBinding Background}"></SolidColorBrush>
</Rectangle.Fill>
</Rectangle>
</Grid>
</ControlTemplate>
然而,当我以这种方式使用 TemplateBinding 时,它工作得很好......
<ControlTemplate x:Key="InstanceButtonTemplate" TargetType="{x:Type Control}">
<Grid>
<Rectangle Fill="{TemplateBinding Background}"></Rectangle>
</Grid>
</ControlTemplate>
有任何想法吗?
编辑:澄清一下,我打算将其扩展为使用渐变画笔,这就是为什么我需要能够使用 XAML 而不是纯字符串分配给 Rectangle.Fill 属性。