using System.Windows.Controls; using System.Windows.Input; using YY.Admin.Module; namespace YY.Admin.Views.Control { /// /// Interaction logic for Sidebar.xaml /// public partial class SidebarControl : UserControl { public SidebarControl() { InitializeComponent(); } private void OnNavItemMouseDown(object sender, MouseButtonEventArgs e) { if (sender is ListBoxItem item && item.DataContext is NavItem navItem) { // 执行命令(如果有) if (navItem.Command?.CanExecute(navItem) == true) { navItem.Command.Execute(navItem); } // 如果不可选,阻止选中 if (!navItem.IsActive) { // 阻止 ListBox 自动选择该项 e.Handled = true; return; } } } } }