Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7594961
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T21:33:06+00:00 2026-05-30T21:33:06+00:00

I have a style for a WPF text box which looks some thing like

  • 0

I have a style for a WPF text box which looks some thing like this. The template has a button on whose button clicked event i need the text to be set to empty. Can someone tell what am i missing. Or how can I call a method inside the custom SearchTextBox say ( OnButtonClikced) custom method

    <Style TargetType="{x:Type DevExGrdDemo:SearchTextBox}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type DevExGrdDemo:SearchTextBox}">
                    <Border x:Name="Border"
                            Background="{TemplateBinding Background}"
                            BorderBrush="{TemplateBinding BorderBrush}"
                            BorderThickness="{TemplateBinding BorderThickness}">
                        <Grid x:Name="LayoutGrid">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*" />
                                <ColumnDefinition Width="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=ActualHeight}" />
                            </Grid.ColumnDefinitions>
                            <ScrollViewer x:Name="PART_ContentHost"
                                          Grid.Column="0"
                                          Margin="2" />
                            <Label x:Name="LabelText"
                                   Grid.Column="0"
                                   Margin="2"
                                   Content="Search"
                                   FontStyle="Italic"
                                   Padding="2,0,0,0" />
                            <Button x:Name="SearchBoxButton"
                                    Grid.Column="1"                                                                             
                                    Style="{DynamicResource SearchButton}" >
                                <i:Interaction.Triggers>
                                    <i:EventTrigger EventName="Click" >
                                        <"A method residing in the SearchTextBox called on button click">
                                    </i:EventTrigger>
                                </i:Interaction.Triggers>
                            </Button>
                        </Grid>
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="HasText" Value="True">
                            <Setter TargetName="LabelText" Property="Visibility" Value="Hidden" />
                            <Setter TargetName="SearchBoxButton" Property="Style" Value="{StaticResource CancelSearchButton}" />
                        </Trigger>
                        <Trigger Property="IsKeyboardFocusWithin" Value="True">
                            <Setter TargetName="LabelText" Property="Visibility" Value="Hidden" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T21:33:07+00:00Added an answer on May 30, 2026 at 9:33 pm

    use an event trigger on the style (not on the ControlTemplate)

    http://msdn.microsoft.com/en-us/library/system.windows.eventtrigger.aspx

    You can’t put setters in an EventTrigger 🙁

    However, you can use a storyboard 🙂

    <Style>
      <Style.Triggers>
        <EventTrigger RoutedEvent="Button.Click">
          <BeginStoryboard>
            <Storyboard>
              <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Text">
                <DiscreteObjectKeyFrame Value="" />
              </ObjectAnimationUsingKeyFrames>
            </Storyboard>
          </BeginStoryboard>        
        </EventTrigger>
      </Style.Triggers>
    </Style>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a template like this, <Style x:Key=WaterMarkTextBoxStyle BasedOn={StaticResource {x:Type TextBox}} TargetType={x:Type TextBox}> <Setter
I'd like to create a custom validator template for my WPF app. I have
I have been having this issue with blurry text in WPF. I know that
I have seen this post: WPF ComboBox: background color when disabled and some others...
I have some what complex UI requirement, need help in understanding type of control/style/template
I'm trying to style Comboboxes in WPF so that they are white, and have
I'm using GNAT Programming Studio to update some ada files. I have a style
I am using Buttons in Wpf C# application. I have declared a style for
I am currently working on a WPF application where I would like to have
Is there a reason why the text content of a WPF button is appearing

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.