整理控件库
This commit is contained in:
@@ -7,24 +7,15 @@ namespace WPFluent.Gallery.Services;
|
||||
|
||||
public class WindowsProviderService
|
||||
{
|
||||
private readonly IServiceProvider _serviceProvider;
|
||||
|
||||
public WindowsProviderService(IServiceProvider serviceProvider)
|
||||
{
|
||||
_serviceProvider = serviceProvider;
|
||||
}
|
||||
|
||||
public void Show<T>()
|
||||
where T : class
|
||||
where T : Window, new()
|
||||
{
|
||||
if (!typeof(Window).IsAssignableFrom(typeof(T)))
|
||||
{
|
||||
throw new InvalidOperationException($"The window class should be derived from {typeof(Window)}.");
|
||||
}
|
||||
|
||||
Window windowInstance =
|
||||
_serviceProvider.GetService<T>() as Window
|
||||
?? throw new InvalidOperationException("Window is not registered as service.");
|
||||
Window windowInstance = new T();
|
||||
windowInstance.Owner = Application.Current.MainWindow;
|
||||
windowInstance.Show();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user