1

現在、開発にWPF .NET 3.5を使用しており、ikrivのMath Converterを使用して、設計で数学的なタスクを実行することにしました。

<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>

+例外アシストによると:

InnerException: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 に答える