@@ -9,6 +9,7 @@ public static class MenuKeys
|
||||
public const string MenuKeyClassInput = "Class Input";
|
||||
public const string MenuKeyDialog = "Dialog";
|
||||
public const string MenuKeyDivider = "Divider";
|
||||
public const string MenuKeyDisableContainer = "DisableContainer";
|
||||
public const string MenuKeyDrawer = "Drawer";
|
||||
public const string MenuKeyDualBadge = "DualBadge";
|
||||
public const string MenuKeyEnumSelector = "EnumSelector";
|
||||
|
||||
29
demo/Ursa.Demo/Pages/DisableContainerDemo.axaml
Normal file
29
demo/Ursa.Demo/Pages/DisableContainerDemo.axaml
Normal file
@@ -0,0 +1,29 @@
|
||||
<UserControl
|
||||
x:Class="Ursa.Demo.Pages.DisableContainerDemo"
|
||||
xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:u="https://irihi.tech/ursa"
|
||||
d:DesignHeight="450"
|
||||
d:DesignWidth="800"
|
||||
mc:Ignorable="d">
|
||||
<StackPanel HorizontalAlignment="Left" Spacing="20">
|
||||
<ToggleSwitch Name="s" IsChecked="True" />
|
||||
<u:DisableContainer DisabledTip="This is disabled. ">
|
||||
<Button IsEnabled="{Binding #s.IsChecked}">Hello World!</Button>
|
||||
</u:DisableContainer>
|
||||
<u:DisableContainer DisabledTip="This is disabled. ">
|
||||
<Calendar IsEnabled="{Binding #s.IsChecked}" />
|
||||
</u:DisableContainer>
|
||||
<u:DisableContainer>
|
||||
<Button IsEnabled="{Binding #s.IsChecked}">Hello Avalonia</Button>
|
||||
</u:DisableContainer>
|
||||
<Button
|
||||
u:DisabledAdorner.DisabledTip="Fine"
|
||||
u:DisabledAdorner.IsEnabled="True"
|
||||
IsEnabled="{Binding #s.IsChecked}">
|
||||
Hello Avalonia
|
||||
</Button>
|
||||
</StackPanel>
|
||||
</UserControl>
|
||||
13
demo/Ursa.Demo/Pages/DisableContainerDemo.axaml.cs
Normal file
13
demo/Ursa.Demo/Pages/DisableContainerDemo.axaml.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Markup.Xaml;
|
||||
|
||||
namespace Ursa.Demo.Pages;
|
||||
|
||||
public partial class DisableContainerDemo : UserControl
|
||||
{
|
||||
public DisableContainerDemo()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
|
||||
namespace Ursa.Demo.ViewModels;
|
||||
|
||||
public class DisableContainerDemoViewModel: ObservableObject
|
||||
{
|
||||
|
||||
}
|
||||
@@ -31,6 +31,7 @@ public class MainViewViewModel : ViewModelBase
|
||||
MenuKeys.MenuKeyClassInput => new ClassInputDemoViewModel(),
|
||||
MenuKeys.MenuKeyDialog => new DialogDemoViewModel(),
|
||||
MenuKeys.MenuKeyDivider => new DividerDemoViewModel(),
|
||||
MenuKeys.MenuKeyDisableContainer => new DisableContainerDemoViewModel(),
|
||||
MenuKeys.MenuKeyDrawer => new DrawerDemoViewModel(),
|
||||
MenuKeys.MenuKeyDualBadge => new DualBadgeDemoViewModel(),
|
||||
MenuKeys.MenuKeyEnumSelector => new EnumSelectorDemoViewModel(),
|
||||
|
||||
@@ -17,6 +17,7 @@ public class MenuViewModel: ViewModelBase
|
||||
new() { MenuHeader = "Button Group", Key = MenuKeys.MenuKeyButtonGroup, Status = "Updated"},
|
||||
new() { MenuHeader = "Class Input", Key = MenuKeys.MenuKeyClassInput, Status = "New" },
|
||||
new() { MenuHeader = "Dialog", Key = MenuKeys.MenuKeyDialog },
|
||||
new() { MenuHeader = "Disable Container", Key = MenuKeys.MenuKeyDisableContainer, Status = "New"},
|
||||
new() { MenuHeader = "Divider", Key = MenuKeys.MenuKeyDivider },
|
||||
new() { MenuHeader = "Drawer", Key = MenuKeys.MenuKeyDrawer },
|
||||
new() { MenuHeader = "DualBadge", Key = MenuKeys.MenuKeyDualBadge },
|
||||
|
||||
16
src/Ursa.Themes.Semi/Controls/DisableContainer.axaml
Normal file
16
src/Ursa.Themes.Semi/Controls/DisableContainer.axaml
Normal file
@@ -0,0 +1,16 @@
|
||||
<ResourceDictionary xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:u="https://irihi.tech/ursa"
|
||||
xmlns:shapes="clr-namespace:Ursa.Controls.Shapes;assembly=Ursa">
|
||||
<!-- Add Resources Here -->
|
||||
<ControlTheme TargetType="u:DisableContainer" x:Key="{x:Type u:DisableContainer}">
|
||||
<Setter Property="Template">
|
||||
<ControlTemplate TargetType="u:DisableContainer">
|
||||
<Panel>
|
||||
<ContentPresenter Content="{TemplateBinding Content}"></ContentPresenter>
|
||||
<shapes:PureRectangle Background="Transparent" IsVisible="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Content.IsEnabled, Converter={x:Static BoolConverters.Not}}" Cursor="No" ToolTip.Tip="{TemplateBinding DisabledTip}"/>
|
||||
</Panel>
|
||||
</ControlTemplate>
|
||||
</Setter>
|
||||
</ControlTheme>
|
||||
</ResourceDictionary>
|
||||
@@ -7,6 +7,7 @@
|
||||
<ResourceInclude Source="ControlClassesInput.axaml" />
|
||||
<ResourceInclude Source="Dialog.axaml" />
|
||||
<ResourceInclude Source="DialogShared.axaml" />
|
||||
<ResourceInclude Source="DisableContainer.axaml" />
|
||||
<ResourceInclude Source="Divider.axaml" />
|
||||
<ResourceInclude Source="Drawer.axaml" />
|
||||
<ResourceInclude Source="DualBadge.axaml" />
|
||||
|
||||
29
src/Ursa/Controls/DisableContainer/DisableContainer.cs
Normal file
29
src/Ursa/Controls/DisableContainer/DisableContainer.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Controls.Primitives;
|
||||
using Avalonia.Input;
|
||||
using Avalonia.Metadata;
|
||||
|
||||
namespace Ursa.Controls;
|
||||
|
||||
public class DisableContainer: TemplatedControl
|
||||
{
|
||||
public static readonly StyledProperty<InputElement?> ContentProperty = AvaloniaProperty.Register<DisableContainer, InputElement?>(
|
||||
nameof(Content));
|
||||
|
||||
[Content]
|
||||
public InputElement? Content
|
||||
{
|
||||
get => GetValue(ContentProperty);
|
||||
set => SetValue(ContentProperty, value);
|
||||
}
|
||||
|
||||
public static readonly StyledProperty<object?> DisabledTipProperty = AvaloniaProperty.Register<DisableContainer, object?>(
|
||||
nameof(DisabledTip));
|
||||
|
||||
public object? DisabledTip
|
||||
{
|
||||
get => GetValue(DisabledTipProperty);
|
||||
set => SetValue(DisabledTipProperty, value);
|
||||
}
|
||||
}
|
||||
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