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

The Archive Base Latest Questions

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

I’m trying to make a control template for a table where each column is

  • 0

I’m trying to make a control template for a table where each column is related to a drop-down list of possible values, and each row has it’s own unique set of ‘selected values’. It looks like this:

<DataTemplate x:Key="ColourCellDataTemplate">
    <local:ColourDictionary Key="{TemplateBinding Content}">
        <local:ColourDictionary.ContentTemplate>
            <DataTemplate>
                <TextBlock Style="{StaticResource EditableTextCell}" Text="{Binding ColourName}" />
            </DataTemplate>
        </local:ColourDictionary.ContentTemplate>
    </local:ColourDictionary>
</DataTemplate>

I have about 10 of these classes, each initialized with a different datatable and sort key, but all the underlying operations and events are the same.

Each of these classes has their own static cached DataView member, which is shared between all instances of that class:

public class ColourDictionary : DataTableDictionary
{
    private static DataView cachedView;

    public ColourDictionary(){ }

    protected override DataView createView()
    {
        if (CachedView == null)
        {
            CachedView = base.buildView(table:((App)App.Current).ApplicationData.Colours, 
                                        keyField:"ColorCode");
        }
        return CachedView;
    }
}

As you can see – when the base class goes to create the DataView for use by the dictionary, it uses a virtual method which allows the different inheriting classes to pass on their own view – but each class needs to keep track of their own static cache.

I was hoping that this caching was logic I could keep in the base class so that “CreateView()” would only need to return a new DataView and would only ever be called once, after which the base class would simply use it’s own cache for each inheriting class type.


Solution

Thank you so much for two very good and very valid ideas. I hope you both get more upvotes. I went with the latter solution because I’m a sucker for brevity. I then went a little further so that the implementing classes need only override a virtual property getter to satisfy the requirements:

public class CATCodeDictionary : DataTableDictionary<CATCodeDictionary>
{
    protected override DataTable table { get { return ((App)App.Current).ApplicationData.CATCodeList; } }
    protected override string indexKeyField { get { return "CatCode"; } }
    public CATCodeDictionary() { }
}
public class CCYDictionary : DataTableDictionary<CCYDictionary>
{
    protected override DataTable table { get { return ((App)App.Current).ApplicationData.CCYList; } }
    protected override string indexKeyField { get { return "CCY"; } }
    public CCYDictionary() { }
}
public class COBDictionary : DataTableDictionary<COBDictionary>
{
    protected override DataTable table { get { return ((App)App.Current).ApplicationData.COBList; } }
    protected override string indexKeyField { get { return "COB"; } }
    public COBDictionary() { }
}    
etc...

Base Class

public abstract class DataTableDictionary<T> : where T : DataTableDictionary<T>
{
    private static DataView _IndexedView = null;

    protected abstract DataTable table { get; }
    protected abstract string indexKeyField { get; }

    public DataTableDictionary()
    {
        if( _IndexedView == null)
        {
            _IndexedView = CreateIndexedView(table.Copy(), indexKeyField);
        }
    }

    private DataView CreateIndexedView(DataTable table, string indexKey)
    {   // Create a data view sorted by ID ( keyField ) to quickly find a row.
        DataView dataView = new DataView(table);
        dataView.Sort = indexKey;
        return dataView;
    }
  • 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:49:25+00:00Added an answer on May 31, 2026 at 1:49 pm

    You can use generics:

    public class DataTableDictionary<T> where T: DataTableDictionary<T>
    {
        private static DataView cachedView;  
    }
    
    public class ColourDictionary : DataTableDictionary<ColourDictionary>
    {
    }
    
    public class XyDictionary : DataTableDictionary<XyDictionary>
    {
    }
    

    Here each class has its own static member.

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

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I'm trying to create an if statement in PHP that prevents a single post

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.