ViewManager
This commit is contained in:
parent
2cd339388f
commit
25ce5d78ba
@ -11,11 +11,34 @@ namespace CPF.Toolkit
|
|||||||
public static T View<T>(params object[] arges) where T : Window
|
public static T View<T>(params object[] arges) where T : Window
|
||||||
{
|
{
|
||||||
var view = Activator.CreateInstance(typeof(T), arges) as T;
|
var view = Activator.CreateInstance(typeof(T), arges) as T;
|
||||||
view.Initialized += View_Initialized;
|
|
||||||
view.Closing += View_Closing;
|
view.Closing += View_Closing;
|
||||||
|
view.PropertyChanged += View_PropertyChanged;
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void View_PropertyChanged(object sender, CPFPropertyChangedEventArgs e)
|
||||||
|
{
|
||||||
|
var view = sender as Window;
|
||||||
|
if (e.PropertyName == nameof(Window.DataContext))
|
||||||
|
{
|
||||||
|
if (view.DataContext is IClosable closable)
|
||||||
|
{
|
||||||
|
closable.Closable += (ss, dialogResult) =>
|
||||||
|
{
|
||||||
|
if (view.IsDialogMode == true)
|
||||||
|
{
|
||||||
|
view.DialogResult = dialogResult;
|
||||||
|
}
|
||||||
|
view.Close();
|
||||||
|
};
|
||||||
|
}
|
||||||
|
if (view.DataContext is IDialog dialog)
|
||||||
|
{
|
||||||
|
dialog.Dialog = new DialogService(view);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static void View_Closing(object sender, ClosingEventArgs e)
|
private static void View_Closing(object sender, ClosingEventArgs e)
|
||||||
{
|
{
|
||||||
var view = sender as Window;
|
var view = sender as Window;
|
||||||
@ -24,25 +47,5 @@ namespace CPF.Toolkit
|
|||||||
closable.OnClosable(sender, e);
|
closable.OnClosable(sender, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void View_Initialized(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
var view = sender as Window;
|
|
||||||
if (view.DataContext is IClosable closable)
|
|
||||||
{
|
|
||||||
closable.Closable += (ss, dialogResult) =>
|
|
||||||
{
|
|
||||||
if (view.IsDialogMode == true)
|
|
||||||
{
|
|
||||||
view.DialogResult = dialogResult;
|
|
||||||
}
|
|
||||||
view.Close();
|
|
||||||
};
|
|
||||||
}
|
|
||||||
if (view.DataContext is IDialog dialog)
|
|
||||||
{
|
|
||||||
dialog.Dialog = new DialogService(view);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user