我有两个CustomButton
的{{1}}。第一个Interaction调用方法(SubmitResult),第二个(ClosePopupAction)只应在第一个调用的结果上调用。我使用I:EventTrigger
属性的实现不起作用。
IsEnabled
<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,则效果与预期一致。