mirror of
https://github.com/ckaczor/ChrisKaczor.Wpf.Windows.CategoryWindow.git
synced 2026-01-13 17:22:32 -05:00
Initial commit
This commit is contained in:
63
CategoryWindow.xaml.cs
Normal file
63
CategoryWindow.xaml.cs
Normal file
@@ -0,0 +1,63 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace ChrisKaczor.Wpf.Windows;
|
||||
|
||||
public partial class CategoryWindow
|
||||
{
|
||||
private readonly List<CategoryPanelBase> _categoryPanels;
|
||||
|
||||
public CategoryWindow(List<CategoryPanelBase> categoryPanels, string title, string closeButtonText)
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
Title = title;
|
||||
CloseButton.Content = closeButtonText;
|
||||
|
||||
_categoryPanels = categoryPanels;
|
||||
|
||||
// Load the category list
|
||||
LoadCategories();
|
||||
}
|
||||
|
||||
private void LoadCategories()
|
||||
{
|
||||
// Loop over each panel
|
||||
foreach (var optionsPanel in _categoryPanels)
|
||||
{
|
||||
// Tell the panel to load itself
|
||||
optionsPanel.LoadPanel(this);
|
||||
|
||||
// Add the panel to the category ist
|
||||
CategoryListBox.Items.Add(new CategoryListItem(optionsPanel));
|
||||
|
||||
// Set the panel into the right side
|
||||
ContentControl.Content = optionsPanel;
|
||||
}
|
||||
|
||||
// Select the first item
|
||||
CategoryListBox.SelectedItem = CategoryListBox.Items[0];
|
||||
}
|
||||
|
||||
private void SelectCategory(CategoryPanelBase panel)
|
||||
{
|
||||
// Set the content
|
||||
ContentControl.Content = panel;
|
||||
}
|
||||
|
||||
private void HandleSelectedCategoryChanged(object sender, SelectionChangedEventArgs e)
|
||||
{
|
||||
// Select the right category
|
||||
SelectCategory(((CategoryListItem)CategoryListBox.SelectedItem).Panel);
|
||||
}
|
||||
|
||||
private class CategoryListItem(CategoryPanelBase panel)
|
||||
{
|
||||
public CategoryPanelBase Panel { get; } = panel;
|
||||
|
||||
public override string? ToString()
|
||||
{
|
||||
return Panel.CategoryName;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user