Skip to content

Commit 06820dc

Browse files
JoshStraussKeboo
andauthored
Make custom tabs deletable in the demo (#3242)
* Make custom tabs deletable in the demo * Add missing file * Moving code around to fix nullability warnings --------- Co-authored-by: Kevin Bost <[email protected]>
1 parent cedea52 commit 06820dc

File tree

2 files changed

+34
-16
lines changed

2 files changed

+34
-16
lines changed

MainDemo.Wpf/Domain/TabsViewModel.cs

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Collections.ObjectModel;
2+
using CommunityToolkit.Mvvm.ComponentModel;
23

34
namespace MaterialDesignDemo.Domain;
45

@@ -19,30 +20,46 @@ internal class TabsViewModel : ViewModelBase
1920
2021
Nulla a porta libero, quis hendrerit ex. In ut pharetra sem. Nunc gravida ante rhoncus commodo aliquet. Integer luctus blandit libero, sed faucibus ligula ornare ut. Mauris facilisis, urna eu fermentum mollis, mauris massa commodo odio, a venenatis nunc nunc sollicitudin nibh. Ut mattis ipsum nec lacus mattis fringilla. Proin vulputate id velit a finibus. Ut nunc ex, elementum porttitor finibus vel, pellentesque vel turpis. Cras fringilla eleifend libero, ac feugiat arcu vehicula ornare. Nullam pretium finibus blandit. Etiam at urna facilisis, posuere felis non, congue velit. Pellentesque tortor erat, mattis at augue eu, egestas interdum nunc. Aliquam tortor lorem, venenatis eget vestibulum vitae, maximus eget nunc. Vestibulum et leo venenatis, rutrum lacus eget, mattis quam.";
2122

22-
public TabsViewModel() =>
23+
public TabsViewModel()
24+
{
25+
var closeCommand = new AnotherCommandImplementation(_ =>
26+
{
27+
if (SelectedTab is { } selectedTab)
28+
CustomTabs?.Remove(selectedTab);
29+
});
30+
2331
CustomTabs = new()
2432
{
25-
new CustomTab {CustomHeader = "Custom tab 1"},
26-
new CustomTab {CustomHeader = "Custom tab 2"}
33+
new CustomTab(closeCommand)
34+
{
35+
CustomHeader = "Custom tab 1",
36+
CustomContent = "Custom content 1"
37+
},
38+
new CustomTab(closeCommand)
39+
{
40+
CustomHeader = "Custom tab 2",
41+
CustomContent = "Custom content 2"
42+
},
43+
new CustomTab(closeCommand)
44+
{
45+
CustomHeader = "Custom tab 3",
46+
CustomContent = "Custom content 3",
47+
},
2748
};
49+
}
50+
2851
}
2952

30-
internal class CustomTab: ViewModelBase
53+
internal partial class CustomTab : ObservableObject
3154
{
3255
public ICommand CloseCommand { get; }
3356

34-
public string? CustomHeader { get; set; }
57+
public CustomTab(ICommand closeCommand) => CloseCommand = closeCommand;
3558

36-
public string? CustomContent => CustomHeader + ", close clicked: " + CloseClickCount;
59+
[ObservableProperty]
60+
private string? _customHeader;
3761

38-
public int CloseClickCount { get; private set; }
62+
[ObservableProperty]
63+
private string? _customContent;
3964

40-
internal CustomTab()
41-
{
42-
CloseCommand = new AnotherCommandImplementation(_ =>
43-
{
44-
CloseClickCount++;
45-
OnPropertyChanged(nameof(CustomContent));
46-
});
47-
}
48-
}
65+
}

MainDemo.Wpf/MaterialDesignDemo.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
<PackageReference Include="BluwolfIcons">
4242
<NoWarn>NU1701</NoWarn>
4343
</PackageReference>
44+
<PackageReference Include="CommunityToolkit.Mvvm" />
4445
<PackageReference Include="VirtualizingWrapPanel" />
4546
<PackageReference Include="ShowMeTheXAML" />
4647
<PackageReference Include="ShowMeTheXAML.AvalonEdit" />

0 commit comments

Comments
 (0)