【发布时间】:2018-09-13 04:02:33
【问题描述】:
我想问为什么在使用RelativeSource={RelativeSource Self} 时总是得到空值。
<TextBlock Tag="{Binding SomeValue}" Text="{Binding SomeValue, Mode=TwoWay, NotifyOnTargetUpdated=True, Converter={StaticResource enumConverter}, ConverterParameter={x:Type EnumModel:SomeEnum},UpdateSourceTrigger=PropertyChanged}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="TargetUpdated">
<i:InvokeCommandAction Command="{Binding DataContext.SomeCommand, RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type v:MyView}}}"
CommandParameter="{Binding Tag, RelativeSource={RelativeSource Self}}" />
</i:EventTrigger>
</i:Interaction.Triggers>
</TextBlock>
我已经通过使用ElementName 解决了这个问题,如下所示:
<TextBlock x:Name="txtSortDirection" Tag="{Binding SomeValue}" Text="{Binding SomeValue, Mode=TwoWay, NotifyOnTargetUpdated=True, Converter={StaticResource enumConverter}, ConverterParameter={x:Type EnumModel:SomeEnum},UpdateSourceTrigger=PropertyChanged}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="TargetUpdated">
<i:InvokeCommandAction Command="{Binding DataContext.SomeCommand, RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type v:MyView}}}"
CommandParameter="{Binding Tag, ElementName=txtSortDirection}" />
</i:EventTrigger>
</i:Interaction.Triggers>
</TextBlock>
但我仍然想知道为什么我在使用 RelativeSource={RelativeSource Self} 时会得到 null?
【问题讨论】:
标签: wpf xaml data-binding