我目前正在使用.NET 3.5进行开发,使用ikriv的数学转换器,我决定在我的设计中做一个数学任务:
<ControlTemplate x:Key="RectangleTemplate">
<Grid Background="Transparent">
<Rectangle x:Name="Shape" Stroke="#d69e31" Fill="{StaticResource YellowGradientBrush}">
<!-- Create a rectangle that applies Cornering accoding to it's (in form) indicated height -->
<Rectangle.RadiusX>
<MultiBinding Converter="{StaticResource MathConverter}" ConverterParameter="x/2.5">
<!-- Error occurs in the line below -->
<Binding Path="Object" ElementName="{TemplateBinding Property=Button.Height}" />
</MultiBinding>
</Rectangle.RadiusX>
<Rectangle.RadiusY>
<MultiBinding Converter="{StaticResource MathConverter}" ConverterParameter="x/2.5">
<!-- Error occurs in the line below -->
<TemplateBinding Property="Button.Height" />
</MultiBinding>
</Rectangle.RadiusY>
</Rectangle>
</Grid>
</ControlTemplate>+Exception assist表示:
InnerException: System.InvalidCastException
将'System.Windows.TemplateBindingExpression‘类型的对象强制转换为'System.String’类型的Message=Unable。
谢谢。
发布于 2012-03-01 02:39:20
是的,该行中有一个错误。请提供更多信息,说明您在绑定中引用的按钮在哪里。
如果它是您为其创建模板的控件,您可以尝试删除行:
<!-- this line causes an error -->
<Binding Path="Object" ElementName="{TemplateBinding Property=Button.Height}" />并将其替换为新的:
<Binding RelativeSource="{RelativeSource TemplatedParent}" Path="Height" />https://stackoverflow.com/questions/9504301
复制相似问题