Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
110
Xamdatagrid Create dynamic columns runtime
posted

Hello all.

I'm looking for an example of runtime column creation in xamdatagrid with mvvm pattern.

I have already found some examples such as the following:

https://es.infragistics.com/community/blogs/b/blagunas/posts/xamdatagrid-dynamically-create-and-data-bind-columns-with-an-editor-of-your-choice

I have a trouble with this one because this define only one kind of editor.

In my scenario, a column could have one of the following type:

- Decimal,

- String,

- String with a ienumerable<string> which represent the allowed values

Each of these "type" have to be edited with a different editor.

Decimal with a numericeditor, string with a texteditor and the last one with a xamcomboeditor.

For holding these different kind of values, I created diferent classes.

Interface IValueHolder

{

string Name {get; set;}

object Value {get; set;}

}

public abstract class AbstractValueHolder<T> : IValueHolder

{

Private T _value;

Public AbstractValueHolder()

{

}

Object IValueHolder.Value{set{.......}get{.....}}

}

public T Value{get{ return _value;}set{_value=value;}

}

Class TableValueHolder: AbstractValueHolder<string>

{

Public object Value {get; set;}

Public IEnumerable<string> AllowedValues{get; set;}

}

In my scenario, a valueHolder can be accessed by its name

Public class ItemViewModel

{

Public IValueHolder this[](string name)

{

Return ValueHolderDictionay[name];}

}

......

}

My trouble is how to databind the ItemSource of a XamComboEditor in the xaml?

I tryed something like that, I don't have the code source in front of me now, ItemSource ="{Binding DataItem[Name].AllowedValue}"

but there is no ValueHolder with the name "Name".

I tryed too, to define it in the code behind, but it does not work as expected.

I hope that my request is clear, and that someone could answer!