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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:36:09+00:00 2026-05-28T01:36:09+00:00

I need to show multiple buttons, but each one must have a different background

  • 0

I need to show multiple buttons, but each one must have a different background than other buttons, I have been working on it, but I only got to display multiple buttons but with the same background.
Here is the XAML:

<Window x:Class="apple.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="370" Width="525">
    <Grid>
        <Image Source="C:\Users\Public\Pictures\Sample Pictures\Koala.jpg" Stretch="Fill"/>
        <DockPanel Name="dock">
            <UniformGrid Name="gridx" DockPanel.Dock="Top" Rows="3" Columns="3" Height="334"> 
            </UniformGrid>
        </DockPanel>
    </Grid>
</Window>

Also, here is the C# code:

namespace apple
{
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            masterGUI();
        }

    public void masterGUI()
    {
        ImageBrush ib = new ImageBrush();
        IconImage[] ico = null;
        Bitmap[] img = null;
        string[] list = null;
        string[] link = Directory.GetFiles(@"C:\ProgramData\Microsoft\Windows\Start Menu\Programs", "*.lnk", SearchOption.AllDirectories);
        list = new string[link.Length];
        ico = new Icon[link.Length];
        img = new Bitmap[link.Length];
        for (int n = 0; n < link.Length; n++)
        {
            System.Windows.Controls.Button newBtn = new Button();
            list[n] = System.IO.Path.GetFileNameWithoutExtension(link[n]);
            FileToImageIconConverter some = new FileToImageIconConverter(link[n]);
            ImageSource imgSource = some.Icon;
            ib.ImageSource = imgSource;
            newBtn.Background = ib;
            newBtn.Content = list[n];
            gridx.Children.Add(newBtn);
        }  
    }
}

}

Any idea? thank you.

  • 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-28T01:36:10+00:00Added an answer on May 28, 2026 at 1:36 am

    The ImageBrush needs to be created in the for-loop individually for each item. Otherwise you will end up with the same background for every item.

    Also you are approaching this the “wrong” way, in WPF you should use data binding and data templating for this sort of thing instead of imperative looping.

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

Sidebar

Related Questions

I have a <select multiple='multiple' and I need to show the selected value in
I am working on a piece of an application attempting to show multiple different
I need show a notication modal window.. But since its a fluid layout the
I have a page that uses multiple dialogs for different things. Some dialogs may
I am working on quiz application . For each question there are multiple answers
I have a windows form with multiple controls and OK and Cancel buttons. In
i have been trying the code using mutex but im unable to open my
me again... I need show 10 or 20 or 50 results number of results
I need to show the name of the currently selected file (in <input type=file>
I need to show the jQuery UI Datepicker plug in for Html.TextBox , how

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.