I have a list of <Data>, which I use to bind to a VirtualGrid
Data:
-Value [InnerData]:
-- Name [string]
-- Description [string]
I use CellTemplateNeeded event handler to select a DataTemplate for the columns :
private void RadVirtualGrid_CellTemplateNeeded(object sender, CellTemplateEventArgs e)
{
e.DataTemplate = this.Resources["Template"] as DataTemplate;
}
<DataTemplate x:Key="Template">
<StackPanel>
<Label Content="{Binding Name}" />
<Label Content="{Binding Description}" />
</StackPanel>
</DataTemplate>
And then I use CellValueNeeded to set the Value:
private void RadVirtualGrid_CellValueNeeded(object sender, CellValueEventArgs e)
{
e.Value = viewModel.List[e.RowIndex].Value;
}
So, basically I want to be able to "bind" an object to the Value of the Column.
Then, I want to display multiple properties of the object in the DataTemplate.
It works fine with string data, for e.g.:
e.Value = viewModel.List[e.RowIndex].Value.Name
<Label Content="{Binding }" />
It doesn't work with objects:
e.Value = viewModel.List[e.RowIndex].Value
<Label Content="{Binding Name}" />
A workaround was to "bind" to a string which contains both properties, $"{name}--#--{description}", then use a converter to get the name and description and display it.
But, I want to be able to pass an object, as I might need to display multiple properties.
Is there a limitation here? Can you recommend a better way to do it?
Thanks
Hi Mihai,
Yes, this is how the VirtualGrid works at the moment, and using such objects is not supported. I wanted to ask why using such an appraoch instead of separate columns. This will break the, sorting filtering and editing is not how a grid is usually used. Have you considered using other controls for this? How many rows do you have in your actual project?
I am looking forward to your reply.