Skip to content

Commit 81822a5

Browse files
committed
Debug TextBoxHelper
- ClearTextButton - AutoWatermark
1 parent 49c692d commit 81822a5

File tree

4 files changed

+47
-3
lines changed

4 files changed

+47
-3
lines changed

src/MahApps.Metro.Samples/MahApps.Metro.Demo/ExampleViews/MultiSelectionComboBoxExample.xaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@
105105
Separator=", "
106106
SelectedItemsTemplate="{DynamicResource MahApps.DataTemplates.MultiSelectionComboBox.Removeable}"
107107
TextWrapping="Wrap"
108+
SelectedItem="{Binding MultiSelectionComboBoxSelectedAlbum}"
108109
ItemsSource="{Binding Albums}" />
109110
</Grid>
110111
</GroupBox>

src/MahApps.Metro.Samples/MahApps.Metro.Demo/MainWindowViewModel.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,19 @@ public void Dispose()
237237

238238
public int SelectedIndex { get; set; }
239239

240+
240241
public ICollection<Album> Albums { get; set; }
241242

243+
244+
private Album _MultiSelectionComboBoxSelectedAlbum;
245+
[Display(Prompt = "Select an Album")]
246+
public Album MultiSelectionComboBoxSelectedAlbum
247+
{
248+
get { return _MultiSelectionComboBoxSelectedAlbum; }
249+
set { _MultiSelectionComboBoxSelectedAlbum = value; OnPropertyChanged(nameof(MultiSelectionComboBoxSelectedAlbum)); }
250+
}
251+
252+
242253
public List<Artist> Artists { get; set; }
243254

244255
private ObservableCollection<Artist> _selectedArtists = new ObservableCollection<Artist>();

src/MahApps.Metro/Controls/Helper/TextBoxHelper.cs

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ public class TextBoxHelper
100100
{ typeof(TimePicker), TimePickerBase.SelectedDateTimeProperty },
101101
{ typeof(DateTimePicker), DateTimePicker.SelectedDateTimeProperty },
102102
{ typeof(ColorPicker), ColorPickerBase.SelectedColorProperty },
103-
{ typeof(ColorCanvas), ColorPickerBase.SelectedColorProperty }
103+
{ typeof(ColorCanvas), ColorPickerBase.SelectedColorProperty },
104+
{ typeof(MultiSelectionComboBox), MultiSelectionComboBox.SelectedItemProperty }
104105
};
105106

106107
/// <summary>
@@ -122,6 +123,7 @@ public static void SetIsSpellCheckContextMenuEnabled(UIElement element, bool val
122123
[Category(AppName.MahApps)]
123124
[AttachedPropertyBrowsableForType(typeof(TextBox))]
124125
[AttachedPropertyBrowsableForType(typeof(ComboBox))]
126+
[AttachedPropertyBrowsableForType(typeof(MultiSelectionComboBox))]
125127
[AttachedPropertyBrowsableForType(typeof(DatePicker))]
126128
[AttachedPropertyBrowsableForType(typeof(TimePickerBase))]
127129
[AttachedPropertyBrowsableForType(typeof(NumericUpDown))]
@@ -392,6 +394,7 @@ public static void SetIsMonitoring(DependencyObject obj, bool value)
392394
[AttachedPropertyBrowsableForType(typeof(TextBoxBase))]
393395
[AttachedPropertyBrowsableForType(typeof(PasswordBox))]
394396
[AttachedPropertyBrowsableForType(typeof(ComboBox))]
397+
[AttachedPropertyBrowsableForType(typeof(MultiSelectionComboBox))]
395398
[AttachedPropertyBrowsableForType(typeof(DatePicker))]
396399
[AttachedPropertyBrowsableForType(typeof(TimePickerBase))]
397400
[AttachedPropertyBrowsableForType(typeof(NumericUpDown))]
@@ -406,6 +409,7 @@ public static string GetWatermark(DependencyObject obj)
406409
[AttachedPropertyBrowsableForType(typeof(TextBoxBase))]
407410
[AttachedPropertyBrowsableForType(typeof(PasswordBox))]
408411
[AttachedPropertyBrowsableForType(typeof(ComboBox))]
412+
[AttachedPropertyBrowsableForType(typeof(MultiSelectionComboBox))]
409413
[AttachedPropertyBrowsableForType(typeof(DatePicker))]
410414
[AttachedPropertyBrowsableForType(typeof(TimePickerBase))]
411415
[AttachedPropertyBrowsableForType(typeof(NumericUpDown))]
@@ -426,6 +430,7 @@ public static void SetWatermark(DependencyObject obj, string value)
426430
[AttachedPropertyBrowsableForType(typeof(TextBoxBase))]
427431
[AttachedPropertyBrowsableForType(typeof(PasswordBox))]
428432
[AttachedPropertyBrowsableForType(typeof(ComboBox))]
433+
[AttachedPropertyBrowsableForType(typeof(MultiSelectionComboBox))]
429434
[AttachedPropertyBrowsableForType(typeof(DatePicker))]
430435
[AttachedPropertyBrowsableForType(typeof(TimePickerBase))]
431436
[AttachedPropertyBrowsableForType(typeof(NumericUpDown))]
@@ -443,6 +448,7 @@ public static TextAlignment GetWatermarkAlignment(DependencyObject obj)
443448
[AttachedPropertyBrowsableForType(typeof(TextBoxBase))]
444449
[AttachedPropertyBrowsableForType(typeof(PasswordBox))]
445450
[AttachedPropertyBrowsableForType(typeof(ComboBox))]
451+
[AttachedPropertyBrowsableForType(typeof(MultiSelectionComboBox))]
446452
[AttachedPropertyBrowsableForType(typeof(DatePicker))]
447453
[AttachedPropertyBrowsableForType(typeof(TimePickerBase))]
448454
[AttachedPropertyBrowsableForType(typeof(NumericUpDown))]
@@ -463,6 +469,7 @@ public static void SetWatermarkAlignment(DependencyObject obj, TextAlignment val
463469
[AttachedPropertyBrowsableForType(typeof(TextBoxBase))]
464470
[AttachedPropertyBrowsableForType(typeof(PasswordBox))]
465471
[AttachedPropertyBrowsableForType(typeof(ComboBox))]
472+
[AttachedPropertyBrowsableForType(typeof(MultiSelectionComboBox))]
466473
[AttachedPropertyBrowsableForType(typeof(DatePicker))]
467474
[AttachedPropertyBrowsableForType(typeof(TimePickerBase))]
468475
[AttachedPropertyBrowsableForType(typeof(NumericUpDown))]
@@ -480,6 +487,7 @@ public static TextTrimming GetWatermarkTrimming(DependencyObject obj)
480487
[AttachedPropertyBrowsableForType(typeof(TextBoxBase))]
481488
[AttachedPropertyBrowsableForType(typeof(PasswordBox))]
482489
[AttachedPropertyBrowsableForType(typeof(ComboBox))]
490+
[AttachedPropertyBrowsableForType(typeof(MultiSelectionComboBox))]
483491
[AttachedPropertyBrowsableForType(typeof(DatePicker))]
484492
[AttachedPropertyBrowsableForType(typeof(TimePickerBase))]
485493
[AttachedPropertyBrowsableForType(typeof(NumericUpDown))]
@@ -516,6 +524,7 @@ public static void SetWatermarkWrapping(DependencyObject obj, TextWrapping value
516524
[AttachedPropertyBrowsableForType(typeof(TextBoxBase))]
517525
[AttachedPropertyBrowsableForType(typeof(PasswordBox))]
518526
[AttachedPropertyBrowsableForType(typeof(ComboBox))]
527+
[AttachedPropertyBrowsableForType(typeof(MultiSelectionComboBox))]
519528
[AttachedPropertyBrowsableForType(typeof(NumericUpDown))]
520529
[AttachedPropertyBrowsableForType(typeof(HotKeyBox))]
521530
[AttachedPropertyBrowsableForType(typeof(ColorPicker))]
@@ -536,6 +545,7 @@ public static void SetUseFloatingWatermark(DependencyObject obj, bool value)
536545
[AttachedPropertyBrowsableForType(typeof(TextBoxBase))]
537546
[AttachedPropertyBrowsableForType(typeof(PasswordBox))]
538547
[AttachedPropertyBrowsableForType(typeof(ComboBox))]
548+
[AttachedPropertyBrowsableForType(typeof(MultiSelectionComboBox))]
539549
[AttachedPropertyBrowsableForType(typeof(DatePicker))]
540550
[AttachedPropertyBrowsableForType(typeof(NumericUpDown))]
541551
public static bool GetHasText(DependencyObject obj)
@@ -896,7 +906,7 @@ public static void ButtonClicked(object sender, RoutedEventArgs e)
896906
{
897907
var button = (Button)sender;
898908

899-
var parent = button.GetAncestors().FirstOrDefault(a => a is RichTextBox || a is TextBox || a is PasswordBox || a is ComboBox || a is ColorPickerBase);
909+
var parent = button.GetAncestors().FirstOrDefault(a => a is RichTextBox || a is TextBox || a is PasswordBox || a is ComboBox || a is ColorPickerBase || a is MultiSelectionComboBox);
900910

901911
var command = GetButtonCommand(parent);
902912
var commandParameter = GetButtonCommandParameter(parent) ?? parent;
@@ -927,6 +937,26 @@ public static void ButtonClicked(object sender, RoutedEventArgs e)
927937
passwordBox.Clear();
928938
passwordBox.GetBindingExpression(PasswordBoxBindingBehavior.PasswordProperty)?.UpdateSource();
929939
}
940+
else if (parent is MultiSelectionComboBox multiSelectionComboBox)
941+
{
942+
if (multiSelectionComboBox.HasCustomText)
943+
{
944+
multiSelectionComboBox.UpdateEditableText();
945+
}
946+
else
947+
{
948+
switch (multiSelectionComboBox.SelectionMode)
949+
{
950+
case SelectionMode.Single:
951+
multiSelectionComboBox.SelectedItem = null;
952+
break;
953+
case SelectionMode.Multiple:
954+
case SelectionMode.Extended:
955+
multiSelectionComboBox.SelectedItems.Clear();
956+
break;
957+
}
958+
}
959+
}
930960
else if (parent is ComboBox comboBox)
931961
{
932962
if (comboBox.IsEditable)
@@ -942,6 +972,7 @@ public static void ButtonClicked(object sender, RoutedEventArgs e)
942972
{
943973
colorPicker.SetCurrentValue(ColorPickerBase.SelectedColorProperty, null);
944974
}
975+
945976
}
946977
}
947978

src/MahApps.Metro/Themes/MultiSelectionComboBox.xaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,8 @@
172172
Grid.Column="1"
173173
Width="{TemplateBinding mah:TextBoxHelper.ButtonWidth}"
174174
mah:TextBoxHelper.IsClearTextButtonBehaviorEnabled="False"
175-
Command="mah:MultiSelectionComboBox.ClearContentCommand"
175+
Command="{TemplateBinding mah:TextBoxHelper.ButtonCommand}"
176+
CommandParameter="{TemplateBinding mah:TextBoxHelper.ButtonCommandParameter}"
176177
Content="{TemplateBinding mah:TextBoxHelper.ButtonContent}"
177178
ContentTemplate="{TemplateBinding mah:TextBoxHelper.ButtonContentTemplate}"
178179
Focusable="False"

0 commit comments

Comments
 (0)