2016-07-01 7 views
0

Ich bin dabei, eine WPF-Anwendung von der Verwendung von PRISM 4 auf PRISM 6.1 zu aktualisieren. Diese Anwendung verwendet eine Klasse mit CommandBehaviorBase als Basisklasse. Es ruft eine Methode namens ExecuteCommand auf. In einem Artikel über die Aktualisierung auf PRISM 5 (Upgrade from 4.1 to 5) sehe ich, dass diese Methode jetzt einen Parameter benötigt. (Die CommandBehaviorBase-Klasse wurde aus dem Commands-Namespace in den Namespace Prism.Interactivity verschoben. Die ExecuteCommand-Methode akzeptiert jetzt ein Objekt als Parameter.). Meine Frage ist, welches Objekt ich an diese Methode weitergeben soll?Welchen Parameter verwendet CommandBehaviorBase.ExcuteCommand() in PRISM 6

Der Code für die Klasse, wie es jetzt ist:

/// <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; 
     } 
    } 
} 

Dankbar für jede Hilfe zu diesem Thema.

Grüße Gert

Antwort

Verwandte Themen