question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Clicking on the "X" button added by TextBoxHelper.ClearTextButton does not clear the databinding target

See original GitHub issue

What steps will reproduce this issue?

  1. Click on Textbox1
  2. Enter some string, eg “123”
  3. Press TAB or click on other textboxes
  4. The string, “123” will be shown in Textbox2 (due to data binding)
  5. Click the “X” button on Textbox1
  6. The string on Textbox2 is not cleared

I noted that for the “X” button to clear the databinding target,

  1. The textbox where the “X” is going to be clicked on must be the active control (focused) or
  2. 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:closed
  • Created 6 years ago
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
thoemmicommented, Sep 9, 2017

Looking at PR #3046, I think it makes sense. 👍

1reaction
punker76commented, Sep 8, 2017

@programatix This is by WPF, cause the default of UpdateSourceTrigger for Text() is LostFocus, so if you change this to UpdateSourceTrigger=PropertyChanged all should work as expected.

<Label Content="Textbox1" />
<TextBox Controls:TextBoxHelper.ClearTextButton="True" Text="{Binding MyString, UpdateSourceTrigger=PropertyChanged}" />
<Label Content="Textbox2" />
<TextBox Controls:TextBoxHelper.ClearTextButton="True" Text="{Binding MyString, UpdateSourceTrigger=PropertyChanged}" />

One of the UpdateSourceTrigger values. The default is Default, which returns the default UpdateSourceTrigger value of the target dependency property. However, the default value for most dependency properties is PropertyChanged, while the Text property has a default value of LostFocus.

https://msdn.microsoft.com/en-us/library/system.windows.data.binding.updatesourcetrigger(v=vs.110).aspx

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found