Skip to content

Commit cc6bbb8

Browse files
committed
better probing of content for smart hint to decide what state to display. fixes #532
1 parent 2706426 commit cc6bbb8

File tree

6 files changed

+31
-4
lines changed

6 files changed

+31
-4
lines changed

MainDemo.Wpf/Snackbars.xaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
88
mc:Ignorable="d"
99
d:DesignHeight="300" d:DesignWidth="300">
10+
1011
<ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Hidden">
1112
<Grid Margin="0 0 0 4">
1213
<Grid.ColumnDefinitions>

MaterialDesignThemes.Wpf/HintProxyFabric.ComboBox.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,26 @@ public object Content
2525
return _comboBox.Text;
2626
}
2727

28-
ComboBoxItem comboBoxItem = _comboBox.SelectedItem as ComboBoxItem;
28+
var comboBoxItem = _comboBox.SelectedItem as ComboBoxItem;
2929
return comboBoxItem != null
3030
? comboBoxItem.Content
3131
: _comboBox.SelectedItem;
3232
}
3333
}
3434

3535
public bool IsLoaded => _comboBox.IsLoaded;
36-
public bool IsVisible => _comboBox.IsVisible;
36+
37+
public bool IsVisible => _comboBox.IsVisible;
38+
39+
public bool IsEmpty()
40+
{
41+
return string.IsNullOrWhiteSpace(_comboBox.Text);
42+
}
3743

3844
public event EventHandler ContentChanged;
45+
3946
public event EventHandler IsVisibleChanged;
47+
4048
public event EventHandler Loaded;
4149

4250
public ComboBoxHintProxy(ComboBox comboBox)

MaterialDesignThemes.Wpf/HintProxyFabric.PasswordBox.cs

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

12+
public bool IsEmpty() => string.IsNullOrWhiteSpace(_passwordBox.Password);
13+
1214
public object Content => _passwordBox.Password;
15+
1316
public bool IsLoaded => _passwordBox.IsLoaded;
17+
1418
public bool IsVisible => _passwordBox.IsVisible;
1519

1620
public event EventHandler ContentChanged;

MaterialDesignThemes.Wpf/HintProxyFabric.TextBox.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,13 @@ private sealed class TextBoxHintProxy : IHintProxy
1111
private readonly TextBox _textBox;
1212

1313
public object Content => _textBox.Text;
14+
1415
public bool IsLoaded => _textBox.IsLoaded;
16+
1517
public bool IsVisible => _textBox.IsVisible;
1618

19+
public bool IsEmpty() => string.IsNullOrWhiteSpace(_textBox.Text);
20+
1721
public event EventHandler ContentChanged;
1822
public event EventHandler IsVisibleChanged;
1923
public event EventHandler Loaded;

MaterialDesignThemes.Wpf/IHintProxy.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@ namespace MaterialDesignThemes.Wpf
1414
/// </summary>
1515
public interface IHintProxy : IDisposable
1616
{
17+
/// <summary>
18+
/// Checks to see if the targetted control can be deemed as logically
19+
/// empty, even if not null, affecting the current hint display.
20+
/// </summary>
21+
/// <returns></returns>
22+
bool IsEmpty();
23+
24+
[Obsolete]
1725
object Content { get; }
1826

1927
bool IsLoaded { get; }

MaterialDesignThemes.Wpf/SmartHint.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ private static void HintProxyPropertyChangedCallback(DependencyObject dependency
150150

151151
protected virtual void OnHintProxyContentChanged(object sender, EventArgs e)
152152
{
153-
IsContentNullOrEmpty = string.IsNullOrEmpty((HintProxy.Content ?? "").ToString());
153+
IsContentNullOrEmpty = HintProxy.IsEmpty();
154154

155155
if (HintProxy.IsLoaded)
156156
{
@@ -182,7 +182,7 @@ private void RefreshState(bool useTransitions)
182182

183183
var action = new Action(() =>
184184
{
185-
var state = String.IsNullOrEmpty((proxy.Content ?? String.Empty).ToString())
185+
var state = proxy.IsEmpty()
186186
? ContentEmptyName
187187
: ContentNotEmptyName;
188188

@@ -198,5 +198,7 @@ private void RefreshState(bool useTransitions)
198198
Dispatcher.BeginInvoke(action);
199199
}
200200
}
201+
202+
201203
}
202204
}

0 commit comments

Comments
 (0)