Why the TargetedTriggerAction's TargetObject i

2019-09-13 06:57发布

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')

2条回答
倾城 Initia
2楼-- · 2019-09-13 07:56

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>
查看更多
Luminary・发光体
3楼-- · 2019-09-13 08:00

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

{Binding Path=OKGenderButton }
查看更多
登录 后发表回答