More work
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
using Microsoft.UI.Xaml.Data;
|
||||
|
||||
namespace Hyperbar.UI.Windows;
|
||||
|
||||
public class GridExtension
|
||||
{
|
||||
public static readonly DependencyProperty GridColumnBindingPathProperty =
|
||||
DependencyProperty.RegisterAttached("GridColumnBindingPath",
|
||||
typeof(string), typeof(GridExtension),
|
||||
new PropertyMetadata(null, OnGridBindingPathPropertyChanged));
|
||||
|
||||
public static readonly DependencyProperty GridRowBindingPathProperty =
|
||||
DependencyProperty.RegisterAttached("GridRowBindingPath",
|
||||
typeof(string), typeof(GridExtension),
|
||||
new PropertyMetadata(null, OnGridBindingPathPropertyChanged));
|
||||
|
||||
public static string GetGridColumnBindingPath(DependencyObject dependencyObject) =>
|
||||
(string)dependencyObject.GetValue(GridColumnBindingPathProperty);
|
||||
|
||||
public static string GetGridRowBindingPath(DependencyObject dependencyObject) =>
|
||||
(string)dependencyObject.GetValue(GridRowBindingPathProperty);
|
||||
|
||||
public static void SetGridColumnBindingPath(DependencyObject dependencyObject, string value) =>
|
||||
dependencyObject.SetValue(GridColumnBindingPathProperty, value);
|
||||
public static void SetGridRowBindingPath(DependencyObject dependencyObject, string value) =>
|
||||
dependencyObject.SetValue(GridRowBindingPathProperty, value);
|
||||
|
||||
private static void OnGridBindingPathPropertyChanged(DependencyObject dependencyObject,
|
||||
DependencyPropertyChangedEventArgs args)
|
||||
{
|
||||
if (args.NewValue is string propertyPath)
|
||||
{
|
||||
DependencyProperty gridProperty =
|
||||
args.Property == GridColumnBindingPathProperty
|
||||
? Grid.ColumnProperty
|
||||
: Grid.RowProperty;
|
||||
|
||||
BindingOperations.SetBinding(
|
||||
dependencyObject,
|
||||
gridProperty,
|
||||
new Binding { Path = new PropertyPath(propertyPath) });
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -11,12 +11,10 @@ public class TemplateGenerator : DataTemplateSelector
|
||||
string xamlString = @"
|
||||
<DataTemplate xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""
|
||||
xmlns:ui=""using:Hyperbar.UI.Windows"">
|
||||
<Grid>
|
||||
<ui:TemplateGeneratorControl VerticalContentAlignment=""Stretch""
|
||||
HorizontalContentAlignment=""Stretch""
|
||||
HorizontalAlignment=""Stretch""
|
||||
VerticalAlignment=""Stretch""/>
|
||||
</Grid>
|
||||
<ui:TemplateGeneratorControl VerticalContentAlignment=""Stretch""
|
||||
HorizontalContentAlignment=""Stretch""
|
||||
HorizontalAlignment=""Stretch""
|
||||
VerticalAlignment=""Stretch""/>
|
||||
</DataTemplate>";
|
||||
|
||||
return (DataTemplate)XamlReader.Load(xamlString);
|
||||
@@ -27,12 +25,10 @@ public class TemplateGenerator : DataTemplateSelector
|
||||
string xamlString = @"
|
||||
<DataTemplate xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""
|
||||
xmlns:ui=""using:Hyperbar.UI.Windows"">
|
||||
<Grid>
|
||||
<ui:TemplateGeneratorControl VerticalContentAlignment=""Stretch""
|
||||
HorizontalContentAlignment=""Stretch""
|
||||
HorizontalAlignment=""Stretch""
|
||||
VerticalAlignment=""Stretch""/>
|
||||
</Grid>
|
||||
<ui:TemplateGeneratorControl VerticalContentAlignment=""Stretch""
|
||||
HorizontalContentAlignment=""Stretch""
|
||||
HorizontalAlignment=""Stretch""
|
||||
VerticalAlignment=""Stretch""/>
|
||||
</DataTemplate>";
|
||||
|
||||
return (DataTemplate)XamlReader.Load(xamlString);
|
||||
|
||||
@@ -11,7 +11,8 @@ public class TemplateGeneratorControl :
|
||||
DataContextChanged += OnDataContextChanged;
|
||||
}
|
||||
|
||||
private void OnDataContextChanged(FrameworkElement sender, DataContextChangedEventArgs args)
|
||||
private void OnDataContextChanged(FrameworkElement sender,
|
||||
DataContextChangedEventArgs args)
|
||||
{
|
||||
if (DataContext is ITemplatedViewModel templatedViewModel)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user