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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T07:47:57+00:00 2026-06-15T07:47:57+00:00

This is a followup on a question on RichTextBoxes in a grid . I’ve

  • 0

This is a followup on a question on RichTextBoxes in a grid. I’ve gotten pretty far but it must be converted to MVVM now. My typeconverter is not getting called so the problem is probably in my databinding. I use two datagrids to test setups quicker.

View gets a ViewModel that has the all the data.

<Window.Resources>
    <local:DifferenceToTextConverter  x:Key="DifferenceToTextConverter" />
    <DataTemplate x:Key="cellTemplate" DataType="{x:Type Label}">
        <Label Content="{Binding Converter={StaticResource ResourceKey=DifferenceToTextConverter}}" >
        </Label>
    </DataTemplate>
</Window.Resources>

        <DataGrid Name="TestGrid" 
                  ItemsSource="{Binding Source=DifferenceViewModel, Path=DifferenceData, Converter={StaticResource DifferenceToTextConverter}}" 
                  HeadersVisibility="Column"
                  ItemTemplate="{StaticResource cellTemplate}" >
        </DataGrid>
        </DataGrid>
        <DataGrid Name="OhterGrid" DataContext="{Binding ElementName=DifferenceViewModel, Path=DifferenceData}" HeadersVisibility="Column" >
            <DataGrid.ItemTemplate>
                <DataTemplate DataType="{x:Type Label}">
                    <Label Content="{Binding Converter={StaticResource ResourceKey=DifferenceToTextConverter}}" >
                    </Label>
                </DataTemplate>
            </DataGrid.ItemTemplate>
        </DataGrid>

    public DifferenceView(ViewModel.DifferenceViewModel differenceViewModel)
    {
        InitializeComponent();

        this.DifferenceViewModel = differenceViewModel;
    }

ViewModel, DataTable filled with objects of my custom class. I know this has data as the method to fill it get’s called. And my converter, which sits in the project root namespace

namespace ViewModel
{
    public class DifferenceViewModel
    {
        private DataTable differenceData;

        /// <summary>
        /// Differences between properties.
        /// </summary>
        public DataTable DifferenceData
        {
            get
            {
                return this.differenceData;
            }
            private set
            {
                this.differenceData = value;
            }
        }
    }
}

class DifferenceToTextConverter : System.Windows.Data.IValueConverter
{
    public object Convert(object value, Type sourceType, object parameter, System.Globalization.CultureInfo culture)
    {
        TextBlock cell = new TextBlock();

        // Convert custom data to text representation.

        return cell;
    }
}

Constraints:

  1. Use MVVM
  2. Style in xaml when possible.
  3. Text with style applied to individual letters.
  4. Unknown number of columns and rows.
  5. Custom typeconverter needs to construct the entire cell text.
  • 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-15T07:47:58+00:00Added an answer on June 15, 2026 at 7:47 am

    The problem is your binding, you’re not setting the DataContext correctly, no data is loaded and therefore your converter isn’t being called.

    Make 2 changes:
    First, set your view’s DataContext to the DifferenceViewModel:

    public DifferenceView(ViewModel.DifferenceViewModel differenceViewModel)
    {       
       this.DataContext = differenceViewModel;
       InitializeComponent();
    }
    

    Then, change your binding:
    Instead of this:

    ItemsSource="{Binding Source=DifferenceViewModel, Path=DifferenceData, Converter={StaticResource DifferenceToTextConverter}}" 
    

    Change it to this:

    ItemsSource="{Binding DifferenceData, Converter={StaticResource DifferenceToTextConverter}}" 
    

    Which basically means:

    ItemsSource="{Binding Path=DifferenceData, Converter={StaticResource DifferenceToTextConverter}}" 
    

    Since your DataContext is the DifferenceViewModel, it’ll directly go to the DifferenceData property. You can now put a breakpoint in your converter.

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

Sidebar

Related Questions

This is a followup to my last question . I now have a byte[]
This is a followup question to: SQL Query with ORDER BY But I think
This is a followup question to my other widget-related question . I'd like to
This is a followup question to my other question : Run bat file in
This is a followup on the question: ASP.NET next/previous buttons to display single row
This is a followup to a question I posted yesterday. I thought everything was
As a followup to this question , is it possible to write a single
NOTE: This is a followup to my question here. I have a program that
This is a followup of a previous question I had. I got the very
This is a followup to an earlier question ( Help Refining RegEx ("\b\d{6}([ ]{1,15})\d{7}\b")

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.