Why the TargetedTriggerAction's TargetObject is always null
Asked Answered
H

2

0

I have three Buttons (1.Male,2.Femal,3.OK),I want to change the CommandParameters Property of Button(OK) by Click Male Button or FeMale Button. I found the question Setting a property with an EventTrigger is very helpful to me, but the TargetObject of TargetedTriggerAction<FrameworkElement> in void Invoke(object parameter){...} function is always null, WHY ?

HOW Can I to solve the Problem? enter image description here enter image description here

Error info in output window.

System.Windows.Data Error: 4 : Cannot find source for binding with reference 'ElementName=OKGenderButton'. BindingExpression:(no path); DataItem=null; target element is 'SetterAction' (HashCode=20203785); target property is 'TargetObject' (type 'Object')

Higgledypiggledy answered 8/11, 2016 at 2:53 Comment(0)
D
0

As the error indicated, bindingExpression has no path. Try to add a Path

{Binding Path=OKGenderButton }
Dubbin answered 8/11, 2016 at 3:28 Comment(0)
H
0

As the question ElementName Binding is failingmentioned,

The code Source={x:Reference DisplayMarkers} works

Demo Code:

<Button Grid.Row="2" Grid.Column="1"
                        Content="FeMale"
                        Margin="0 0 90 0"
                        VerticalAlignment="Bottom"
                        HorizontalAlignment="Right"
                        Width="93"
                        Height="93"
                        Style="{DynamicResource FemaleButton}">
                    <i:Interaction.Triggers>
                        <i:EventTrigger EventName="Click">
                            <triggerActions:SetterAction PropertyName="CommandParameter"
                                                         TargetObject="{x:Reference OKGenderButton}"
                                                         Value="{x:Static constants:Genders.FeMale}" />

                        </i:EventTrigger>
                    </i:Interaction.Triggers>
                </Button>
Higgledypiggledy answered 8/11, 2016 at 3:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.