Bunch of insane work
This commit is contained in:
@@ -1,15 +0,0 @@
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
|
||||
namespace Hyperbar.UI.Windows;
|
||||
|
||||
public class DataTemplateConverter :
|
||||
ValueConverter<object, DataTemplateSelector>
|
||||
{
|
||||
protected override DataTemplateSelector? ConvertTo(object value,
|
||||
Type? targetType,
|
||||
object? parameter,
|
||||
string? language)
|
||||
{
|
||||
return new TemplateGenerator();
|
||||
}
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace Hyperbar.UI.Windows;
|
||||
|
||||
public class TemplateFactory(IEnumerable<IContentTemplateDescriptor> descriptors,
|
||||
IServiceProvider provider) :
|
||||
ITemplateFactory
|
||||
{
|
||||
public object? Create(object key)
|
||||
{
|
||||
if (descriptors.FirstOrDefault(x => x.Key == key)
|
||||
is IContentTemplateDescriptor descriptor)
|
||||
{
|
||||
if (provider.GetRequiredKeyedService(descriptor.TemplateType,
|
||||
descriptor.Key) is { } template)
|
||||
{
|
||||
return template;
|
||||
}
|
||||
}
|
||||
|
||||
return default;
|
||||
}
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
using Microsoft.UI.Xaml.Markup;
|
||||
|
||||
namespace Hyperbar.UI.Windows;
|
||||
|
||||
public class TemplateGenerator : DataTemplateSelector
|
||||
{
|
||||
protected override DataTemplate SelectTemplateCore(object item)
|
||||
{
|
||||
string xamlString = @"
|
||||
<DataTemplate xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""
|
||||
xmlns:ui=""using:Hyperbar.UI.Windows"">
|
||||
<ui:TemplateGeneratorControl VerticalContentAlignment=""Stretch""
|
||||
HorizontalContentAlignment=""Stretch""
|
||||
HorizontalAlignment=""Stretch""
|
||||
VerticalAlignment=""Stretch""/>
|
||||
</DataTemplate>";
|
||||
|
||||
return (DataTemplate)XamlReader.Load(xamlString);
|
||||
}
|
||||
|
||||
protected override DataTemplate SelectTemplateCore(object item, DependencyObject container)
|
||||
{
|
||||
string xamlString = @"
|
||||
<DataTemplate xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""
|
||||
xmlns:ui=""using:Hyperbar.UI.Windows"">
|
||||
<ui:TemplateGeneratorControl VerticalContentAlignment=""Stretch""
|
||||
HorizontalContentAlignment=""Stretch""
|
||||
HorizontalAlignment=""Stretch""
|
||||
VerticalAlignment=""Stretch""/>
|
||||
</DataTemplate>";
|
||||
|
||||
return (DataTemplate)XamlReader.Load(xamlString);
|
||||
}
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
|
||||
namespace Hyperbar.UI.Windows;
|
||||
|
||||
public class TemplateGeneratorControl :
|
||||
ContentControl
|
||||
{
|
||||
public TemplateGeneratorControl()
|
||||
{
|
||||
DataContextChanged += OnDataContextChanged;
|
||||
}
|
||||
|
||||
private void OnDataContextChanged(FrameworkElement sender,
|
||||
DataContextChangedEventArgs args)
|
||||
{
|
||||
if (DataContext is ITemplatedViewModel templatedViewModel)
|
||||
{
|
||||
Content = templatedViewModel.TemplateFactory.Create(DataContext.GetType().Name);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
|
||||
namespace Hyperbar.UI.Windows;
|
||||
|
||||
public class ViewModelTemplatePresenter :
|
||||
ContentPresenter
|
||||
{
|
||||
public ViewModelTemplatePresenter()
|
||||
{
|
||||
DataContextChanged += OnDataContextChanged;
|
||||
}
|
||||
|
||||
private void OnDataContextChanged(FrameworkElement sender,
|
||||
DataContextChangedEventArgs args)
|
||||
{
|
||||
//if (DataContext is IViewModelTemplate templatedViewModel)
|
||||
//{
|
||||
// Content = templatedViewModel.TemplateFactory
|
||||
// .Create(DataContext.GetType().Name);
|
||||
//}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
using Microsoft.UI.Xaml.Markup;
|
||||
|
||||
namespace Hyperbar.UI.Windows;
|
||||
|
||||
public class ImplicitTemplate :
|
||||
MarkupExtension
|
||||
{
|
||||
protected override object ProvideValue(IXamlServiceProvider serviceProvider) =>
|
||||
new ImplicitTemplateSelector();
|
||||
|
||||
internal class ImplicitTemplateSelector :
|
||||
DataTemplateSelector
|
||||
{
|
||||
protected override DataTemplate SelectTemplateCore(object item,
|
||||
DependencyObject container)
|
||||
{
|
||||
|
||||
|
||||
string xamlString = @"
|
||||
<DataTemplate xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""
|
||||
xmlns:ui=""using:Hyperbar.UI.Windows"">
|
||||
<ui:ViewModelTemplatePresenter VerticalContentAlignment=""Stretch""
|
||||
HorizontalContentAlignment=""Stretch""
|
||||
HorizontalAlignment=""Stretch""
|
||||
VerticalAlignment=""Stretch""/>
|
||||
</DataTemplate>";
|
||||
|
||||
return (DataTemplate)XamlReader.Load(xamlString);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class ViewModelTemplate :
|
||||
MarkupExtension
|
||||
{
|
||||
protected override object ProvideValue(IXamlServiceProvider serviceProvider) =>
|
||||
new ViewModelTemplateSelector();
|
||||
|
||||
internal class ViewModelTemplateSelector :
|
||||
DataTemplateSelector
|
||||
{
|
||||
protected override DataTemplate SelectTemplateCore(object item)
|
||||
{
|
||||
if (item is IObservableViewModel observableViewModel)
|
||||
{
|
||||
if (observableViewModel.ServiceProvider.GetService<IViewModelTemplateDescriptorProvider>()
|
||||
is ViewModelTemplateDescriptorProvider descriptors)
|
||||
{
|
||||
if (descriptors.Get(item.GetType().Name) is IViewModelTemplateDescriptor descriptor)
|
||||
{
|
||||
string xamlString = @$"
|
||||
<DataTemplate xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""
|
||||
xmlns:ui=""using:{descriptor.TemplateType.Namespace}"">
|
||||
<ui:{descriptor.TemplateType.Name} />
|
||||
</DataTemplate>";
|
||||
|
||||
return (DataTemplate)XamlReader.Load(xamlString);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return new DataTemplate();
|
||||
}
|
||||
|
||||
protected override DataTemplate SelectTemplateCore(object item,
|
||||
DependencyObject container)
|
||||
{
|
||||
if (item is IObservableViewModel observableViewModel)
|
||||
{
|
||||
if (observableViewModel.ServiceProvider.GetService<IViewModelTemplateDescriptorProvider>()
|
||||
is ViewModelTemplateDescriptorProvider descriptors)
|
||||
{
|
||||
if (descriptors.Get(item.GetType().Name) is IViewModelTemplateDescriptor descriptor)
|
||||
{
|
||||
string xamlString = @$"
|
||||
<DataTemplate xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""
|
||||
xmlns:ui=""using:{descriptor.TemplateType.Namespace}"">
|
||||
<ui:{descriptor.TemplateType.Name} />
|
||||
</DataTemplate>";
|
||||
|
||||
return (DataTemplate)XamlReader.Load(xamlString);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return new DataTemplate();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,17 @@
|
||||
using Hyperbar.Interop.Windows;
|
||||
using Microsoft.UI.Windowing;
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
using Windows.Graphics;
|
||||
using WinRT.Interop;
|
||||
|
||||
namespace Hyperbar.UI.Windows;
|
||||
|
||||
public class NavigationItemTemplateSelector :
|
||||
DataTemplateSelector
|
||||
{
|
||||
|
||||
}
|
||||
public static class WindowExtensions
|
||||
{
|
||||
public static WindowMessageListener CreateMessageListener(this Window window) =>
|
||||
@@ -36,6 +42,16 @@ public static class WindowExtensions
|
||||
public static void SetStyle(this Window window,
|
||||
ExtendedWindowStyle style) => window.GetHandle().SetExtendedWindowStyle(style);
|
||||
|
||||
public static void TitleBarConfiguration(this Window window,
|
||||
Action<AppWindowTitleBar> titleBarDelegate)
|
||||
{
|
||||
AppWindow appWindow = window.AppWindow;
|
||||
if (appWindow.TitleBar is AppWindowTitleBar titleBar)
|
||||
{
|
||||
titleBarDelegate.Invoke(titleBar);
|
||||
}
|
||||
}
|
||||
|
||||
public static void SetTopMost(this Window window,
|
||||
bool value)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user