Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clear TextBox Button doesn't seem to be fully working #1764

Closed
CobyBorel opened this issue Jan 20, 2015 · 6 comments
Closed

Clear TextBox Button doesn't seem to be fully working #1764

CobyBorel opened this issue Jan 20, 2015 · 6 comments
Labels
Milestone

Comments

@CobyBorel
Copy link

In the Demo App, TextExamples.xaml line 41, the 3rd textbox

Changed to this:

When running the app I get this behaviour.
Change tab to "text"
Enter "asdf" into the 3rd textbox
ClearTextButton appears
Click ClearTextButton and nothing happens
Tab to another tab "dates" and tab back "text"
Click ClearTextButton and text clears
enter text "asdf" into the 3rd textbox
ClearTextButton appears
Click ClearTextButton and text clears
Tab to another tab "dates" and tab back "text"
enter text into the 3rd textbox "asdf"
ClearTextButton appears
Click ClearTextButton and nothing happens

I'm thinking something is out of synce or not being updated.

I'm experiencing the same thing in my app as well when bound to an object.

Thanks for any help or advise.

@punker76
Copy link
Member

punker76 commented Feb 5, 2015

@CobyBorel which version you are using? i can't reproduce this with the latest github source.

@CobyBorel
Copy link
Author

@punker76
I downloaded the MahApps.Metro-master.zip on 12/23/2014
TextExamples.xaml line 41-43, the 3rd textbox
remove
line 42: Controls:TextBoxHelper.ButtonCommand="{Binding TextBoxButtonCmd, Mode=OneWay}"
line 43: Text=""

@thoemmi
Copy link
Collaborator

thoemmi commented Feb 12, 2015

I was able to reproduce this issue. The problem is, that Controls:TextBoxHelper.ClearTextButton="true" is set via the style. I guess the value is applied after the TextBox is loaded, so TextBoxLoaded will never be called. If I change the code in TextBoxHelper.ButtonCommandOrClearTextChanged to this (note the if (textbox.IsLoaded)...) it works:

private static void ButtonCommandOrClearTextChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
    var textbox = d as TextBox;
    if (textbox != null)
    {
        // only one loaded event
        textbox.Loaded -= TextBoxLoaded;
        textbox.Loaded += TextBoxLoaded;
        if (textbox.IsLoaded) {
            TextBoxLoaded(textbox, new RoutedEventArgs());
        }
    }
    //...

@punker76
Copy link
Member

@thoemmi seems like we should do this always and for the password and combo box too

@thoemmi
Copy link
Collaborator

thoemmi commented Feb 12, 2015

That's what I think too. Should I create a PR?

@punker76
Copy link
Member

@thoemmi jepp 👍

thoemmi added a commit to thoemmi/MahApps.Metro that referenced this issue Feb 12, 2015
@punker76 punker76 added the Bug label Feb 12, 2015
punker76 added a commit that referenced this issue Feb 12, 2015
Subscribe to clear button even if control is already loaded. Fixes #1764
@punker76 punker76 added this to the 1.1.0 milestone Feb 13, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

3 participants