New expander control.

This commit is contained in:
Burak Kaan Köse
2024-08-26 01:07:51 +02:00
parent 31c7c8b46f
commit f4bbf6eb73
9 changed files with 176 additions and 45 deletions

View File

@@ -1,17 +1,43 @@
using Microsoft.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Markup;
namespace Wino.Controls
{
public class WinoExpander : Expander
[ContentProperty(Name = nameof(Content))]
public class WinoExpander : Control
{
protected override void OnApplyTemplate()
public static readonly DependencyProperty HeaderProperty = DependencyProperty.Register(nameof(Header), typeof(UIElement), typeof(WinoExpander), new PropertyMetadata(null));
public static readonly DependencyProperty ContentProperty = DependencyProperty.Register(nameof(Content), typeof(UIElement), typeof(WinoExpander), new PropertyMetadata(null));
public static readonly DependencyProperty IsExpandedProperty = DependencyProperty.Register(nameof(IsExpanded), typeof(bool), typeof(WinoExpander), new PropertyMetadata(false, new PropertyChangedCallback(OnIsExpandedChanged)));
public bool IsExpanded
{
base.OnApplyTemplate();
if (GetTemplateChild("ExpanderHeader") is ToggleButton toggleButton)
{
toggleButton.Padding = new Windows.UI.Xaml.Thickness(0, 4, 0, 4);
}
get { return (bool)GetValue(IsExpandedProperty); }
set { SetValue(IsExpandedProperty, value); }
}
public UIElement Content
{
get { return (UIElement)GetValue(ContentProperty); }
set { SetValue(ContentProperty, value); }
}
public UIElement Header
{
get { return (UIElement)GetValue(HeaderProperty); }
set { SetValue(HeaderProperty, value); }
}
private static void OnIsExpandedChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args)
{
if (obj is WinoExpander control)
control.UpdateVisualStates();
}
private void UpdateVisualStates()
{
VisualStateManager.GoToState(this, IsExpanded ? "Expanded" : "Collapsed", true);
}
}
}