Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions src/MainDemo.Wpf/Fields.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
<TextBox VerticalAlignment="Center"
materialDesign:TextFieldAssist.HasClearButton="True"
materialDesign:TextFieldAssist.PrefixText="$"
materialDesign:TextFieldAssist.SelectAllOnTripleClick="True"
materialDesign:TextFieldAssist.SuffixText="mm"
Style="{StaticResource MaterialDesignFloatingHintTextBox}"
Text="Good stuff">
Expand Down Expand Up @@ -182,18 +183,18 @@
<CheckBox x:Name="TextBoxWrapTextCheckBox"
Content="Wrap text"
IsChecked="True" />

<TextBox Grid.Row="1"
Height="80"
MinWidth="280"
VerticalAlignment="Stretch"
materialDesign:HintAssist.Hint="Multiline text"
AcceptsReturn="True"
HorizontalScrollBarVisibility="Auto"
SpellCheck.IsEnabled="True"
Text="Multiline. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. The quick brown fox jumps over the lazy dog. War and peace. Keep going. Go on. For how long? Not long. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."
TextWrapping="{Binding ElementName=TextBoxWrapTextCheckBox, Path=IsChecked, Converter={StaticResource BoolToTextWrappingConverter}}"
VerticalScrollBarVisibility="Auto"
HorizontalScrollBarVisibility="Auto"/>
VerticalScrollBarVisibility="Auto" />
</Grid>
</smtx:XamlDisplay>

Expand Down Expand Up @@ -690,12 +691,11 @@
<TextBlock Style="{StaticResource PageSectionTitleTextBlock}" Text="Custom Background" />

<WrapPanel Margin="0,0,0,32" Background="Chocolate">
<smtx:XamlDisplay Margin="16"
UniqueKey="fields_custom_background_1">
<smtx:XamlDisplay Margin="16" UniqueKey="fields_custom_background_1">
<TextBox Width="200"
Style="{StaticResource MaterialDesignOutlinedTextBox}"
materialDesign:HintAssist.Hint="Hint text"
materialDesign:HintAssist.HintPaddingBrush="Chocolate" />
materialDesign:HintAssist.HintPaddingBrush="Chocolate"
Style="{StaticResource MaterialDesignOutlinedTextBox}" />
<!-- Set HintAssist.HintPaddingBrush to match the custom background to get correct coloring of the hint padding (when floated) -->
</smtx:XamlDisplay>
</WrapPanel>
Expand All @@ -704,7 +704,7 @@
<TextBlock Style="{StaticResource PageSectionTitleTextBlock}" Text="AutoSuggestBox" />

<WrapPanel>
<StackPanel Width="256" Margin="0,0,16,16">
<StackPanel Width="256" Margin="0,0,16,16">
<TextBlock Margin="0,0,0,8"
VerticalAlignment="Center"
Style="{StaticResource MaterialDesignSubtitle1TextBlock}"
Expand All @@ -719,7 +719,7 @@
</smtx:XamlDisplay>
</StackPanel>

<StackPanel Width="256" Margin="0,0,16,16">
<StackPanel Width="256" Margin="0,0,16,16">
<TextBlock Margin="0,0,0,8"
Style="{StaticResource MaterialDesignSubtitle1TextBlock}"
Text="AutoSuggestBox with ItemTemplate" />
Expand Down Expand Up @@ -774,7 +774,7 @@
</smtx:XamlDisplay>
</StackPanel>

<StackPanel Width="256" Margin="0,0,16,16">
<StackPanel Width="256" Margin="0,0,16,16">
<TextBlock Margin="0,0,0,8"
Style="{StaticResource MaterialDesignSubtitle1TextBlock}"
Text="Outlined AutoSuggestBox" />
Expand Down
39 changes: 39 additions & 0 deletions src/MaterialDesignThemes.Wpf/TextFieldAssist.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,45 @@ public static class TextFieldAssist

public static bool GetIncludeSpellingSuggestions(TextBoxBase element) => (bool)element.GetValue(IncludeSpellingSuggestionsProperty);

/// <summary>
/// Allow triple click to select all text in a TextBox.
/// </summary>
public static readonly DependencyProperty SelectAllOnTripleClickProperty =
DependencyProperty.RegisterAttached(
"SelectAllOnTripleClick",
typeof(bool),
typeof(TextFieldAssist),
new PropertyMetadata(false, OnSelectAllOnTripleClickChanged));

public static bool GetSelectAllOnTripleClick(DependencyObject obj) =>
(bool)obj.GetValue(SelectAllOnTripleClickProperty);

public static void SetSelectAllOnTripleClick(DependencyObject obj, bool value) =>
obj.SetValue(SelectAllOnTripleClickProperty, value);

private static void OnSelectAllOnTripleClickChanged(
DependencyObject d,
DependencyPropertyChangedEventArgs e)
{
if (d is TextBox textBox)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (d is TextBox textBox)
if (d is TextBoxBase textBox)

{
if ((bool)e.NewValue)
textBox.PreviewMouseLeftButtonDown += TextBox_PreviewMouseLeftButtonDown;
else
textBox.PreviewMouseLeftButtonDown -= TextBox_PreviewMouseLeftButtonDown;
}
}

private static void TextBox_PreviewMouseLeftButtonDown(
object sender,
MouseButtonEventArgs e)
{
if (e.ClickCount == 3 && sender is TextBox textBox)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (e.ClickCount == 3 && sender is TextBox textBox)
if (e.ClickCount == 3 && sender is TextBoxBase textBox)

{
textBox.SelectAll();
e.Handled = true;
}
}
/// <summary>
/// SuffixText dependency property
/// </summary>
Expand Down
21 changes: 21 additions & 0 deletions tests/MaterialDesignThemes.UITests/WPF/TextBoxes/TextBoxTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,27 @@ public async Task TextBox_MultiLineAndFixedHeight_RespectsVerticalContentAlignme
}

[Test]
public async Task TextBox_WithSelectAllOnTripleClick_SelectsAllText()
{
var textBox = await LoadXaml<TextBox>($$"""
<TextBox Style="{StaticResource MaterialDesignFilledTextBox}"
Text="Some text to select"
materialDesign:TextFieldAssist.SelectAllOnTripleClick="True"
Width="200" VerticalAlignment="Center" HorizontalAlignment="Center" />
""");
await textBox.LeftClick();
await textBox.LeftClick();
await textBox.LeftClick();
//await Task.Delay(1000);
await Wait.For(async () =>
{
string? selectedText = await textBox.GetSelectedText();

await Assert.That(selectedText).IsEqualTo("Some text to select");
});
}

[Test]
[Description("Issue 3176")]
public async Task ValidationErrorTemplate_WithChangingErrors_UpdatesValidation()
{
Expand Down