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 393395
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T16:15:11+00:00 2026-05-12T16:15:11+00:00

Im making a custom button called ShardButton which uses a Style to control its

  • 0

Im making a custom button called “ShardButton” which uses a Style to control its content as well as its event triggers:

<Style x:Key="ButtonStyle" TargetType="{x:Type obj:ShardButton}">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type obj:ShardButton}">
                <Grid>
                    <Path .../>
                    <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" 
                                      VerticalAlignment="{TemplateBinding VerticalContentAlignment}" 
                                      SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" 
                                      RecognizesAccessKey="True"/>
                </Grid>
                <ControlTemplate.Triggers>
                    <EventTrigger RoutedEvent="ButtonBase.Click">
                        !!!SOMETHING HERE!!!
                    </EventTrigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

Im using the above XAML in the main Window1.xaml file, and creating a xmlns to the “obj” namespace, so what I want to do is to call a custom event handling method on the ShardButton class, how do I do that in XAML?

I cant seem to find the right way to phrase it for a Google search…

Thanks for any help you can give me!

Mark

  • 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-12T16:15:11+00:00Added an answer on May 12, 2026 at 4:15 pm

    You can’t directly execute event handlers in EventTriggers, they were’nt created for this purpose.

    However, if every instance of your ShardButton must do the same thing on click, simply override the OnClick method in your ShardButton class and do whatever you have to do here.

    If you don’t desire this behavior but instead want to have a specific handler executed for each ShardButton instance that is using this specific style defined in Window1.xaml, add another setter:

    <Setter Property="Command" Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type obj:Window1}}, Path=MyCommand}" />
    

    Where MyCommand is an instance property of Window1 returning a custom implementation of ICommand that will invoke your handler. This line of code assumes that every button using this Style is somewhere in the visual tree of Window1, which should be probably the case (or the Style would be defined elsewhere).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 308k
  • Answers 308k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Well Hulk, since we haven't gotten any more info from… May 13, 2026 at 9:45 pm
  • Editorial Team
    Editorial Team added an answer What do you mean you would like to avoid "having… May 13, 2026 at 9:45 pm
  • Editorial Team
    Editorial Team added an answer Not really possible : there's no API for that (and… May 13, 2026 at 9:45 pm

Related Questions

For example, I have a custom control called SampleControl. To simplify things for this
I'm developing an application in Silverlight2 and trying to follow the Model-View-ViewModel pattern. I
I'm writing a custom file selection component. In my UI, first the user clicks
I am building a Web Application using asp.net (C#). I come from windows forms

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.