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

TextboxHelper.ClearTextButton does not work when is applied via Trigger #1283

Closed
erdmenchen opened this issue Apr 10, 2014 · 1 comment
Closed
Assignees
Labels
Milestone

Comments

@erdmenchen
Copy link

I am trying to achieve something similar to #788, but dont want to show any icon when no text is inserted.

What I've come up so far maybe exposes a bug with the TextboxHelper.ClearTextButton:

<TextBox>
<TextBox.Style>
    <Style TargetType="{x:Type TextBox}" BasedOn="{StaticResource MetroTextBox}">
          <Style.Triggers>
                <Trigger Property="metro:TextboxHelper.HasText" Value="True">
                       <Setter Property="metro:TextboxHelper.ClearTextButton" Value="True"/>
                </Trigger>
          </Style.Triggers>
    </Style>
</TextBox.Style>
</TextBox>

It works fine, the ClearTextButton is only visible, when the TextBox has Text.

But the problem is, that the ClearTextButton does not clear the TextBox any more...

When the TextboxHelper.ClearTextButton=True is set on the TextBox, then the Trigger wount work any more.

One or both of those behaviors are wrong to me...what is the solution?

@punker76 punker76 added this to the v0.14 milestone May 23, 2014
@punker76 punker76 self-assigned this May 23, 2014
punker76 added a commit that referenced this issue May 24, 2014
- add example for this issue: TextboxHelper.ClearTextButton does not
work when is applied via Trigger #1283
- remove inheritance to DependencyObject to avoid possible bugs with
attached properties
- change getter for HasText and add a setter
- fire HasText property on controls loaded event
- fix BindingExpression error for PasswordBox
- add example from @thoemmi for:  a search box with a magnifier on its
button, but as soon as text is entered, the button content should change
to an X.
@punker76
Copy link
Member

@erdmenchen here is a working example for you (also now included in the main demo)

<TextBox Margin="0, 10, 0, 0"
            Controls:TextboxHelper.ButtonCommand="{Binding TextBoxButtonCmd, Mode=OneWay}"
            Text="Clear button">
    <TextBox.Style>
        <Style TargetType="{x:Type TextBox}"
                BasedOn="{StaticResource MetroTextBox}">
            <Setter Property="Controls:TextboxHelper.ClearTextButton" Value="True"></Setter>
            <Style.Triggers>
                <Trigger Property="Controls:TextboxHelper.HasText"
                            Value="False">
                    <Setter Property="Controls:TextboxHelper.ClearTextButton"
                            Value="False" />
                    <Setter Property="Controls:TextboxHelper.Watermark"
                            Value="Now enter some text..." />
                </Trigger>
                <Trigger Property="Controls:TextboxHelper.HasText"
                            Value="True">
                    <Setter Property="Controls:TextboxHelper.ClearTextButton"
                            Value="True" />
                </Trigger>
            </Style.Triggers>
        </Style>
    </TextBox.Style>
</TextBox>

@punker76 punker76 mentioned this issue May 24, 2014
33 tasks
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

2 participants