我在这里得到了一些xaml,我试图做的只是在一个矩形的宽度上绑定一个属性调用Property(不是真实名称),并将这个属性的值转换为转换器名称Conv,它与{TemplateBinding Property} 或 DataContext={TemplateBinding Property} 或具有相对源(如代码示例中)。
我的问题是converterParameter 也应该是一个绑定属性,但我无法绑定converterParameter 中的任何属性。所以示例中的 30 应该类似于 {Binding Path=SecondProperty}。如果有人遇到这个问题,或者如果有人有其他方法来绑定自定义控件中的东西,非常感谢;)
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="clr-namespace:RatingControl">
<Style TargetType="controls:Ctr">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="controls:Ctr">
<Grid>
<Grid.Resources>
<controls:Converter x:Name="Conv" />
</Grid.Resources>
<Rectangle x:Name="rect" Width="{Binding Path=Property, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource Conv}, ConverterParameter=30}" Height="20" />