2012-02-29 110 views
1

我目前使用WPF .NET 3.5开发,使用ikriv的数学转换,我决定做一个数学问题在我的设计:在XAML绑定,XAML解析异常

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

谢谢。

+0

是的,有一个错误那条线。请给出一些关于你想要绑定的信息。 – 2012-02-29 18:33:50

回答

2

是的,该行有错误。请提供一些关于您在该绑定中引用的按钮位置的更多信息。

如果它是你创建的模板控制,你可以尝试删除行:

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

,并取代它与一个新问题:

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

感谢朋友,它的工作。 – lkn2993 2012-02-29 19:00:33