feat: add adorner flavor usage.
This commit is contained in:
@@ -1,20 +1,29 @@
|
|||||||
<UserControl xmlns="https://github.com/avaloniaui"
|
<UserControl
|
||||||
|
x:Class="Ursa.Demo.Pages.DisableContainerDemo"
|
||||||
|
xmlns="https://github.com/avaloniaui"
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
xmlns:u="https://irihi.tech/ursa"
|
xmlns:u="https://irihi.tech/ursa"
|
||||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
d:DesignHeight="450"
|
||||||
x:Class="Ursa.Demo.Pages.DisableContainerDemo">
|
d:DesignWidth="800"
|
||||||
|
mc:Ignorable="d">
|
||||||
<StackPanel HorizontalAlignment="Left" Spacing="20">
|
<StackPanel HorizontalAlignment="Left" Spacing="20">
|
||||||
<ToggleSwitch Name="s" IsChecked="True"></ToggleSwitch>
|
<ToggleSwitch Name="s" IsChecked="True" />
|
||||||
<u:DisableContainer DisabledTip="This is disabled. ">
|
<u:DisableContainer DisabledTip="This is disabled. ">
|
||||||
<Button IsEnabled="{Binding #s.IsChecked}">Hello World!</Button>
|
<Button IsEnabled="{Binding #s.IsChecked}">Hello World!</Button>
|
||||||
</u:DisableContainer>
|
</u:DisableContainer>
|
||||||
<u:DisableContainer DisabledTip="This is disabled. ">
|
<u:DisableContainer DisabledTip="This is disabled. ">
|
||||||
<Calendar IsEnabled="{Binding #s.IsChecked}"></Calendar>
|
<Calendar IsEnabled="{Binding #s.IsChecked}" />
|
||||||
</u:DisableContainer>
|
</u:DisableContainer>
|
||||||
<u:DisableContainer>
|
<u:DisableContainer>
|
||||||
<Calendar IsEnabled="{Binding #s.IsChecked}"></Calendar>
|
<Button IsEnabled="{Binding #s.IsChecked}">Hello Avalonnia</Button>
|
||||||
</u:DisableContainer>
|
</u:DisableContainer>
|
||||||
|
<Button
|
||||||
|
u:DisabledAdorner.DisabledTip="Fine"
|
||||||
|
u:DisabledAdorner.IsEnabled="True"
|
||||||
|
IsEnabled="{Binding #s.IsChecked}">
|
||||||
|
Hello Avalonia
|
||||||
|
</Button>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
</UserControl>
|
</UserControl>
|
||||||
|
|||||||
55
src/Ursa/Controls/DisableContainer/DisabledAdorner.cs
Normal file
55
src/Ursa/Controls/DisableContainer/DisabledAdorner.cs
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
using Avalonia;
|
||||||
|
using Avalonia.Controls;
|
||||||
|
using Avalonia.Controls.Primitives;
|
||||||
|
using Avalonia.Data;
|
||||||
|
using Avalonia.Data.Converters;
|
||||||
|
using Avalonia.Input;
|
||||||
|
using Avalonia.Layout;
|
||||||
|
using Avalonia.Media;
|
||||||
|
using Ursa.Controls.Shapes;
|
||||||
|
|
||||||
|
namespace Ursa.Controls;
|
||||||
|
|
||||||
|
public class DisabledAdorner
|
||||||
|
{
|
||||||
|
public static readonly AttachedProperty<bool> IsEnabledProperty =
|
||||||
|
AvaloniaProperty.RegisterAttached<DisabledAdorner, InputElement, bool>("IsEnabled");
|
||||||
|
|
||||||
|
public static void SetIsEnabled(InputElement obj, bool value) => obj.SetValue(IsEnabledProperty, value);
|
||||||
|
public static bool GetIsEnabled(InputElement obj) => obj.GetValue(IsEnabledProperty);
|
||||||
|
|
||||||
|
public static readonly AttachedProperty<object?> DisabledTipProperty =
|
||||||
|
AvaloniaProperty.RegisterAttached<DisabledAdorner, InputElement, object?>("DisabledTip");
|
||||||
|
|
||||||
|
public static void SetDisabledTip(InputElement obj, object? value) => obj.SetValue(DisabledTipProperty, value);
|
||||||
|
public static object? GetDisabledTip(InputElement obj) => obj.GetValue(DisabledTipProperty);
|
||||||
|
|
||||||
|
static DisabledAdorner()
|
||||||
|
{
|
||||||
|
IsEnabledProperty.Changed.AddClassHandler<InputElement, bool>(OnIsEnabledChanged);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void OnIsEnabledChanged(InputElement arg1, AvaloniaPropertyChangedEventArgs<bool> arg2)
|
||||||
|
{
|
||||||
|
if (arg2.NewValue.Value)
|
||||||
|
{
|
||||||
|
var pureRectangle = new Border()
|
||||||
|
{
|
||||||
|
Background = Brushes.Transparent,
|
||||||
|
IsHitTestVisible = true,
|
||||||
|
HorizontalAlignment = HorizontalAlignment.Stretch,
|
||||||
|
VerticalAlignment = VerticalAlignment.Stretch,
|
||||||
|
Cursor = new Cursor(StandardCursorType.No),
|
||||||
|
[!ToolTip.TipProperty] = arg1[!DisabledTipProperty],
|
||||||
|
};
|
||||||
|
var binding = arg1.GetObservable(InputElement.IsEnabledProperty, converter: (a) => !a).ToBinding();
|
||||||
|
pureRectangle.Bind(Visual.IsVisibleProperty, binding);
|
||||||
|
AdornerLayer.SetAdorner(arg1, pureRectangle);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
AdornerLayer.SetAdorner(arg1, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user