Skip to content

Commit 1debcf9

Browse files
committed
rename a couple of props, resharper coding standards, and enable more complex hints
1 parent e6acf16 commit 1debcf9

16 files changed

+98
-86
lines changed

MainDemo.Wpf/TextFields.xaml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,15 @@
165165
</StackPanel>
166166
</StackPanel>
167167

168-
<TextBox Grid.Row="5" Grid.Column="1" materialDesign:HintAssist.Hint="Floating Hint" Style="{StaticResource MaterialDesignFloatingHintTextBox}" Text="Good stuff"
169-
Margin="0 8 0 8"/>
168+
<TextBox Grid.Row="5" Grid.Column="1" Style="{StaticResource MaterialDesignFloatingHintTextBox}" Text="Good stuff"
169+
Margin="0 8 0 8">
170+
<materialDesign:HintAssist.Hint>
171+
<StackPanel Orientation="Horizontal" Margin="-2 0 0 0">
172+
<materialDesign:PackIcon Kind="AccessPoint" />
173+
<TextBlock>WiFi</TextBlock>
174+
</StackPanel>
175+
</materialDesign:HintAssist.Hint>
176+
</TextBox>
170177
<ComboBox Grid.Row="5" Grid.Column="3" materialDesign:HintAssist.Hint="Search" IsEditable="True" Style="{StaticResource MaterialDesignFloatingHintComboBox}"
171178
Margin="0 8 0 8">
172179
<ComboBoxItem IsSelected="True">Apple</ComboBoxItem>

MaterialDesignThemes.Wpf/HintAssist.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,20 @@ public static class HintAssist
66
{
77
#region UseFloating
88

9-
public static readonly DependencyProperty UseFloatingProperty = DependencyProperty.RegisterAttached(
10-
"UseFloating",
9+
public static readonly DependencyProperty IsFloatingProperty = DependencyProperty.RegisterAttached(
10+
"IsFloating",
1111
typeof(bool),
1212
typeof(HintAssist),
1313
new FrameworkPropertyMetadata(default(bool), FrameworkPropertyMetadataOptions.Inherits));
1414

15-
public static bool GetUseFloating(DependencyObject element)
15+
public static bool GetIsFloating(DependencyObject element)
1616
{
17-
return (bool) element.GetValue(UseFloatingProperty);
17+
return (bool) element.GetValue(IsFloatingProperty);
1818
}
1919

20-
public static void SetUseFloating(DependencyObject element, bool value)
20+
public static void SetIsFloating(DependencyObject element, bool value)
2121
{
22-
element.SetValue(UseFloatingProperty, value);
22+
element.SetValue(IsFloatingProperty, value);
2323
}
2424

2525
#endregion
@@ -31,7 +31,7 @@ public static void SetUseFloating(DependencyObject element, bool value)
3131
/// </summary>
3232
public static readonly DependencyProperty HintProperty = DependencyProperty.RegisterAttached(
3333
"Hint",
34-
typeof(string),
34+
typeof(object),
3535
typeof(HintAssist),
3636
new FrameworkPropertyMetadata(default(string), FrameworkPropertyMetadataOptions.Inherits));
3737

@@ -40,7 +40,7 @@ public static void SetUseFloating(DependencyObject element, bool value)
4040
/// </summary>
4141
/// <param name="element">The element.</param>
4242
/// <param name="value">The value.</param>
43-
public static void SetHint(DependencyObject element, string value)
43+
public static void SetHint(DependencyObject element, object value)
4444
{
4545
element.SetValue(HintProperty, value);
4646
}
@@ -52,9 +52,9 @@ public static void SetHint(DependencyObject element, string value)
5252
/// <returns>
5353
/// The <see cref="string" />.
5454
/// </returns>
55-
public static string GetHint(DependencyObject element)
55+
public static object GetHint(DependencyObject element)
5656
{
57-
return (string)element.GetValue(HintProperty);
57+
return element.GetValue(HintProperty);
5858
}
5959

6060
#endregion

MaterialDesignThemes.Wpf/HintProxyFabric.ComboBox.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ private sealed class ComboBoxHintProxy : IHintProxy
1616
private readonly ComboBox _comboBox;
1717
private readonly TextChangedEventHandler _comboBoxTextChangedEventHandler;
1818

19-
public string Text => _comboBox.Text;
19+
public object Content => _comboBox.Text;
2020
public bool IsLoaded => _comboBox.IsLoaded;
2121
public bool IsVisible => _comboBox.IsVisible;
2222

23-
public event EventHandler TextChanged;
23+
public event EventHandler ContentChanged;
2424
public event EventHandler IsVisibleChanged;
2525
public event EventHandler Loaded;
2626

@@ -38,7 +38,7 @@ public ComboBoxHintProxy(ComboBox comboBox)
3838

3939
private void ComboBoxSelectionChanged(object sender, SelectionChangedEventArgs e)
4040
{
41-
TextChanged?.Invoke(sender, EventArgs.Empty);
41+
ContentChanged?.Invoke(sender, EventArgs.Empty);
4242
}
4343

4444
private void ComboBoxIsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
@@ -53,7 +53,7 @@ private void ComboBoxLoaded(object sender, RoutedEventArgs e)
5353

5454
private void ComboBoxTextChanged(object sender, TextChangedEventArgs e)
5555
{
56-
TextChanged?.Invoke(sender, EventArgs.Empty);
56+
ContentChanged?.Invoke(sender, EventArgs.Empty);
5757
}
5858

5959
public void Dispose()

MaterialDesignThemes.Wpf/HintProxyFabric.PasswordBox.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ private sealed class PasswordBoxHintProxy : IHintProxy
99
{
1010
private readonly PasswordBox _passwordBox;
1111

12-
public string Text => _passwordBox.Password;
12+
public object Content => _passwordBox.Password;
1313
public bool IsLoaded => _passwordBox.IsLoaded;
1414
public bool IsVisible => _passwordBox.IsVisible;
1515

16-
public event EventHandler TextChanged;
16+
public event EventHandler ContentChanged;
1717
public event EventHandler IsVisibleChanged;
1818
public event EventHandler Loaded;
1919

@@ -39,7 +39,7 @@ private void PasswordBoxLoaded(object sender, System.Windows.RoutedEventArgs e)
3939

4040
private void PasswordBoxPasswordChanged(object sender, System.Windows.RoutedEventArgs e)
4141
{
42-
TextChanged?.Invoke(this, EventArgs.Empty);
42+
ContentChanged?.Invoke(this, EventArgs.Empty);
4343
}
4444

4545
public void Dispose()

MaterialDesignThemes.Wpf/HintProxyFabric.TextBox.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ private sealed class TextBoxHintProxy : IHintProxy
1010
{
1111
private readonly TextBox _textBox;
1212

13-
public string Text => _textBox.Text;
13+
public object Content => _textBox.Text;
1414
public bool IsLoaded => _textBox.IsLoaded;
1515
public bool IsVisible => _textBox.IsVisible;
1616

17-
public event EventHandler TextChanged;
17+
public event EventHandler ContentChanged;
1818
public event EventHandler IsVisibleChanged;
1919
public event EventHandler Loaded;
2020

@@ -40,7 +40,7 @@ private void TextBoxLoaded(object sender, RoutedEventArgs e)
4040

4141
private void TextBoxTextChanged(object sender, TextChangedEventArgs e)
4242
{
43-
TextChanged?.Invoke(sender, EventArgs.Empty);
43+
ContentChanged?.Invoke(sender, EventArgs.Empty);
4444
}
4545

4646
public void Dispose()

MaterialDesignThemes.Wpf/HintProxyFabric.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,23 +27,23 @@ public HintProxyBuilder(Func<Control, bool> canBuild, Func<Control, IHintProxy>
2727
public IHintProxy Build(Control control) => _build(control);
2828
}
2929

30-
private static readonly List<HintProxyBuilder> _builders = new List<HintProxyBuilder>();
30+
private static readonly List<HintProxyBuilder> Builders = new List<HintProxyBuilder>();
3131

3232
static HintProxyFabric()
3333
{
34-
_builders.Add(new HintProxyBuilder(c => c is ComboBox, c => new ComboBoxHintProxy((ComboBox) c)));
35-
_builders.Add(new HintProxyBuilder(c => c is TextBox, c => new TextBoxHintProxy((TextBox)c)));
36-
_builders.Add(new HintProxyBuilder(c => c is PasswordBox, c => new PasswordBoxHintProxy((PasswordBox)c)));
34+
Builders.Add(new HintProxyBuilder(c => c is ComboBox, c => new ComboBoxHintProxy((ComboBox) c)));
35+
Builders.Add(new HintProxyBuilder(c => c is TextBox, c => new TextBoxHintProxy((TextBox)c)));
36+
Builders.Add(new HintProxyBuilder(c => c is PasswordBox, c => new PasswordBoxHintProxy((PasswordBox)c)));
3737
}
3838

3939
public static void RegisterBuilder(Func<Control, bool> canBuild, Func<Control, IHintProxy> build)
4040
{
41-
_builders.Add(new HintProxyBuilder(canBuild, build));
41+
Builders.Add(new HintProxyBuilder(canBuild, build));
4242
}
4343

4444
public static IHintProxy Get(Control control)
4545
{
46-
var builder = _builders.FirstOrDefault(v => v.CanBuild(control));
46+
var builder = Builders.FirstOrDefault(v => v.CanBuild(control));
4747

4848
if (builder == null) throw new NotImplementedException();
4949

MaterialDesignThemes.Wpf/IHintProxy.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,16 @@ namespace MaterialDesignThemes.Wpf
1414
/// </summary>
1515
public interface IHintProxy : IDisposable
1616
{
17-
string Text { get; }
17+
object Content { get; }
18+
1819
bool IsLoaded { get; }
20+
1921
bool IsVisible { get; }
2022

21-
event EventHandler TextChanged;
23+
event EventHandler ContentChanged;
24+
2225
event EventHandler IsVisibleChanged;
26+
2327
event EventHandler Loaded;
2428
}
2529
}

MaterialDesignThemes.Wpf/SmartHint.cs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -39,25 +39,25 @@ public IHintProxy HintProxy
3939
#region HintProperty
4040

4141
public static readonly DependencyProperty HintProperty = DependencyProperty.Register(
42-
nameof(Hint), typeof(string), typeof(SmartHint), new PropertyMetadata(default(string)));
42+
nameof(Hint), typeof(object), typeof(SmartHint), new PropertyMetadata(null));
4343

44-
public string Hint
44+
public object Hint
4545
{
46-
get { return (string)GetValue(HintProperty); }
46+
get { return GetValue(HintProperty); }
4747
set { SetValue(HintProperty, value); }
4848
}
4949

5050
#endregion
5151

52-
#region IsTextNullOrEmpty
52+
#region IsContentNullOrEmpty
5353

54-
public static readonly DependencyProperty IsTextNullOrEmptyProperty = DependencyProperty.Register(
55-
nameof(IsTextNullOrEmpty), typeof(bool), typeof(SmartHint), new PropertyMetadata(default(bool)));
54+
public static readonly DependencyProperty IsContentNullOrEmptyProperty = DependencyProperty.Register(
55+
nameof(IsContentNullOrEmpty), typeof(bool), typeof(SmartHint), new PropertyMetadata(default(bool)));
5656

57-
public bool IsTextNullOrEmpty
57+
public bool IsContentNullOrEmpty
5858
{
59-
get { return (bool)GetValue(IsTextNullOrEmptyProperty); }
60-
set { SetValue(IsTextNullOrEmptyProperty, value); }
59+
get { return (bool)GetValue(IsContentNullOrEmptyProperty); }
60+
set { SetValue(IsContentNullOrEmptyProperty, value); }
6161
}
6262

6363
#endregion
@@ -110,24 +110,24 @@ private static void HintProxyPropertyChangedCallback(DependencyObject dependency
110110
if (hintProxy != null)
111111
{
112112
hintProxy.IsVisibleChanged -= smartHint.OnHintProxyIsVisibleChanged;
113-
hintProxy.TextChanged -= smartHint.OnHintProxyTextChanged;
114-
hintProxy.Loaded -= smartHint.OnHintProxyTextChanged;
113+
hintProxy.ContentChanged -= smartHint.OnHintProxyContentChanged;
114+
hintProxy.Loaded -= smartHint.OnHintProxyContentChanged;
115115
hintProxy.Dispose();
116116
}
117117

118118
hintProxy = dependencyPropertyChangedEventArgs.NewValue as IHintProxy;
119119
if (hintProxy != null)
120120
{
121121
hintProxy.IsVisibleChanged += smartHint.OnHintProxyIsVisibleChanged;
122-
hintProxy.TextChanged += smartHint.OnHintProxyTextChanged;
123-
hintProxy.Loaded += smartHint.OnHintProxyTextChanged;
122+
hintProxy.ContentChanged += smartHint.OnHintProxyContentChanged;
123+
hintProxy.Loaded += smartHint.OnHintProxyContentChanged;
124124
smartHint.RefreshState(false);
125125
}
126126
}
127127

128-
protected virtual void OnHintProxyTextChanged(object sender, EventArgs e)
128+
protected virtual void OnHintProxyContentChanged(object sender, EventArgs e)
129129
{
130-
IsTextNullOrEmpty = String.IsNullOrEmpty(HintProxy.Text);
130+
IsContentNullOrEmpty = string.IsNullOrEmpty((HintProxy.Content ?? "").ToString());
131131

132132
if (HintProxy.IsLoaded)
133133
{
@@ -157,7 +157,7 @@ private void RefreshState(bool useTransitions)
157157

158158
Dispatcher.BeginInvoke(new Action(() =>
159159
{
160-
var state = string.IsNullOrEmpty(HintProxy.Text)
160+
var state = string.IsNullOrEmpty((HintProxy.Content ?? "").ToString())
161161
? MaterialDesignStateTextEmptyName
162162
: MaterialDesignStateTextNotEmptyName;
163163

MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.ComboBox.xaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@
420420
FontSize="{TemplateBinding FontSize}"
421421
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
422422
UseLayoutRounding="{TemplateBinding UseLayoutRounding}"
423-
UseFloating="{Binding Path=(wpf:HintAssist.UseFloating), RelativeSource={RelativeSource TemplatedParent}}"
423+
UseFloating="{Binding Path=(wpf:HintAssist.IsFloating), RelativeSource={RelativeSource TemplatedParent}}"
424424
HintOpacity="{Binding Path=(wpf:HintAssist.HintOpacity), RelativeSource={RelativeSource TemplatedParent}}"
425425
Hint="{TemplateBinding wpf:HintAssist.Hint}" />
426426
</Grid>
@@ -474,21 +474,21 @@
474474
</MultiTrigger>
475475
<MultiTrigger>
476476
<MultiTrigger.Conditions>
477-
<Condition SourceName="Hint" Property="IsTextNullOrEmpty" Value="False" />
477+
<Condition SourceName="Hint" Property="IsContentNullOrEmpty" Value="False" />
478478
<Condition Property="IsKeyboardFocused" Value="True" />
479479
</MultiTrigger.Conditions>
480480
<Setter TargetName="Hint" Property="Foreground" Value="{DynamicResource PrimaryHueMidBrush}" />
481481
</MultiTrigger>
482482
<MultiTrigger>
483483
<MultiTrigger.Conditions>
484-
<Condition SourceName="Hint" Property="IsTextNullOrEmpty" Value="False" />
484+
<Condition SourceName="Hint" Property="IsContentNullOrEmpty" Value="False" />
485485
<Condition SourceName="PART_EditableTextBox" Property="IsKeyboardFocused" Value="True" />
486486
</MultiTrigger.Conditions>
487487
<Setter TargetName="Hint" Property="Foreground" Value="{DynamicResource PrimaryHueMidBrush}" />
488488
</MultiTrigger>
489489
<MultiTrigger>
490490
<MultiTrigger.Conditions>
491-
<Condition SourceName="Hint" Property="IsTextNullOrEmpty" Value="False" />
491+
<Condition SourceName="Hint" Property="IsContentNullOrEmpty" Value="False" />
492492
<Condition Property="IsDropDownOpen" Value="True" />
493493
</MultiTrigger.Conditions>
494494
<Setter TargetName="Hint" Property="Foreground" Value="{DynamicResource PrimaryHueMidBrush}" />
@@ -543,7 +543,7 @@
543543
<Style x:Key="MaterialDesignFloatingHintComboBox"
544544
BasedOn="{StaticResource MaterialDesignComboBox}"
545545
TargetType="{x:Type ComboBox}">
546-
<Setter Property="wpf:HintAssist.UseFloating" Value="True"/>
546+
<Setter Property="wpf:HintAssist.IsFloating" Value="True"/>
547547
</Style>
548548

549549
</ResourceDictionary>

MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.DataGrid.ComboBox.xaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@
183183
FontSize="{TemplateBinding FontSize}"
184184
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
185185
UseLayoutRounding="{TemplateBinding UseLayoutRounding}"
186-
UseFloating="{Binding Path=(wpf:HintAssist.UseFloating), RelativeSource={RelativeSource TemplatedParent}}"
186+
UseFloating="{Binding Path=(wpf:HintAssist.IsFloating), RelativeSource={RelativeSource TemplatedParent}}"
187187
HintOpacity="{Binding Path=(wpf:HintAssist.HintOpacity), RelativeSource={RelativeSource TemplatedParent}}"
188188
Hint="{TemplateBinding wpf:HintAssist.Hint}" />
189189
<ContentPresenter x:Name="contentPresenter" ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}" ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}" Content="{TemplateBinding SelectionBoxItem}" ContentStringFormat="{TemplateBinding SelectionBoxItemStringFormat}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" IsHitTestVisible="false" Margin="{TemplateBinding Padding}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
@@ -268,7 +268,7 @@
268268
FontSize="{TemplateBinding FontSize}"
269269
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
270270
UseLayoutRounding="{TemplateBinding UseLayoutRounding}"
271-
UseFloating="{Binding Path=(wpf:HintAssist.UseFloating), RelativeSource={RelativeSource TemplatedParent}}"
271+
UseFloating="{Binding Path=(wpf:HintAssist.IsFloating), RelativeSource={RelativeSource TemplatedParent}}"
272272
HintOpacity="{Binding Path=(wpf:HintAssist.HintOpacity), RelativeSource={RelativeSource TemplatedParent}}"
273273
Hint="{TemplateBinding wpf:HintAssist.Hint}" />
274274
<TextBox x:Name="PART_EditableTextBox" HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" IsReadOnly="{Binding IsReadOnly, RelativeSource={RelativeSource TemplatedParent}}" Margin="{TemplateBinding Padding}" Style="{StaticResource MaterialDesignDataGridComboBoxEditableTextBox}" VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"/>

0 commit comments

Comments
 (0)