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

  • Home
  • SEARCH
  • 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 8409317
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T23:52:30+00:00 2026-06-09T23:52:30+00:00

I am creating a WPF application. I want a page to be displayed on

  • 0

I am creating a WPF application. I want a page to be displayed on each button click.

 <ItemsControl ItemsSource="{Binding Path=DashBoardApps}" VerticalAlignment="Bottom" HorizontalAlignment="Center" Name="Abc">
            <ItemsControl.ItemsPanel>
                <ItemsPanelTemplate>
                    <Controls:FishEyeControl />
                </ItemsPanelTemplate>
            </ItemsControl.ItemsPanel>
            <ItemsControl.ItemTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal">
                        <Button MouseDown="Button_MouseDown">
                            <Image  Source="{Binding Path=ApplicationImage}" Width="32" Height="32"/>
                        </Button>
                        <TextBlock x:Name="txtAppName" Text="{Binding Path=ApplicationName}" TextAlignment="Center" Visibility="Hidden" FontSize="7px" Foreground="#eff7ff" VerticalAlignment="Center"/>
                    </StackPanel>
                    <DataTemplate.Triggers>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter TargetName="txtAppName" Property="Visibility" Value="Visible" />
                        </Trigger>
                    </DataTemplate.Triggers>
                </DataTemplate>
            </ItemsControl.ItemTemplate>
        </ItemsControl>

There are 6 buttons in total.On the button click I want a page to be displayed.(different pages for different buttons).
In the code behind I’ve done something like this

private void Button_MouseDown(object sender, MouseButtonEventArgs e)
    {
        var s = sender as ItemsControl;
        if (s == Abc.Items.GetItemAt(1))//if it is the first button. Not sure if it is right
        {
           //Code to display page
        }

    }

I want to know which button generated the event. As in, if the first button was clicked then page1 has to be displayed. So I tried using GetItemAt() function to see if the first button was clicked(to display the first page). However it doesn’t work and I am not sure if this approach is correct.

P.S Simply stated I want to know which button generated the event-Can this be done using index. If so, how?
Kindly help

  • 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-06-09T23:52:32+00:00Added an answer on June 9, 2026 at 11:52 pm

    The actual Button is passed to the event handler in the sender argument:

    Button button = sender as Button;
    

    There is however a problem. Since Button handles the MouseDown event, you won’t get it. You would have to either add a handler for the PreviewMouseDown event, or better for the Button’s Click event.

    And just as a note: The ItemCollection.GetItemAt method uses a zero-based index.

    EDIT: Here is how to bind the Button’s Tag property to the ItemsControl’s AlternationIndex property and how to utilize that index in the Button’s Click handler:

    <ItemsControl ... AlternationCount="2147483647">
    ...
    <ItemsControl.ItemTemplate>
        <DataTemplate>
            <StackPanel Orientation="Horizontal">
                <Button Click="Button_Click"
                        Tag="{Binding RelativeSource={RelativeSource Mode=TemplatedParent},
                                      Path=(ItemsControl.AlternationIndex)}">
                ...
            </StackPanel>
            ...
        </DataTemplate>
    </ItemsControl.ItemTemplate>
    

    With the XAML namespace xmlns:sys="clr-namespace:System;assembly=mscorlib" you could alternatively write

    <ItemsControl AlternationCount="{x:Static sys:Int32.MaxValue}">
    

    The Click handler:

    private void Button_Click(object sender, RoutedEventArgs e)
    {
        Button button = sender as Button;
        int index = (int)button.Tag;
        // get page by zero-based index
        ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm creating a WPF MVVM application. I have a long process that I want
I'm creating some desktop application using WPF(C# .net). I want to create it as
I am creating a Notepad like application in WPF. I want to set the
I'm creating a logger application thing to learn WPF, and I want new messages
I am creating a wpf application where it is going to be installed on
I am creating a simple WPF Application with a Sql Connection. The problem is
In a WPF application I had a BackgroundWorker thread creating an object. Let's call
Hello I am creating a Windows application (WPF) that is going to be running
I'm using WPF for creating my application, I am calling a windows form using
I am creating a pretty standard business application in WPF. I need to use

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.