Skip to content
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
36 changes: 36 additions & 0 deletions ContextMenuManager/Controls/MyToolBar.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<UserControl
x:Class="ContextMenuManager.Controls.MyToolBar"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
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:sys="clr-namespace:System;assembly=mscorlib"
Height="96"
mc:Ignorable="d">

<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>

<!-- 按钮容器 -->
<WrapPanel
x:Name="ButtonContainer"
Grid.Column="0"
Margin="8,0"
VerticalAlignment="Center">
<WrapPanel.Resources>
<!-- Override styles of UI.WPF.Modern -->
<sys:Double x:Key="AppBarButtonContentHeight">36</sys:Double>
</WrapPanel.Resources>
</WrapPanel>

<!-- 搜索框容器 -->
<ContentPresenter
x:Name="SearchBoxHost"
Grid.Column="1"
Margin="0,0,16,0"
VerticalAlignment="Center" />
</Grid>
</UserControl>
116 changes: 116 additions & 0 deletions ContextMenuManager/Controls/MyToolBar.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using iNKORE.UI.WPF.Modern.Controls;

namespace ContextMenuManager.Controls
{
public partial class MyToolBar : UserControl
{
private readonly HashSet<AppBarToggleButton> _nonSelectableButtons = new();
private AppBarToggleButton _selectedButton;

public MyToolBar()
{
InitializeComponent();
}

public AppBarToggleButton SelectedButton
{
get => _selectedButton;
set
{
if (_selectedButton == value)
{
if (_selectedButton != null)
{
_selectedButton.IsChecked = true;
}
return;
}

if (_selectedButton != null)
{
_selectedButton.IsChecked = false;
_selectedButton.Cursor = Cursors.Hand;
}

_selectedButton = value;

if (_selectedButton != null)
{
_selectedButton.IsChecked = true;
_selectedButton.Cursor = Cursors.Arrow;
}

SelectedButtonChanged?.Invoke(this, EventArgs.Empty);
}
}

public int SelectedIndex
{
get
{
if (_selectedButton == null) return -1;
for (int i = 0; i < ButtonContainer.Children.Count; i++)
{
if (ButtonContainer.Children[i] == _selectedButton) return i;
}
return -1;
}
set
{
if (value < 0 || value >= ButtonContainer.Children.Count)
{
SelectedButton = null;
}
else
{
SelectedButton = ButtonContainer.Children[value] as AppBarToggleButton;
}
}
}

public event EventHandler SelectedButtonChanged;

public void AddButton(AppBarToggleButton button, bool canBeSelected = true)
{
button.Margin = new Thickness(12, 4, 0, 4);
button.Width = 88;
button.Height = 88;

if (!canBeSelected)
{
_nonSelectableButtons.Add(button);
}

button.Click += (sender, e) =>
{
if (_nonSelectableButtons.Contains(button))
{
button.IsChecked = false;
return;
}

SelectedButton = button;
};

ButtonContainer.Children.Add(button);
}

public void AddButtons(AppBarToggleButton[] buttons)
{
foreach (var button in buttons)
{
AddButton(button);
}
}

public void AddSearchBox(UIElement searchBox)
{
SearchBoxHost.Content = searchBox;
}
}
}
103 changes: 40 additions & 63 deletions ContextMenuManager/MainWindow.xaml
Original file line number Diff line number Diff line change
@@ -1,91 +1,68 @@
<Window
<Window
x:Class="ContextMenuManager.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="clr-namespace:ContextMenuManager.Controls"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:ui="http://schemas.inkore.net/lib/ui/wpf/modern"
Title="ContextMenuManager"
Width="850"
Height="610"
MinWidth="680"
MinHeight="450"
Title="Windows右键管理"
Width="900"
Height="650"
MinWidth="700"
MinHeight="480"
ui:ThemeManager.IsThemeAware="True"
ui:ThemeManager.RequestedTheme="Default"
ui:WindowHelper.SystemBackdropType="Mica"
ui:WindowHelper.UseModernWindowStyle="True"
Closing="Window_Closing"
WindowStartupLocation="CenterScreen"
mc:Ignorable="d">

<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
<RowDefinition Height="36" />
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="28"/>
</Grid.RowDefinitions>

<!-- Navigation View (replaces WinForms MyToolBar + MySideBar) -->
<ui:NavigationView
x:Name="NavView"
Grid.Row="0"
AlwaysShowHeader="False"
IsBackButtonVisible="Collapsed"
IsSettingsVisible="False"
SelectionChanged="NavView_SelectionChanged">
<!-- Top Toolbar -->
<Border Grid.Row="0" Background="Transparent" BorderBrush="{DynamicResource {x:Static SystemColors.ControlLightBrushKey}}" BorderThickness="0,0,0,1">
<controls:MyToolBar x:Name="ToolBar"/>
</Border>

<!-- Main content area -->
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<!-- Main area with sidebar + content -->
<Grid Grid.Row="1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>

<!-- Search box -->
<StackPanel x:Name="SearchBoxPanel">
<TextBox
x:Name="SearchBox"
Grid.Row="0"
Margin="16,8"
TextChanged="SearchBox_TextChanged" />
<Button
x:Name="RefreshButton"
Margin="16,0,16,0"
HorizontalAlignment="Stretch"
Click="RefreshButton_Click" />
</StackPanel>
<!-- Left Sidebar - using iNKORE ListView style -->
<Border Grid.Column="0" Width="160" Background="Transparent" BorderBrush="{DynamicResource {x:Static SystemColors.ControlLightBrushKey}}" BorderThickness="0,0,1,0">
<ui:ListView x:Name="SideBar" Margin="0,4" SelectionChanged="SideBar_SelectionChanged"/>
</Border>

<Grid Grid.Row="1">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<!-- Content Area -->
<Grid Grid.Column="1">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>

<controls:ExplorerRestarter
x:Name="ExplorerRestarterBanner"
Grid.Row="0"
Margin="15,6,15,6" />
<ContentControl
x:Name="WpfContentHost"
Grid.Row="1"
Visibility="Collapsed" />
</Grid>
<controls:ExplorerRestarter x:Name="ExplorerRestarterBanner" Grid.Row="0" Margin="12,6"/>
<ContentControl x:Name="WpfContentHost" Grid.Row="1" Visibility="Collapsed"/>
</Grid>
</ui:NavigationView>
</Grid>

<!-- Separator -->
<Border
Grid.Row="1"
Height="{DynamicResource AppBarSeparatorWidth}"
Background="{DynamicResource AppBarSeparatorForeground}" />
<!-- Separator before status bar -->
<Border Grid.Row="2" Height="1" Background="{DynamicResource {x:Static SystemColors.ControlLightBrushKey}}"/>

<!-- Status Bar -->
<StatusBar Grid.Row="2">
<StatusBarItem
Margin="8,0,0,0"
VerticalAlignment="Stretch"
HorizontalContentAlignment="Stretch">
<TextBlock x:Name="StatusText" Padding="4,2" />
<!-- Status Bar -->
<StatusBar Grid.Row="3" Background="Transparent">
<StatusBarItem VerticalAlignment="Stretch">
<TextBlock x:Name="StatusText" Padding="8,2" VerticalAlignment="Center"/>
</StatusBarItem>
</StatusBar>
</Grid>
Expand Down
Loading
Loading