0

次の XAML があるとします。

<Window x:Class="Test.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="350" Width="525">

<Canvas>
    <Button Content="Write something" Canvas.Left="43" Canvas.Top="159" Width="162" Height="42" Click="Button_Click_1"/>
</Canvas>

私のViewModelはこのクラスにすることも、そのインスタンス(viewmodelロジック)を含めることもできます:

 //Here is my static class for extension methods
 public static  class ExtendenWindowClass
{

  /// <summary>
  /// Eventhandler for Button
  /// </summary>
  /// <param name="obj"></param>
  /// <param name="sender"></param>
  /// <param name="e"></param>
  public static void Button_Click_1(this MainWindow obj, object sender, RoutedEventArgs e)
  {

      MessageBox.Show("Wait 10 seconds");
      Thread.Sleep(10000);
      MessageBox.Show("Ready, now you can press again");
  }
}

そのため、うなり声はもはやコード ビハインドではなく、拡張メソッドにあります。MainWindow クラスの静的フィールドの使用は最小限であるため、スキップできます。

xaml の外観は、DataBinding オブジェクトや中かっこよりも自然です。また、概念の分離にも従います。どう思いますか ?

4

1 に答える 1