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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T03:28:16+00:00 2026-06-09T03:28:16+00:00

I am new to WPF and I want to create a WPF application with

  • 0

I am new to WPF and I want to create a WPF application with 5buttons. On the click of each button I want a content to be displayed on another panel. Right now I just want different images to be displayed on my right side panel on the button clicks.

Here’s my XAML code:

<Window x:Class="GridButton.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MyFirstApp" Height="350" Width="525" Loaded="Window_Loaded">
<Viewbox Stretch="Fill" StretchDirection="Both">
<DockPanel>
    <StackPanel DockPanel.Dock="left" Margin="5" Width="Auto" VerticalAlignment="Center" Height="Auto">
        <Button  Content="1" Name="button2" Click="button2_Click">
       </Button>
        <Button Content="2" Name="button1" Click="button1_Click_1">
</Button>
        <Button Content="3" Name="button3"  Click="button3_Click">
          </Button>
        <Button Content="4" Name="button4" Margin="5">
          </Button>
        <Button Content="5" Name="button5" Margin="5" Click="button5_Click_1">
          </Button>
    </StackPanel>
        <StackPanel DockPanel.Dock="Right">
            <Image Name="img1" Source="Blue Hills.jpg" Stretch="Uniform" Visibility="Hidden" ImageFailed="Image_ImageFailed" Height="257" />

        </StackPanel>

</DockPanel>

And my xaml.cs file contains code to display image:

private void button2_Click(object sender, RoutedEventArgs e)
{

    img1.Visibility = Visibility.Visible;
}

I could get only this far.

  • 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-09T03:28:18+00:00Added an answer on June 9, 2026 at 3:28 am

    You can set the Source property of the Image control in code:

    private void buttonx_Click(object sender, RoutedEventArgs e) 
    {
        string path = ... // path to image file here
        img1.Source = new BitmapImage(new Uri(path));
    }
    

    You could easily reuse the same Click handler for all Buttons and check which one was pressed:

    private void Button_Click(object sender, RoutedEventArgs e) 
    {
        Button button = sender as Button;
        string path = null;
        if (button == button1)
        {
            path = ... // path to image file 1 here
        }
        else if ...
    
        if (path != null)
        {
            img1.Source = new BitmapImage(new Uri(path));
        }
    }
    

    If you want to remove the a child Panel (or other control) from a parent Panel and add another one, you would have to modify the Panel’s Children property:

    <StackPanel Name="parent">   
        <StackPanel Name="child" />   
    </StackPanel>  
    
    parent.Children.Remove(child);
    parent.Children.Add(...); // some other control here
    

    This approach would usually make sense if you wanted to create child panels dynamically. If you want to declare everything in XAML you may put all child panels in a Grid and change their visibility as you did already.

    However, you might also change the ZIndex attached property.

    <Grid>
        <StackPanel Name="child1">
        </StackPanel>
        <StackPanel Name="child2">
        </StackPanel>
        <StackPanel Name="child3">
        </StackPanel>
    </Grid>
    

    child3 is topmost by default, but now you can set ZIndex to some value > 0 to make another child topmost:

    private void Button_Click(object sender, RoutedEventArgs e) 
    {
        ...
        // reset ZIndex on previous topmost panel to 0 before
        Panel.SetZIndex(child1, 1);
    }
    

    Or completely omit the Button/Grid/Panel design and use a TabControl.

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

Sidebar

Related Questions

I'm fairly new to WPF, and I want to create an MVVM based application
When I create a new WPF application in Visual Studio 2012 the platform target
I'm new to using WPF. I have the following program I want to create:
I have a WPF application where I'm trying to create a diagnostics panel that's
I want to create aa localizable WPF Application. I've followed the instructions in the
Here is the reproduction of my problem: Create a WPF Application Add a new
I'm creating a logger application thing to learn WPF, and I want new messages
I want to create an application by WPF 4 , my application must support
I am using Caliburn Micro with WPF. I want to create an application with
being new to WPF this is a complex problem for me. What i want

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.