首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么在使用RelativeSource={RelativeSource自}时总是获得null?

为什么在使用RelativeSource={RelativeSource自}时总是获得null?
EN

Stack Overflow用户
提问于 2018-09-13 04:02:33
回答 1查看 439关注 0票数 0

我想问为什么在使用RelativeSource={RelativeSource Self}时我总是获得null。

代码语言:javascript
复制
<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来解决这个问题,如下所示:

代码语言:javascript
复制
<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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-09-14 03:22:14

RelativeSource={RelativeSource Self}用于获取此绑定属性属于元素作为绑定源。

只在UIElement.上工作的

你试着在i:InvokeCommandAction in Trigger上使用它,但是它不是

顺便说一句:但是它能在DataTrigger上工作。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52306471

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档