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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T04:13:43+00:00 2026-05-16T04:13:43+00:00

I have a question regarding how to best accomplish something in WPF MVVM. I

  • 0

I have a question regarding how to best accomplish something in WPF MVVM. I have in my ViewModel a series of integers. For the sake of example, lets call them:

public int Yellow
{
    get;set;
}
public int Red
{
    get;set;
}
public int Green
{
    get;set;
}

I also have some small images that are very simple: A Red circle, a Yellow circle, and a Green circle. The idea is to have an area on the view with a number of these images, based on the above properties. So if this instance of the view model has 3 Yellow, 2 Red, and 1 Green, I want 6 images in my ListBox, 3 of the yellow circle, 2 of the red, and 1 of the green. Right now, I have it working, but using some very clumsy code where I build the image list in the ViewModel using an ugly for-loop. Is there some more elegant way to accomplish this task in WPF? Ideally, I wouldn’t want to have to reference the image in the ViewModel at all…

  • 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-16T04:13:44+00:00Added an answer on May 16, 2026 at 4:13 am

    You could use an ImageBrush to tile a rectangle with an image, and bind the width of the rectangle to the number of copies of the image you want. Something like this:

    <StackPanel Orientation="Horizontal">
        <StackPanel.LayoutTransform>
            <ScaleTransform ScaleX="20" ScaleY="20"/>
        </StackPanel.LayoutTransform>
        <Rectangle Width="{Binding Yellow}" Height="1">
            <Rectangle.Fill>
                <ImageBrush
                    ImageSource="Yellow.png"
                    Viewport="0,0,1,1"
                    ViewportUnits="Absolute"
                    TileMode="Tile"/>
            </Rectangle.Fill>
        </Rectangle>
        <Rectangle Width="{Binding Red}" Height="1">
            <Rectangle.Fill>
                <ImageBrush
                    ImageSource="Red.png"
                    Viewport="0,0,1,1"
                    ViewportUnits="Absolute"
                    TileMode="Tile"/>
            </Rectangle.Fill>
        </Rectangle>
        <Rectangle Width="{Binding Green}" Height="1">
            <Rectangle.Fill>
                <ImageBrush
                    ImageSource="Green.png"
                    Viewport="0,0,1,1"
                    ViewportUnits="Absolute"
                    TileMode="Tile"/>
            </Rectangle.Fill>
        </Rectangle>
    </StackPanel>
    

    Update: As Ray pointed out in his comment, if you are just trying to draw circles then you will get better zoom behavior by using a DrawingBrush than by using an Image:

    <StackPanel Orientation="Horizontal">
        <StackPanel.LayoutTransform>
            <ScaleTransform ScaleX="20" ScaleY="20"/>
        </StackPanel.LayoutTransform>
        <StackPanel.Resources>
            <EllipseGeometry x:Key="Circle" RadiusX="1" RadiusY="1"/>
        </StackPanel.Resources>
        <Rectangle Width="{Binding Yellow}" Height="1">
            <Rectangle.Fill>
                <DrawingBrush ViewportUnits="Absolute" TileMode="Tile">
                    <DrawingBrush.Drawing>
                        <GeometryDrawing
                            Brush="Yellow"
                            Geometry="{StaticResource Circle}"/>
                    </DrawingBrush.Drawing>
                </DrawingBrush>
            </Rectangle.Fill>
        </Rectangle>
        <!-- etc. -->
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a question regarding best-practice when including headers. Obviously include guards protect us
I have a question about best practices regarding how one should approach storing complex
I have a question regarding .ajaxComplete(). Lets say I do this: // Register an
I am new to developing for android. I have a question regarding some best
I have a question regarding an ArrayList of Integers, or primitive types in general.
So I have a question regarding the best practice for a PHP page inserting
Hey, I have a question regarding code structure, and was wondering what the best
I have a question regarding best practices when adding targets to a UIButton on
I'm new to JavaScript, and have a simple (I presume) question regarding best practices
Hi, I'm new to both Prism and WPF, and I have a question regarding

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.