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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:26:45+00:00 2026-05-31T13:26:45+00:00

I’m developing a RAM simulation in WPF. When a create the memory, I set

  • 0

I’m developing a RAM simulation in WPF. When a create the memory, I set the size (1024 k) and I can create partitions setting the size and position.

Here are the classes:

public class Memory
{
    public ObservableCollection<Partition> Partitions { get; set; }
    public ulong Size { get; set; }

    public Memory(ulong size)
    {
        this.Partitions = new ObservableCollection<Partition>();
        this.Size = size;
    }
}

public class Partition
{
    public int Id { get; set; }
    public ulong Size { get; set; }
    public ulong Position { get; set; }
}

public class MemoryService
{
    public Memory GetModel()
    {
        var model = new Memory2(1024);
        model.Partitions.Add(new Partition() { Id = 1, Size = 512, Position = 0 });
        model.Partitions.Add(new Partition() { Id = 2, Size = 256, Position = 512 });
        model.Partitions.Add(new Partition() { Id = 3, Size = 256, Position = 768 });

        return model;
    }
}

My problem is how can I show this model into an UI? I’m planning to create something like this:

enter image description here

When I add an new Partition, it should show at the left a Position, and the width of each rectangle of the partition must be proportional of the sizes (IE the memory size is 1024 and the partition 1 has 512, so this partition is the half of the memory size in the image).

At this moment, I haven’t created any UI, but I guess I will need to create a new control, where I draw in a canvas. I’m really not sure about this, can I take a little help about how can I start? I really have no idea creating new controls.

Thanks a lot!

  • 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-31T13:26:46+00:00Added an answer on May 31, 2026 at 1:26 pm

    WPF (specifically XAML) is made for this kind of stuff. An ItemsControl with a customized ItemTemplate can do this so elegantly, there’s absolutely no reason to create a custom control and draw it in code. To show you how simple it is, I’ve mocked up a simple prototype using mostly XAML.

    First, some preliminary changes to your memory model. To make the height calculation simpler, I’ve added a RelativeSize property to the Partition class. This is exactly what it sounds like, a double value that is the result of Partition.Size / Memory.Size. That’s the only model change I made.

    Now, the good stuff:

    <Window x:Class="DrawMemory.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:DrawMemory"
        Width="200"
        Height="600"
        Title="Draw Memory">
    <Window.Resources>
        <local:MultiplyConverter x:Key="MultiplyConverter"/>
    </Window.Resources>
    
    <Grid x:Name="Grid"
          Margin="5">
        <ItemsControl ItemsSource="{Binding Partitions}">
            <ItemsControl.ItemTemplate>
                <DataTemplate>
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition MaxWidth="80"/>
                            <ColumnDefinition/>
                        </Grid.ColumnDefinitions>
    
                        <TextBlock Text="{Binding Position, StringFormat={}{0}k}"
                                   Margin="5"/>
                        <Grid Grid.Column="1">
                            <Border BorderThickness="5"
                                    BorderBrush="Black">
                                <Border.Height>
                                    <MultiBinding Converter="{StaticResource MultiplyConverter}">
                                        <Binding ElementName="Grid" Path="ActualHeight"/>
                                        <Binding Path="RelativeSize"/>
                                    </MultiBinding>
                                </Border.Height>
                            </Border>
                            <TextBlock Text="{Binding Id}"
                                       VerticalAlignment="Center"
                                       HorizontalAlignment="Center"/>
                        </Grid>
                    </Grid>
                </DataTemplate>
            </ItemsControl.ItemTemplate>
        </ItemsControl>
    </Grid>
    

    I’ve created a simple window with a single ItemsControl. The items it uses are the partitions, obviously. For each partition, I create a Grid with two columns. In the first column, I write some text for the position in memory (I used StringFormat to append the “k”). In the second column, I have another Grid that is composed of a Border and the text from Id.

    The only logic here is in the height binding. What I’m basically saying here is, “bind the height of this border to the height of the parent grid multiplied by the partition’s relative size.” I created some code-behind for the multiply converter, but it’s dead-simple (and not production quality):

    public class MultiplyConverter : IMultiValueConverter
    {
        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            return (double)values[0] * (double)values[1];
        }
    
        public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
        {
            return null;
        }
    }
    

    Because of this binding, as the Window resizes, the border height will be kept in sync. In other words, this ItemsControl will always fit the available space. Here’s what it ends up looking like:

    Screenshot of Window

    Obviously, you have a lot of polishing to do. But this should give you a good idea of what XAML is capable of.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a jquery bug and I've been looking for hours now, I can't
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have a reasonable size flat file database of text documents mostly saved in
I'm trying to create an if statement in PHP that prevents a single post
That's pretty much it. I'm using Nokogiri to scrape a web page what has

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.