インタラクティブトリガーでいくつかの追加条件を使用する必要があります。例:
イベントへの反応として、コマンドを実行したいのですが、条件が一致した場合に限ります。また、コマンドが少し遅れて実行されるようにしたいです。私はその疑似xamlでこれを表現することができます。
<ci:RoutedEventTrigger Event="{x:Static Selector.SelectionChangedEvent}">
<li:TriggerCondition ActualValue="{Binding Value}" ExpectedValue="{StaticResource foo}">
<li:DelayAction DelayTime="{StaticResource delayTime}">
<InvokeCommandAction CommandName="{StaticResourc commandName}"/>
</li:DelayAction>
</li:TriggerCondition>
</ci:RoutedEventTrigger>
TriggerConditionクラスとDelayActionクラスを作成しようとしましたが、ほとんどすべてのInteractivityコードは内部にあります。
だから問題は、どうすれば望ましい行動に到達できるかということです。条件と遅延を使用してRoutedEventTriggerを作成することは、それほど一般的ではないように見えます。さらに、InputBindingTriggerとその他のいくつかがあります。
前もって感謝します
更新: 私はリフレクションを使用して欲しいものを作りましたが、それでも正しい方法でそれを行う方法についてのあなたの提案を探しています:)
[ContentProperty("Actions")]
public abstract class TriggerDecorator : TriggerAction<DependencyObject>
{
private static readonly DependencyPropertyKey ActionsPropertyKey =
DependencyProperty.RegisterReadOnly("Actions", typeof (TriggerActionCollection),typeof (TriggerDecorator), new FrameworkPropertyMetadata());
public static readonly DependencyProperty ActionsProperty = ActionsPropertyKey.DependencyProperty;
public TriggerActionCollection Actions
{
get { return (TriggerActionCollection) GetValue(ActionsProperty); }
}
private readonly MethodInfo myTriggerAction_CallInvokeMethod;
public TriggerDecorator()
{
var triggerActionType = typeof (TriggerAction);
myTriggerAction_CallInvokeMethod = triggerActionType.GetMethod("CallInvoke", BindingFlags.Instance | BindingFlags.NonPublic);
if(myTriggerAction_CallInvokeMethod == null)
throw new InvalidOperationException();
var actionCollection = (TriggerActionCollection)Activator.CreateInstance(typeof(TriggerActionCollection), true);
SetValue(ActionsPropertyKey, actionCollection);
}
protected override void OnAttached()
{
base.OnAttached();
if(AssociatedObject == null)
return;
Actions.Attach(AssociatedObject);
}
protected override void OnDetaching()
{
base.OnDetaching();
Actions.Detach();
}
protected void ExecuteActions(object parameter)
{
var param = new[] {parameter};
foreach (var triggerAction in Actions)
myTriggerAction_CallInvokeMethod.Invoke(triggerAction, param);
}
}