未验证 提交 06820dc4 编写于 作者: J Josh Strauss 提交者: GitHub

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: NKevin Bost <kitokeboo@gmail.com>
上级 cedea523
using System.Collections.ObjectModel;
using CommunityToolkit.Mvvm.ComponentModel;
namespace MaterialDesignDemo.Domain;
......@@ -19,30 +20,46 @@ internal class TabsViewModel : ViewModelBase
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.";
public TabsViewModel() =>
public TabsViewModel()
{
var closeCommand = new AnotherCommandImplementation(_ =>
{
if (SelectedTab is { } selectedTab)
CustomTabs?.Remove(selectedTab);
});
CustomTabs = new()
{
new CustomTab {CustomHeader = "Custom tab 1"},
new CustomTab {CustomHeader = "Custom tab 2"}
new CustomTab(closeCommand)
{
CustomHeader = "Custom tab 1",
CustomContent = "Custom content 1"
},
new CustomTab(closeCommand)
{
CustomHeader = "Custom tab 2",
CustomContent = "Custom content 2"
},
new CustomTab(closeCommand)
{
CustomHeader = "Custom tab 3",
CustomContent = "Custom content 3",
},
};
}
}
internal class CustomTab: ViewModelBase
internal partial class CustomTab : ObservableObject
{
public ICommand CloseCommand { get; }
public string? CustomHeader { get; set; }
public CustomTab(ICommand closeCommand) => CloseCommand = closeCommand;
public string? CustomContent => CustomHeader + ", close clicked: " + CloseClickCount;
[ObservableProperty]
private string? _customHeader;
public int CloseClickCount { get; private set; }
[ObservableProperty]
private string? _customContent;
internal CustomTab()
{
CloseCommand = new AnotherCommandImplementation(_ =>
{
CloseClickCount++;
OnPropertyChanged(nameof(CustomContent));
});
}
}
\ No newline at end of file
}
......@@ -41,6 +41,7 @@
<PackageReference Include="BluwolfIcons">
<NoWarn>NU1701</NoWarn>
</PackageReference>
<PackageReference Include="CommunityToolkit.Mvvm" />
<PackageReference Include="VirtualizingWrapPanel" />
<PackageReference Include="ShowMeTheXAML" />
<PackageReference Include="ShowMeTheXAML.AvalonEdit" />
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册