Merge pull request #655 from irihitech/badge
Fix various badge layout issues.
This commit is contained in:
@@ -5,6 +5,9 @@
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:u="https://irihi.tech/ursa"
|
||||
xmlns:viewModels="clr-namespace:Ursa.Demo.ViewModels"
|
||||
xmlns:common="clr-namespace:Ursa.Common;assembly=Ursa"
|
||||
x:DataType="viewModels:BadgeDemoViewModel"
|
||||
d:DesignHeight="850"
|
||||
d:DesignWidth="850"
|
||||
mc:Ignorable="d">
|
||||
@@ -19,6 +22,15 @@
|
||||
<Setter Property="Margin" Value="10" />
|
||||
</Style>
|
||||
</StackPanel.Styles>
|
||||
|
||||
<Border Theme="{DynamicResource CardBorder}">
|
||||
<StackPanel>
|
||||
<u:EnumSelector Name="position" EnumType="{x:Type common:CornerPosition}"/>
|
||||
<u:Badge CornerPosition="{Binding #position.Value}" Header="{Binding Text}">
|
||||
<Button Content="Test" Command="{Binding ChangeTextCommand}"/>
|
||||
</u:Badge>
|
||||
</StackPanel>
|
||||
</Border>
|
||||
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<u:Badge Header="5">
|
||||
|
||||
@@ -9,9 +9,4 @@ public partial class BadgeDemo : UserControl
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void InitializeComponent()
|
||||
{
|
||||
AvaloniaXamlLoader.Load(this);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,28 @@
|
||||
using System;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
|
||||
namespace Ursa.Demo.ViewModels;
|
||||
|
||||
public class BadgeDemoViewModel: ViewModelBase
|
||||
public partial class BadgeDemoViewModel: ViewModelBase
|
||||
{
|
||||
|
||||
[ObservableProperty] private string? _text = null;
|
||||
|
||||
public BadgeDemoViewModel()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
public void ChangeText()
|
||||
{
|
||||
if (Text == null)
|
||||
{
|
||||
Text = DateTime.Now.ToShortDateString();
|
||||
}
|
||||
else
|
||||
{
|
||||
Text = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -66,6 +66,7 @@ public class Badge : HeaderedContentControl
|
||||
static Badge()
|
||||
{
|
||||
HeaderProperty.Changed.AddClassHandler<Badge>((badge, _) => badge.UpdateBadgePosition());
|
||||
CornerPositionProperty.Changed.AddClassHandler<Badge>((badge, _) => badge.UpdateBadgePosition());
|
||||
DotProperty.Changed.AddClassHandler<Badge>((badge, _) => badge.UpdateBadgePosition());
|
||||
}
|
||||
|
||||
@@ -83,8 +84,9 @@ public class Badge : HeaderedContentControl
|
||||
|
||||
protected override Size ArrangeOverride(Size finalSize)
|
||||
{
|
||||
var size = base.ArrangeOverride(finalSize);
|
||||
UpdateBadgePosition();
|
||||
return base.ArrangeOverride(finalSize);
|
||||
return size;
|
||||
}
|
||||
|
||||
private void UpdateBadgePosition()
|
||||
Reference in New Issue
Block a user