Skip to content

Instantly share code, notes, and snippets.

@masaru-b-cl
Created November 21, 2013 14:47
Show Gist options
  • Select an option

  • Save masaru-b-cl/7582834 to your computer and use it in GitHub Desktop.

Select an option

Save masaru-b-cl/7582834 to your computer and use it in GitHub Desktop.
WeakEventパターンで実装
using System;
using System.Windows;
namespace WpfApplication1
{
/// <summary>
/// MainWindow.xaml の相互作用ロジック
/// </summary>
public partial class MainWindow : Window
{
private readonly MainWindowViewModel vm;
public MainWindow()
{
InitializeComponent();
vm = DataContext as MainWindowViewModel;
WeakEventManager<MainWindowViewModel, EventArgs>.AddHandler(vm, "Hide", (sender, e) => this.Hide());
}
private void Button_Click(object sender, RoutedEventArgs e)
{
vm.HideWindow();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment