views:

206

answers:

3

Is there a way to xamly set a StaticResource per row in a DataGrid accessing it from all the columns?


UPDATE
My aim is to have 3 ComboBox columns, while only the last one is actually bound to the rows item.
For instance, the DataGrid represents a list of Items. I have Category->Vendor->Style->Finish ComboBoxes, but those are only for navigation assistance, in fact, the Item class has only a 'Finish' relationship. So if there coulda been a StaticResource per row, I could set the ItemsSource & IsSynchronizedWithCurrentItem props of the ComboBox and this would work automatically.

Thanks a lot.

A: 

Can you elaborate a little bit more on what you are trying to achieve ?

I'd think it is simpler to have one staticResource which represents a Collection (See ObjectDataProvider type) and then bind the DataGrid's ItemSource property to it in XAML.

Gishu
I want to treat each row with its custom DataSource, take a look at what I did, it's on Josh's response.
Shimmy
But it would still be a great idea to have a resource for each row, because now I have all the cascading comboboxes in one column, if i would be able to have a resource per row, i could separate them between columns.Waiting to hear forward.
Shimmy
@Shimmy : it looks like you're using the wrong control here for the job. Are you looking for a series of comboboxes where the choice in one filters the options for the next combobox in sequence ?
Gishu
I have a DataGrid that shows 'Product' entities.I included these cols: Vendor, Style, Finish; while the chain works this way: Product.Finish.Style.Vendor.So I want to make in each of these columns a combobox that cascades according to the previous selected value in the prev column.
Shimmy
@Shimmy - So if I design the Product class to expose Properties called Finish, Style and Vendor. Bind each column of the datagrid to the appropriate property. The properties themselves lookup the deciding sibling property and return the right list for the dropdown in the combobox e.g. Style would see lookup the value of this.Finish in an internal hashtable to get the list of allowed choices for the Style value. Would that work for you ?
Gishu
Please take a look at: http://stackoverflow.com/questions/3203416/accessing-control-between-datagridcells-dynamic-cascading-comboboxes
Shimmy
+1  A: 

Technically, I guess you could because the row is in the visual tree. But what are you trying to achieve? There's probably a better way.

Josh Einstein
I wanted to do 2 cascading ComboBoxes.I put them both on 1 DataGridTemplateColumn setting the CollectionViewSource in the DataTemplate.Resources.
Shimmy
But it would still be a great idea to have a resource for each row, because now I have all the cascading comboboxes in one column, if i would be able to have a resource per row, i could separate them between columns.Waiting to hear forward.
Shimmy
A: 

You can certainly set it at the DataGrid level like this:

xmlns:data="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data"

<data:DataGrid x:Name="..."  ItemsSource="{Binding ...}" >
    <data:DataGrid.Resources>
    </data:DataGrid.Resources>
</data:DataGrid>

I would presume you can set it at row level if you define a row template?

slugster
No, I want it to be set per row, not per the Control container. My aim is to set the CollectionViewSource within the row according to a value the user selected for this row.
Shimmy