WPF DataGrid: Resource per row?
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 开发者_JAVA百科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.
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.
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.
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?
What I did and solved my issue (no guarantees for whether this is the proper way), I am using a UserControl as the DataTemplate content, having the resource declared in the UserControl, then it gets initialized each time.
Another thing I havn't tried is setting x:Shared
attribute to false
, which I believe is supposed to help with the issue.
精彩评论