在WPF中,为什么似乎是Rectangle.Fill财产不使用TemplateBinding何时工作?
-
21-08-2019 - |
题
我想不通为什么这个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>
任何想法?
编辑:的,以澄清,我打算扩大这还是用渐变画笔,这就是为什么我需要能够使用分配给Rectangle.Fill财产XAML代替纯字符串。
解决方案
这是因为颜色具有不同的类型,那么背景
背景是刷,颜色是..好..颜色可以使用的IValueConverter你刷转换成颜色..
HTH
不隶属于 StackOverflow