wil*_*lem 1 wpf templatebinding
我无法弄清楚为什么这个XAML代码不起作用.使用TemplateBinding(见下文)时,未设置背景颜色.但是当我使用普通的颜色字符串(即"红色")时,它工作正常.
<ControlTemplate x:Key="InstanceButtonTemplate" TargetType="{x:Type Control}">
<Grid>
<Rectangle>
<Rectangle.Fill>
<SolidColorBrush Color="{TemplateBinding Background}"></SolidColorBrush>
</Rectangle.Fill>
</Rectangle>
</Grid>
</ControlTemplate>
Run Code Online (Sandbox Code Playgroud)
然而,当我以这种方式使用TemplateBinding时,它工作正常......
<ControlTemplate x:Key="InstanceButtonTemplate" TargetType="{x:Type Control}">
<Grid>
<Rectangle Fill="{TemplateBinding Background}"></Rectangle>
</Grid>
</ControlTemplate>
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
编辑:为了澄清,我打算将其扩展为使用渐变画笔,这就是为什么我需要能够使用XAML而不是普通字符串分配给Rectangle.Fill属性.
| 归档时间: |
|
| 查看次数: |
3737 次 |
| 最近记录: |