第二个调用I:EventTrigger条件

时间:2017-05-15 11:22:34

标签: c# wpf xaml interaction eventtrigger

我有两个CustomButton的{​​{1}}。第一个Interaction调用方法(SubmitResult),第二个(ClosePopupAction)只应在第一个调用的结果上调用。我使用I:EventTrigger属性的实现不起作用。

XAML

IsEnabled

C#代码

<Controls:CustomButton>
    <I:Interaction.Triggers>
        <I:EventTrigger EventName="CustomClick">
            <Ei:CallMethodAction TargetObject="{Binding RelativeSource={RelativeSource TemplatedParent}}" MethodName="SubmitData"/>
        </I:EventTrigger>
        <I:EventTrigger EventName="CustomClick">
            <Actions:ClosePopupAction IsEnabled="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=InvokeClose, UpdateSourceTrigger=PropertyChanged}"/>
        </I:EventTrigger>
    </I:Interaction.Triggers>
</Controls:CustomButton>

动作

public bool InvokeClose
{
    get { return _InvokeClose; }
    set
    {
        if (_InvokeClose == value) return;
        _InvokeClose = value;
        OnPropertyChanged();
    }
}
private bool _InvokeClose;

public void SubmitData()
{
    InvokeClose = true;
}

如果我将public class ClosePopupAction:TargetedTriggerAction<DependencyObject> { protected override void Invoke(object parameter) { HtChildWindow window = FindChildWindow(AssociatedObject); window?.Close(); } private HtChildWindow FindChildWindow(DependencyObject element) { IAttachedObject attachedObject = element as IAttachedObject; if(attachedObject != null) return FindChildWindow(attachedObject.AssociatedObject); HtChildWindow childWindow = element as HtChildWindow; return childWindow ?? FindChildWindow(VisualTreeHelper.GetParent(element)); } } 设置为InvokeClose作为initalValue,则效果与预期一致。

0 个答案:

没有答案