1

我目前正在使用 WPF .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>

+异常协助 说:

内部异常:System.InvalidCastException

消息=无法将“System.Windows.TemplateBindingExpression”类型的对象转换为“System.String”类型。

谢谢。

4

1 回答 1

3

是的,该行有错误。请提供有关您在该绑定中引用的按钮在哪里的更多信息。

如果它是您为其创建模板的控件,您可以尝试删除该行:

<!-- this line causes an error -->
<Binding Path="Object" ElementName="{TemplateBinding Property=Button.Height}" />

并用一个新的替换它:

<Binding RelativeSource="{RelativeSource TemplatedParent}" Path="Height" />
于 2012-02-29T18:39:19.793 回答