-3

インタラクショントリガーを使用して、ViewModelのプロパティでPropertyChangedイベントを発生させようとしています。

CS:

public string MyContentProperty
{
    get { return "I Was Raised From an outside Source !";}
}

XAML:

<Button Content="{Binding MyContentProperty}">
    <i:Interaction.Triggers>
        <i:EventTrigger EventName="Button.Click">
               < .... what needs to be done ?>         
        </i:EventTrigger>                        
     </i:Interaction.Triggers>
</Button>

もちろん、この質問に疑問がある場合は、

 xmlns:ei="clr-namespace:Microsoft.Expression.Interactivity.Core;assembly=Microsoft.Expression.Interactions" 
 xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity" 

自由に、事前に感謝します。

4

1 に答える 1

2

通常のコマンドまたは Expression Blend のCallMethodActionInvokeCommandActionまたはChangePropertyActionを使用できます。

やりたいことを実現するための 4 つの方法を次に示します。

<Button Content="Button" Height="23" Width="100" Command="{Binding RaiseItCmd}">
    <i:Interaction.Triggers>
        <i:EventTrigger EventName="Click">
            <i:InvokeCommandAction Command="{Binding RaiseItCmd}"/>
            <ei:CallMethodAction MethodName="RaiseIt" TargetObject="{Binding}"/>
            <ei:ChangePropertyAction Value="" 
                     PropertyName="MyContentProperty" TargetObject="{Binding}"/>
        </i:EventTrigger>
    </i:Interaction.Triggers>
</Button>

ここでは、MVVM Light の ViewModelBase を使用しています。

using System.Windows.Input;
using GalaSoft.MvvmLight;
using Microsoft.Expression.Interactivity.Core;

public class ViewModel : ViewModelBase
{
    public ViewModel()
    {
        RaiseItCmd = new ActionCommand(this.RaiseIt);
    }

    public string MyContentProperty
    {
        get
        {
            return "property";
        }
        set
        {
            this.RaiseIt(); 
        }
    }

    public void RaiseIt()
    {
        RaisePropertyChanged("MyContentProperty");
    }

    public ICommand RaiseItCmd { get; private set; }
}
于 2013-03-21T22:29:16.870 に答える