FilterTemplateSelector.cs
1 // Copyright (c) Microsoft Corporation 2 // The Microsoft Corporation licenses this file to you under the MIT license. 3 // See the LICENSE file in the project root for more information. 4 5 using System.Diagnostics.CodeAnalysis; 6 using Microsoft.CmdPal.Core.ViewModels; 7 using Microsoft.UI.Xaml; 8 using Microsoft.UI.Xaml.Controls; 9 10 namespace Microsoft.CmdPal.UI; 11 12 internal sealed partial class FilterTemplateSelector : DataTemplateSelector 13 { 14 public DataTemplate? Default { get; set; } 15 16 public DataTemplate? Separator { get; set; } 17 18 [DynamicDependency(DynamicallyAccessedMemberTypes.All, "Microsoft.UI.Xaml.Controls.ComboBoxItem", "Microsoft.WinUI")] 19 protected override DataTemplate? SelectTemplateCore(object item, DependencyObject dependencyObject) 20 { 21 DataTemplate? dataTemplate = Default; 22 23 if (dependencyObject is ComboBoxItem comboBoxItem) 24 { 25 comboBoxItem.IsEnabled = true; 26 27 if (item is SeparatorViewModel) 28 { 29 comboBoxItem.IsEnabled = false; 30 comboBoxItem.AllowFocusWhenDisabled = false; 31 comboBoxItem.AllowFocusOnInteraction = false; 32 dataTemplate = Separator; 33 } 34 } 35 36 return dataTemplate; 37 } 38 }