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
300
UnboundField with dynamically UI Properties stored in an bind Object
posted

Hi there,

I’m facing a problem when I want to use the XamDataGrid and bind to an object, instead of a primitive value.

In my object I want to store the actual Value and some UI information like FontWeight, Forground, Background or IsEditable and bind them to their opponents.

Right now I’m using a different approach, a global CellValuePresenter and extend this in my CodeBehind, because I need to add dynamically columns to my grid. So I create my own UnboundField and add the PropertyPath to new PropertyPath("Items[" + key + "].Value"), also add my extendet CellValuePresenter, LabelPresenter and an EditorStyle.

In my extended CellValuePresenter Style I do a BasedOn call and set the Setter-Bindings, like

new Binding("DataItem.Items[" + key + "].Background");

new Binding("DataItem.Items[" + key + "].FontWeight");

new Binding("DataItem.Items[" + key + "].Foreground");

 

But by using this approach I’m facing performance problems and I already read your Blogs about it. When I disable my UI Property, I can increase the performance to an acceptable level (By about 600 rows and 60 columns). I use Recycle for both GenerationMode and activated CelVirtualization and all the small and big tweaks  I could find.

And here comes my first question, now I have several CellValuePresenters, because I need per Column (key) a different but makes this the Grid slower? Because now it can’t reuse one single CellValuePresenter and creates and save multiple.

Because of this thought I tried to use an object and bind it directly to my UnbondField, without PropertyPath. And define my UI Property in my base CellValuePresenter and embedded it in my Grid Ressources.

unboundField.Binding = new Binding("Items[" + key + "]");

 

<Setter Property="Background" Value="{Binding RelativeSource={RelativeSource Self}, Path=Value.Background, UpdateSourceTrigger=PropertyChanged}" />

And see, the Grid gained a decent performance boost.

But now I’m facing another problem. First the Grid shows my object-Type, what it in general fine, because I declared nowhere my “DisplayMemberPath” alike Property. And for this reason, when I edit the displayed underline XamTextEditor-Value, I kill my CellValuePresenter data object. Because the Editors shows the Property Content or Value of the CellValuePresenter as I guess.

I tried to extend the EditorStyle that it will use his ancestor Item and display the objects Value-Property but I couldn’t find the correct way. It shows the value on Start correct but if I change it, it kill the object again, in the CellValuePresenter.

binding = new Binding("Value.Value");

binding.RelativeSource = new RelativeSource(RelativeSourceMode.FindAncestor, new CellValuePresenter().GetType(), 1);

style.Setters.Add(new Setter(XamTextEditor.TextProperty, binding));

// or

style.Setters.Add(new Setter(XamTextEditor.ValueProperty, binding));

  

So here are my big questions.

First, is my thought of the different CellValuePresenter and the performance lost correct?

Second, what would be the most performances way of dealing with this kind of situation?

Third, is it even possible to bind correct to an object or did I miss some step?

 

Best regards

Andreas