Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix breadcrumb memory leakage issue #568

Merged
merged 1 commit into from
Feb 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 0 additions & 21 deletions demo/Sandbox/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,5 @@ namespace Sandbox.ViewModels;

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; }
}
25 changes: 17 additions & 8 deletions demo/Sandbox/Views/MainWindow.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,28 @@
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="Sandbox.Views.MainWindow"
x:DataType="vm:MainWindowViewModel"
xmlns:sys="using:System"
Icon="/Assets/avalonia-logo.ico"
Title="Sandbox">

<Design.DataContext>
<!-- 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) -->
<vm:MainWindowViewModel />
</Design.DataContext>
<u:UrsaView>
<Panel>
<Button Content="???" Click="Button_OnClick"></Button>
<u:OverlayDialogHost HostId="root"></u:OverlayDialogHost>
</Panel>
</u:UrsaView>
<StackPanel>
<Button Content="???" Click="Button_OnClick"></Button>
<ContentControl Name="content">
<ContentControl.DataTemplates>
<DataTemplate DataType="x:Int32">
<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>
9 changes: 8 additions & 1 deletion demo/Sandbox/Views/MainWindow.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ public MainWindow()

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;
}
}
}
15 changes: 0 additions & 15 deletions demo/Sandbox/Views/PW.axaml

This file was deleted.

42 changes: 0 additions & 42 deletions demo/Sandbox/Views/PW.axaml.cs

This file was deleted.

20 changes: 14 additions & 6 deletions src/Ursa/Controls/Breadcrumb/Breadcrumb.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,21 @@ public IDataTemplate? IconTemplate
static Breadcrumb()
{
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)
{
return NeedsContainer<BreadcrumbItem>(item, out recycleKey);
Expand All @@ -94,11 +107,6 @@ protected override void PrepareContainerForItemOverride(Control container, objec
{
breadcrumbItem.Separator = a;
}
SeparatorProperty.Changed.AddClassHandler<Breadcrumb, object?>((_, args) =>
{
if (GetSeparatorInstance(args.NewValue.Value) is { } b)
breadcrumbItem.Separator = b;
});
}

if (container == item) return;
Expand Down