[英]Use RelativeSource as a ConverterParameter in a style
I am trying to use a converter in an items control ItemContainerStyle
to convert a property of an item in the ItemsControl
to an X value. 我试图在项目控件
ItemContainerStyle
使用转换器,将ItemsControl
项目的属性转换为X值。 To do the conversion, I also need a reference to the parent UserControl
that the ItemsControl
is contained in. I tried to use RelativeSource
, but in the Convert
function, the parameter is not a UserControl
but an instance of RelativeSource
. 要进行转换,我还需要引用包含
ItemsControl
的父UserControl
。我尝试使用RelativeSource
,但是在Convert
函数中,该参数不是UserControl
而是RelativeSource
的实例。 Here's my XAML: 这是我的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>
Is there something wrong with my syntax, or is there another way of achieving this? 我的语法有问题吗,还是有另一种方法来实现呢?
如果需要绑定Parameter
,则通常应使用MultiBinding
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.