Почему при использовании RelativeSource = {RelativeSource Self} всегда я получаю нулевое значение? - PullRequest
0 голосов
/ 13 сентября 2018

Я хотел бы спросить, почему при использовании 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}?

1 Ответ

0 голосов
/ 14 сентября 2018

RelativeSource={RelativeSource Self} используется для получения самого элемента в качестве источника в Binding.

И действует только на UIElement.

Но вы используете его на i:InvokeCommandAction в Trigger, Это не UIElement.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...