wabbajack/Wabbajack.App/Controls/LargeIconButton.axaml.cs
2021-10-23 10:51:17 -06:00

47 lines
1.3 KiB
C#

using System.Reactive.Disposables;
using System.Reactive.Linq;
using Avalonia;
using Avalonia.Controls;
using Material.Icons;
using ReactiveUI;
namespace Wabbajack.App.Controls;
public partial class LargeIconButton : UserControl, IActivatableView
{
public static readonly StyledProperty<string> TextProperty =
AvaloniaProperty.Register<LargeIconButton, string>(nameof(Text));
public static readonly StyledProperty<MaterialIconKind> IconProperty =
AvaloniaProperty.Register<LargeIconButton, MaterialIconKind>(nameof(IconProperty));
public LargeIconButton()
{
InitializeComponent();
this.WhenActivated(dispose =>
{
this.WhenAnyValue(x => x.Icon)
.Where(x => x != default)
.BindTo(IconControl, x => x.Kind)
.DisposeWith(dispose);
this.WhenAnyValue(x => x.Text)
.Where(x => x != default)
.BindTo(TextBlock, x => x.Text)
.DisposeWith(dispose);
});
}
public string Text
{
get => GetValue(TextProperty);
set => SetValue(TextProperty, value);
}
public MaterialIconKind Icon
{
get => GetValue(IconProperty);
set => SetValue(IconProperty, value);
}
}