Skip to content

Commit 9ec7e2a

Browse files
[SmartHint] Follow up - make behavior and supporting APs public (#3689)
* Ensure behavior triggers AP change on initial binding * Make helper APs public * Apply renamed APs
1 parent 7cdaa76 commit 9ec7e2a

File tree

4 files changed

+27
-22
lines changed

4 files changed

+27
-22
lines changed

src/MaterialDesignThemes.Wpf/Behaviors/TextBoxLineCountBehavior.cs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,32 @@
33
namespace MaterialDesignThemes.Wpf.Behaviors;
44

55
/// <summary>
6-
/// Internal behavior exposing the <see cref="TextBox.LineCount"/> (non-DP) as an attached property which we can bind to
6+
/// Behavior exposing the <see cref="TextBox.LineCount"/> (non-DP) as attached properties which are bindable from XAML.
77
/// </summary>
8-
internal class TextBoxLineCountBehavior : Behavior<TextBox>
8+
public class TextBoxLineCountBehavior : Behavior<TextBox>
99
{
10-
private void AssociatedObjectOnTextChanged(object sender, TextChangedEventArgs e)
10+
private void AssociatedObjectOnTextChanged(object sender, TextChangedEventArgs e) => UpdateAttachedProperties();
11+
private void AssociatedObjectOnLayoutUpdated(object? sender, EventArgs e) => UpdateAttachedProperties();
12+
13+
private void UpdateAttachedProperties()
1114
{
12-
AssociatedObject.SetCurrentValue(TextFieldAssist.LineCountProperty, AssociatedObject.LineCount);
13-
AssociatedObject.SetCurrentValue(TextFieldAssist.IsMultiLineProperty, AssociatedObject.LineCount > 1);
15+
AssociatedObject.SetCurrentValue(TextFieldAssist.TextBoxLineCountProperty, AssociatedObject.LineCount);
16+
AssociatedObject.SetCurrentValue(TextFieldAssist.TextBoxIsMultiLineProperty, AssociatedObject.LineCount > 1);
1417
}
1518

1619
protected override void OnAttached()
1720
{
1821
base.OnAttached();
1922
AssociatedObject.TextChanged += AssociatedObjectOnTextChanged;
23+
AssociatedObject.LayoutUpdated += AssociatedObjectOnLayoutUpdated;
2024
}
2125

2226
protected override void OnDetaching()
2327
{
2428
if (AssociatedObject != null)
2529
{
2630
AssociatedObject.TextChanged -= AssociatedObjectOnTextChanged;
31+
AssociatedObject.LayoutUpdated -= AssociatedObjectOnLayoutUpdated;
2732
}
2833
base.OnDetaching();
2934
}

src/MaterialDesignThemes.Wpf/TextFieldAssist.cs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -368,19 +368,19 @@ public static void SetOutlinedBorderActiveThickness(DependencyObject element, Th
368368
public static Thickness GetOutlinedBorderActiveThickness(DependencyObject element)
369369
=> (Thickness)element.GetValue(OutlinedBorderActiveThicknessProperty);
370370

371-
internal static readonly DependencyProperty LineCountProperty = DependencyProperty.RegisterAttached(
372-
"LineCount", typeof(int), typeof(TextFieldAssist), new PropertyMetadata(0));
373-
internal static void SetLineCount(DependencyObject element, int value)
374-
=> element.SetValue(LineCountProperty, value);
375-
internal static int GetLineCount(DependencyObject element)
376-
=> (int) element.GetValue(LineCountProperty);
377-
378-
internal static readonly DependencyProperty IsMultiLineProperty = DependencyProperty.RegisterAttached(
379-
"IsMultiLine", typeof(bool), typeof(TextFieldAssist), new PropertyMetadata(false));
380-
internal static void SetIsMultiLine(DependencyObject element, bool value)
381-
=> element.SetValue(IsMultiLineProperty, value);
382-
internal static bool GetIsMultiLine(DependencyObject element)
383-
=> (bool) element.GetValue(IsMultiLineProperty);
371+
public static readonly DependencyProperty TextBoxLineCountProperty = DependencyProperty.RegisterAttached(
372+
"TextBoxLineCount", typeof(int), typeof(TextFieldAssist), new PropertyMetadata(0));
373+
public static void SetTextBoxLineCount(DependencyObject element, int value)
374+
=> element.SetValue(TextBoxLineCountProperty, value);
375+
public static int GetTextBoxLineCount(DependencyObject element)
376+
=> (int) element.GetValue(TextBoxLineCountProperty);
377+
378+
public static readonly DependencyProperty TextBoxIsMultiLineProperty = DependencyProperty.RegisterAttached(
379+
"TextBoxIsMultiLine", typeof(bool), typeof(TextFieldAssist), new PropertyMetadata(false));
380+
public static void SetTextBoxIsMultiLine(DependencyObject element, bool value)
381+
=> element.SetValue(TextBoxIsMultiLineProperty, value);
382+
public static bool GetTextBoxIsMultiLine(DependencyObject element)
383+
=> (bool) element.GetValue(TextBoxIsMultiLineProperty);
384384

385385
#region Methods
386386

src/MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.AutoSuggestBox.xaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@
328328
<MultiTrigger>
329329
<MultiTrigger.Conditions>
330330
<Condition Property="VerticalContentAlignment" Value="Stretch" />
331-
<Condition Property="wpf:TextFieldAssist.IsMultiLine" Value="True" />
331+
<Condition Property="wpf:TextFieldAssist.TextBoxIsMultiLine" Value="True" />
332332
</MultiTrigger.Conditions>
333333
<Setter TargetName="PrefixTextBlock" Property="VerticalAlignment" Value="Stretch" />
334334
<Setter TargetName="SuffixTextBlock" Property="VerticalAlignment" Value="Stretch" />
@@ -516,7 +516,7 @@
516516
<MultiBinding Converter="{StaticResource FloatingHintInitialVerticalOffsetConverter}">
517517
<Binding ElementName="PART_ContentHost" Path="ActualHeight" />
518518
<Binding ElementName="Hint" Path="ActualHeight" />
519-
<Binding RelativeSource="{RelativeSource TemplatedParent}" Path="(wpf:TextFieldAssist.LineCount)" />
519+
<Binding RelativeSource="{RelativeSource TemplatedParent}" Path="(wpf:TextFieldAssist.TextBoxLineCount)" />
520520
</MultiBinding>
521521
</Setter.Value>
522522
</Setter>

src/MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.TextBox.xaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@
340340
<MultiTrigger>
341341
<MultiTrigger.Conditions>
342342
<Condition Property="VerticalContentAlignment" Value="Stretch" />
343-
<Condition Property="wpf:TextFieldAssist.IsMultiLine" Value="True" />
343+
<Condition Property="wpf:TextFieldAssist.TextBoxIsMultiLine" Value="True" />
344344
</MultiTrigger.Conditions>
345345
<Setter TargetName="PrefixTextBlock" Property="VerticalAlignment" Value="Stretch" />
346346
<Setter TargetName="SuffixTextBlock" Property="VerticalAlignment" Value="Stretch" />
@@ -522,7 +522,7 @@
522522
<MultiBinding Converter="{StaticResource FloatingHintInitialVerticalOffsetConverter}">
523523
<Binding ElementName="PART_ContentHost" Path="ActualHeight" />
524524
<Binding ElementName="Hint" Path="ActualHeight" />
525-
<Binding RelativeSource="{RelativeSource TemplatedParent}" Path="(wpf:TextFieldAssist.LineCount)" />
525+
<Binding RelativeSource="{RelativeSource TemplatedParent}" Path="(wpf:TextFieldAssist.TextBoxLineCount)" />
526526
</MultiBinding>
527527
</Setter.Value>
528528
</Setter>

0 commit comments

Comments
 (0)