Merge pull request #568 from irihitech/breadcrumb
Fix breadcrumb memory leakage issue
This commit is contained in:
@@ -5,26 +5,5 @@ namespace Sandbox.ViewModels;
|
|||||||
|
|
||||||
public partial class MainWindowViewModel : ViewModelBase
|
public partial class MainWindowViewModel : ViewModelBase
|
||||||
{
|
{
|
||||||
public ObservableCollection<DataGridItem> Items { get; set; }
|
|
||||||
|
|
||||||
public MainWindowViewModel()
|
|
||||||
{
|
|
||||||
Items = new ObservableCollection<DataGridItem>()
|
|
||||||
{
|
|
||||||
new DataGridItem() { Name = "John Doe", Age = 42 },
|
|
||||||
new DataGridItem() { Name = "Jane Doe", Age = 39 },
|
|
||||||
new DataGridItem() { Name = "Sammy Doe", Age = 13 },
|
|
||||||
new DataGridItem() { Name = "Barry Doe", Age = 7 },
|
|
||||||
new DataGridItem() { Name = "Molly Doe", Age = 5 },
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public class DataGridItem
|
|
||||||
{
|
|
||||||
public string? Name { get; set; }
|
|
||||||
public int Age { get; set; }
|
|
||||||
public IPAddress? Address { get; set; }
|
|
||||||
}
|
}
|
||||||
@@ -7,19 +7,28 @@
|
|||||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||||
x:Class="Sandbox.Views.MainWindow"
|
x:Class="Sandbox.Views.MainWindow"
|
||||||
x:DataType="vm:MainWindowViewModel"
|
x:DataType="vm:MainWindowViewModel"
|
||||||
xmlns:sys="using:System"
|
|
||||||
Icon="/Assets/avalonia-logo.ico"
|
Icon="/Assets/avalonia-logo.ico"
|
||||||
Title="Sandbox">
|
Title="Sandbox">
|
||||||
|
|
||||||
<Design.DataContext>
|
<Design.DataContext>
|
||||||
<!-- This only sets the DataContext for the previewer in an IDE,
|
<!-- This only sets the DataContext for the previewer in an IDE,
|
||||||
to set the actual DataContext for runtime, set the DataContext property in code (look at App.axaml.cs) -->
|
to set the actual DataContext for runtime, set the DataContext property in code (look at App.axaml.cs) -->
|
||||||
<vm:MainWindowViewModel />
|
<vm:MainWindowViewModel />
|
||||||
</Design.DataContext>
|
</Design.DataContext>
|
||||||
<u:UrsaView>
|
<StackPanel>
|
||||||
<Panel>
|
<Button Content="???" Click="Button_OnClick"></Button>
|
||||||
<Button Content="???" Click="Button_OnClick"></Button>
|
<ContentControl Name="content">
|
||||||
<u:OverlayDialogHost HostId="root"></u:OverlayDialogHost>
|
<ContentControl.DataTemplates>
|
||||||
</Panel>
|
<DataTemplate DataType="x:Int32">
|
||||||
</u:UrsaView>
|
<u:Breadcrumb Separator="·" Classes="Margin">
|
||||||
|
<u:BreadcrumbItem Content="a" />
|
||||||
|
<u:BreadcrumbItem Content="b" />
|
||||||
|
<u:BreadcrumbItem Content="c" />
|
||||||
|
</u:Breadcrumb>
|
||||||
|
</DataTemplate>
|
||||||
|
<DataTemplate DataType="x:Double">
|
||||||
|
<TextBlock Text="Hello World"/>
|
||||||
|
</DataTemplate>
|
||||||
|
</ContentControl.DataTemplates>
|
||||||
|
</ContentControl>
|
||||||
|
</StackPanel>
|
||||||
</Window>
|
</Window>
|
||||||
@@ -13,6 +13,13 @@ public partial class MainWindow : Window
|
|||||||
|
|
||||||
private async void Button_OnClick(object? sender, RoutedEventArgs e)
|
private async void Button_OnClick(object? sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
var res = await OverlayDialog.ShowModal(new TextBlock() { Text = "sdfksjdl" }, "root");
|
if (content.Content is int s)
|
||||||
|
{
|
||||||
|
content.Content = 1.1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
content.Content = 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
<UserControl 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"
|
|
||||||
MinHeight="200"
|
|
||||||
MinWidth="500"
|
|
||||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
|
||||||
x:Class="Sandbox.Views.PW">
|
|
||||||
<Panel>
|
|
||||||
<Button Content="???" Click="Button_OnClick"></Button>
|
|
||||||
<Button Content="close" VerticalAlignment="Bottom" Click="Close"></Button>
|
|
||||||
<u:OverlayDialogHost x:Name="_overlayDialogHost" ></u:OverlayDialogHost>
|
|
||||||
</Panel>
|
|
||||||
</UserControl>
|
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.IO;
|
|
||||||
using Avalonia;
|
|
||||||
using Avalonia.Controls;
|
|
||||||
using Avalonia.Interactivity;
|
|
||||||
using Avalonia.Markup.Xaml;
|
|
||||||
using Irihi.Avalonia.Shared.Contracts;
|
|
||||||
using Sandbox.ViewModels;
|
|
||||||
using Ursa.Controls;
|
|
||||||
|
|
||||||
namespace Sandbox.Views;
|
|
||||||
|
|
||||||
public partial class PW : UserControl
|
|
||||||
{
|
|
||||||
public PW()
|
|
||||||
{
|
|
||||||
InitializeComponent();
|
|
||||||
_overlayDialogHost.HostId = _hostid;
|
|
||||||
}
|
|
||||||
|
|
||||||
private string _hostid = Path.GetRandomFileName();
|
|
||||||
|
|
||||||
private async void Button_OnClick(object? sender, RoutedEventArgs e)
|
|
||||||
{
|
|
||||||
Drawer.ShowCustom(new PW(), new TestVM(), _hostid);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void Close(object? sender, RoutedEventArgs e)
|
|
||||||
{
|
|
||||||
(DataContext as TestVM)?.Close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class TestVM : ViewModelBase, IDialogContext
|
|
||||||
{
|
|
||||||
public void Close()
|
|
||||||
{
|
|
||||||
RequestClose?.Invoke(this, 12456789);
|
|
||||||
}
|
|
||||||
|
|
||||||
public event EventHandler<object?>? RequestClose;
|
|
||||||
}
|
|
||||||
@@ -73,8 +73,21 @@ public class Breadcrumb: ItemsControl
|
|||||||
static Breadcrumb()
|
static Breadcrumb()
|
||||||
{
|
{
|
||||||
ItemsPanelProperty.OverrideDefaultValue<Breadcrumb>(_defaultPanel);
|
ItemsPanelProperty.OverrideDefaultValue<Breadcrumb>(_defaultPanel);
|
||||||
|
SeparatorProperty.Changed.AddClassHandler<Breadcrumb, object?>((b, args) => b.OnSeparatorChanged(args));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void OnSeparatorChanged(AvaloniaPropertyChangedEventArgs<object?> args)
|
||||||
|
{
|
||||||
|
if (GetSeparatorInstance(Separator) is { } a)
|
||||||
|
{
|
||||||
|
var breadcrumbItems = this.GetVisualDescendants().OfType<BreadcrumbItem>().ToList();
|
||||||
|
foreach (var item in breadcrumbItems)
|
||||||
|
{
|
||||||
|
item.Separator = a;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected override bool NeedsContainerOverride(object? item, int index, out object? recycleKey)
|
protected override bool NeedsContainerOverride(object? item, int index, out object? recycleKey)
|
||||||
{
|
{
|
||||||
return NeedsContainer<BreadcrumbItem>(item, out recycleKey);
|
return NeedsContainer<BreadcrumbItem>(item, out recycleKey);
|
||||||
@@ -94,11 +107,6 @@ public class Breadcrumb: ItemsControl
|
|||||||
{
|
{
|
||||||
breadcrumbItem.Separator = a;
|
breadcrumbItem.Separator = a;
|
||||||
}
|
}
|
||||||
SeparatorProperty.Changed.AddClassHandler<Breadcrumb, object?>((_, args) =>
|
|
||||||
{
|
|
||||||
if (GetSeparatorInstance(args.NewValue.Value) is { } b)
|
|
||||||
breadcrumbItem.Separator = b;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (container == item) return;
|
if (container == item) return;
|
||||||
|
|||||||
Reference in New Issue
Block a user