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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T07:27:31+00:00 2026-05-18T07:27:31+00:00

I currently have a class containing the following properties public class Chromosome { public

  • 0

I currently have a class containing the following properties

public class Chromosome
{
    public int Length
    {
        get;
        set;
    }

    public int Number
    {
        get;
        set;
    }

    public Chromosome(int _length, int _number)
    {
        Length = _length;
        Number = _number;
    }
}

I have a list box data binded to my view model. The items source is data binded to a Observable of Chromosome objects ChromosomeList.

<Grid>
        <ListBox Style="{StaticResource ListBoxStyle}"  
                 ItemsSource="{Binding Path=ChromosomeList}"
                 ItemTemplate="{StaticResource ChromosomeDataTemplate}">
        </ListBox>
    </Grid>

The ItemTemplate for the list box items is ChromosomeDataTemplate and is shown below.

<DataTemplate x:Key="ChromosomeDataTemplate">
    <Border>
        <Grid Height="10">
            <TextBlock VerticalAlignment="Bottom" 
                       Text="{Binding Number}">
            </TextBlock>
        </Grid>
    </Border>

In this case, I want the Height property of the grid to be data binded to the Length property of the chromosome. However, as the Length is extremely large, I need it to be a small percentage of the actual value. I could do this by:

  • Making a new property specific for the modified height

However, I feel that this does not follow the MVVM Pattern. Is there any way to modify the Length value when data binding it?

  • 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-18T07:27:31+00:00Added an answer on May 18, 2026 at 7:27 am

    Chromosome is your Model. Your XAML code resides in your View. The hypothetical “modified-length” value should reside in your ViewModel.

    You are correct in saying that making a new property for the modified height is not MVVM (and is a very bad idea generally, of course).

    For a better approach, you would normally put the modified-length property in the ViewModel. However your problem is now that your ViewModel has an ObservableCollection<Chromosome> and therefore cannot provide a simple modified-length property for each one of the Chromosome instances.

    Therefore, you have two choices:

    1. Implement a ValueConverter that translates the original Length to an appopriate Grid.Height. This could be either in your ViewModel or the View, but I think putting it in the ViewModel is not appropriate (since it will be used by a specific View only). This is the simplest approach.

    2. Wrap every Chromosome in its own ViewModel, e.g. ChromosomeViewModel. Your existing ViewModel would take a collection of Chromosomes and expose an ObservableCollection<ChromosomeViewModel>. You would then create a ChromosomeView bound to each ViewModel, which would basically be what you have now in your ChromosomeDataTemplate. Since the ChromosomeView will be bound to a ChromosomeViewModel, which in turn wraps a single Chromosome, you can now provide a “modified-length” property directly in your ChromosomeViewModel.

    If it’s just for this, I suggest going with the ValueConverter. However, keep the second approach in mind for more complex scenarios.

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

Sidebar

Related Questions

Given the following types public class SomeValue { public int Id { get; set;
I currently have the following code: public class Count { public static void countChar()
I currently have a class file with the following enumeration: using System; namespace Helper
I currently have a class where I need accomplish the equivalent of the following
Currently I have a class that looks like this: public class MyClass : IMyClass
I currently have service classes that look something like this public class UserService :
I have a little Java project where I've set the properties of the class
Suppose I have the following two data structures: std::vector<int> all_items; std::set<int> bad_items; The all_items
I have a the following controller containing one action with a single parameter: public
I have the following class in PHP5.3: class MyClass { public $a=1; public $hook;

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.