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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T08:31:12+00:00 2026-06-01T08:31:12+00:00

I’ve got an ItemsControl bound to a collection of extremely basic ViewModels, that each

  • 0

I’ve got an ItemsControl bound to a collection of extremely basic ViewModels, that each have a row\col Postion property. I’m also using Caliburn.Micro MVVM Framework, it automatically uses the matching View (Which is just a simple rectangle, with a Fill=”Transparent”) I’m filling the Grid up at the start with these, so I can add ContextMenus to them, and know what cell has been clicked etc.

The ItemsPanelTemplate is a Grid, and the ItemContainerStyle binds the Grid.Row\Column to the Position.X\Y property.

This screen is an Screen Editor for making emulations of an old 80×25 text mode system, that originally used a custom raster font to draw some simple graphics. Original system could handle 8 of those screens. I’m using rectangles and vector drawings for flexibility, as well as expand the screen size to any size.

First idea, was to simply for(i){for(j){Add}} loop through the grid, and add a new BlankVM to every cell.

It works, but as it has to do it 2000 time, it’s very slow. The binding etc is fast, but it adds up over that many. Since the potential screen size can be as large as needed, it’s
going to choke. Right now its about 40+ seconds.

I’m not that great a programmer (yet!) so I’m at a loss.

Can I replace the for loop with something more efficient?

Since the BlankCells are all the same except for a Position(row, column), can I take advantage of that?

Maybe I don’t even need to be adding all these to the grid, if there is a simpler way to be able to use a contextmenus and know what cell I’m clicking on…

here’s the code:

public class BlankCellViewModel : PropertyChangedBase, IEditorCell
{
    public GridPosition Position { get; set; }

    public BlankCellViewModel(GridPosition position) {
        Position = position;
    }
}

And the View

<UserControl x:Class="EditorCells.BlankCellView"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
      <Rectangle>
        <Rectangle.ContextMenu>
          <ContextMenu>
            <MenuItem Header="New Track Segment Here" />
          </ContextMenu>
        </Rectangle.ContextMenu>
        <Rectangle.Style>
          <Style>
            <Setter Property="Rectangle.Fill"
                    Value="Transparent" />
            <Style.Triggers>
              <Trigger Property="Rectangle.IsMouseOver"
                       Value="True">
                <Setter Property="Rectangle.Fill"
                        Value="White" />
              </Trigger>
            </Style.Triggers>
          </Style>
        </Rectangle.Style>
      </Rectangle>
</UserControl>

From the containing Viewmodel, the loop in question

private void SetupEditorGrid()
    {
        EditorMap.Resize(MaxRow, MaxColumn);
        for (int i = 0; i < MaxRow; i++)
        {
            for (int j = 0; j < MaxColumn; j++)
            {
                AddCell(new BlankCellViewModel(new GridPosition(j, i)));
            }
        }
    }

and its view:

<UserControl x:Class="EditorView"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:ap="clr-namespace:Support.AttachedProperties;assembly=Systems"
         HorizontalAlignment="Center">
  <ItemsControl x:Name="EditorCells">
    <ItemsControl.ItemsPanel>
      <ItemsPanelTemplate>
        <Grid ShowGridLines="True"
              Background="Black"
              HorizontalAlignment="Center"
              VerticalAlignment="Center"
              ap:GridHelpers.RowCount="{Binding RowCount}"
              ap:GridHelpers.ColumnCount="{Binding ColumnCount}" >
          <Grid.Resources>
            <Style TargetType="{x:Type ColumnDefinition}">
              <Setter Property="Width"
                      Value="8" />
            </Style>
            <Style TargetType="{x:Type RowDefinition}">
              <Setter Property="Height"
                      Value="16" />
            </Style>
          </Grid.Resources>
        </Grid>
      </ItemsPanelTemplate>
    </ItemsControl.ItemsPanel>
    <ItemsControl.ItemContainerStyle>
      <Style>
        <Setter Property="Grid.Row"
                Value="{Binding Position.Row}" />
        <Setter Property="Grid.Column"
                Value="{Binding Position.Column}" />
         </Style>
    </ItemsControl.ItemContainerStyle>
  </ItemsControl>
</UserControl>
  • 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-01T08:31:13+00:00Added an answer on June 1, 2026 at 8:31 am

    Messed with thise some more.

    Since the grid cells are a known, fixed sized, used MouseMove event handler to calc the cell the mouse is over, and used a contextmenu on the grid itself.

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

Sidebar

Related Questions

I've got a string that has curly quotes in it. I'd like to replace
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have just tried to save a simple *.rtf file with some websites and
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
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
this is what i have right now Drawing an RSS feed into the php,

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.