Clicking on the "X" button added by TextBoxHelper.ClearTextButton does not clear the databinding target
See original GitHub issueWhat steps will reproduce this issue?
- Click on Textbox1
- Enter some string, eg “123”
- Press TAB or click on other textboxes
- The string, “123” will be shown in Textbox2 (due to data binding)
- Click the “X” button on Textbox1
- The string on Textbox2 is not cleared
I noted that for the “X” button to clear the databinding target,
- The textbox where the “X” is going to be clicked on must be the active control (focused) or
- After clicking the “X” button, focus the textbox which the “X” button was clicked on by clicking on it, and then click on other control to make to lose focus.
Expected outcome
Upon clicking the “X” button, the databinding target should be cleared immediately.
Code
cs
using System.Windows;
namespace Test
{
/// <summary>
/// Interaction logic for Window1.xaml
/// </summary>
public partial class Window1 : Window
{
public string MyString
{
get { return (string)GetValue(MyStringProperty); }
set { SetValue(MyStringProperty, value); }
}
// Using a DependencyProperty as the backing store for MyString. This enables animation, styling, binding, etc...
public static readonly DependencyProperty MyStringProperty =
DependencyProperty.Register("MyString", typeof(string), typeof(Window1), new PropertyMetadata());
public Window1()
{
InitializeComponent();
}
}
}
XAML
<Window x:Class="Test.Window1"
x:Name="this"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Test"
xmlns:mahapps="http://metro.mahapps.com/winfx/xaml/controls"
mc:Ignorable="d"
Title="Window1" Height="300" Width="300">
<StackPanel DataContext="{Binding ElementName=this}">
<Label Content="Textbox1" />
<TextBox Text="{Binding MyString}" mahapps:TextBoxHelper.ClearTextButton="True" />
<Label Content="Textbox2" />
<TextBox Text="{Binding MyString}" mahapps:TextBoxHelper.ClearTextButton="True" />
<Label Content="Textbox3" />
<TextBox />
</StackPanel>
</Window>
Environment
- MahApps.Metro 1.6.0-alpha013 (nuget)
- Windows OS 10
- Visual Studio 2017
- .NET Framework 4.6.2
Issue Analytics
- State:
- Created 6 years ago
- Comments:7 (6 by maintainers)
Top Results From Across the Web
Release 1.6.0
#3046 Update TextBoxHelper.cs; #3045 Clicking on the "X" button added by TextBoxHelper.ClearTextButton does not clear the databinding target ...
Read more >Why is the ClearTextButton icon showing as a letter r ...
Metro and I defined a style for the ComboBox so that it shows a clear text button. <Style TargetType="ComboBox" x:Key="{x:Type ComboBox} ...
Read more >News
#3046 Update TextBoxHelper.cs; #3045 Clicking on the “X” button added by TextBoxHelper.ClearTextButton does not clear the databinding target ...
Read more >Data binding overview - WPF .NET
OneWay binding causes changes to the source property to automatically update the target property, but changes to the target property are not ......
Read more >Wpf numericupdown github. NET7 WPF Control Samples ...
In NumericUpDown, the displayed text won't be empty when initializing the NumericUpDown with Value equal to DefaultValue. Click NumericUpDown to get focus ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Looking at PR #3046, I think it makes sense. 👍
@programatix This is by WPF, cause the default of
UpdateSourceTrigger
for Text() is LostFocus, so if you change this toUpdateSourceTrigger=PropertyChanged
all should work as expected.https://msdn.microsoft.com/en-us/library/system.windows.data.binding.updatesourcetrigger(v=vs.110).aspx