2016-07-01 4 views
0

PRISM 4を使用してPRISM 6.1を使用するWPFアプリケーションのアップグレード中です。このアプリケーションは、基本クラスとしてCommandBehaviorBaseを持つクラスを使用します。 ExecuteCommandというメソッドを呼び出します。 PRISM 5(Upgrade from 4.1 to 5)へのアップグレードについて議論している記事では、このメソッドにパラメータが必要になることがわかりました。 (CommandBehaviorBaseクラスがCommands名前空間からPrism.Interactivity名前空間に移動されました.ExecuteCommandメソッドはオブジェクトをパラメータとして受け取ります。)。私の質問は、どのようなオブジェクトを私はそのメソッドに渡す必要がありますか?PRISM 6でCommandBehaviorBase.ExcuteCommand()が使用するパラメータ

それが今であるとしてクラスのコード:

/// <summary> 
/// Defines a behavior that executes a <see cref="ICommand"/> when the Return key is pressed inside a <see cref="TextBox"/>. 
/// </summary> 
/// <remarks>This behavior also supports setting a basic watermark on the <see cref="TextBox"/>.</remarks> 
public class ReturnCommandBehavior : CommandBehaviorBase<TextBox> 
{ 
    /// <summary> 
    /// Initializes a new instance of <see cref="ReturnCommandBehavior"/>. 
    /// </summary> 
    /// <param name="textBox">The <see cref="TextBox"/> over which the <see cref="ICommand"/> will work.</param> 
    public ReturnCommandBehavior(TextBox textBox) 
     : base(textBox) 
    { 
     textBox.AcceptsReturn = false; 
     textBox.KeyDown += (s, e) => this.KeyPressed(e.Key); 
     textBox.GotFocus += (s, e) => this.GotFocus(); 
     textBox.LostFocus += (s, e) => this.LostFocus(); 
    } 

    /// <summary> 
    /// Gets or Sets the text which is set as water mark on the <see cref="TextBox"/>. 
    /// </summary> 
    public string DefaultTextAfterCommandExecution { get; set; } 

    /// <summary> 
    /// Executes the <see cref="ICommand"/> when <paramref name="key"/> is <see cref="Key.Enter"/>. 
    /// </summary> 
    /// <param name="key">The key pressed on the <see cref="TextBox"/>.</param> 
    protected void KeyPressed(Key key) 
    { 
     if (key == Key.Enter && TargetObject != null) 
     { 
      this.CommandParameter = TargetObject.Text; 
      ExecuteCommand(); 


      this.ResetText(); 
     } 
    } 

    private void GotFocus() 
    { 
     if (TargetObject != null && TargetObject.Text == this.DefaultTextAfterCommandExecution) 
     { 
      this.ResetText(); 
     } 
    } 

    private void ResetText() 
    { 
     TargetObject.Text = string.Empty; 
    } 

    private void LostFocus() 
    { 
     if (TargetObject != null && string.IsNullOrEmpty(TargetObject.Text) && this.DefaultTextAfterCommandExecution != null) 
     { 
      TargetObject.Text = this.DefaultTextAfterCommandExecution; 
     } 
    } 
} 

グレイトフル・この上の任意の助け。

に関して直感的に ゲルト

答えて

関連する問題