C# 将RelativeSource用作样式中的转换器参数
我正在尝试使用items控件C# 将RelativeSource用作样式中的转换器参数,c#,wpf,xaml,data-binding,datatemplate,C#,Wpf,Xaml,Data Binding,Datatemplate,我正在尝试使用items控件ItemContainerStyle中的转换器将ItemsControl中的项的属性转换为X值。要进行转换,我还需要一个对父UserControl的引用,其中包含ItemsControl。我试图使用RelativeSource,但在Convert函数中,参数不是UserControl,而是RelativeSource的一个实例。这是我的XAML: <ItemsControl x:Name="itemsControl"> <ItemsContr
ItemContainerStyle
中的转换器将ItemsControl
中的项的属性转换为X值。要进行转换,我还需要一个对父UserControl
的引用,其中包含ItemsControl
。我试图使用RelativeSource
,但在Convert
函数中,参数不是UserControl
,而是RelativeSource
的一个实例。这是我的XAML:
<ItemsControl x:Name="itemsControl">
<ItemsControl.ItemContainerStyle>
<Style>
<Setter Property="Canvas.Left">
<Setter.Value>
<Binding Path="StartTime"
Converter="{StaticResource startTimeToXConverter}"
ConverterParameter="{RelativeSource Mode=FindAncestor, AncestorType=UserControl}" />
</Setter.Value>
</Setter>
<Setter Property="Canvas.Top" Value="{Binding Path=Y}" />
</Style>
</ItemsControl.ItemContainerStyle>
我的语法是否有问题,或者是否有其他方法可以实现这一点?如果需要绑定
参数,通常应使用a。如果需要绑定参数,通常应使用a