привязка в xaml, исключение xaml parse - PullRequest
1 голос
/ 29 февраля 2012

В настоящее время я использую 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>

+ Помощник по исключениям говорит:

InnerException: System.InvalidCastException

Сообщение = Невозможно привести объект типа 'System.Windows.TemplateBindingExpression' к типу 'System.String'.

Спасибо.

1 Ответ

2 голосов
/ 29 февраля 2012

Да, в этой строке есть ошибка.Пожалуйста, дайте больше информации о том, где находится кнопка, на которую вы ссылаетесь в этой привязке.

Если вы создаете шаблон для элемента управления, попробуйте удалить строку:

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

и замените его новым:

<Binding RelativeSource="{RelativeSource TemplatedParent}" Path="Height" />
...