WPF DataGrid: resource in row?

Is there a way to xamly set a StaticResource for each row in a DataGrid by accessing it from all columns?


UPDATE
My goal is to have 3 ComboBox columns, while the latter is only bound to the rows element.
For example, a DataGrid represents a list of items. I have Category-> Vendor-> Style-> Finish ComboBoxes, but this is for navigation only, in fact the Item class only has a “Finish” relationship. Therefore, if there were no StaticResource for each row, I could set the ItemsSource and IsSynchronizedWithCurrentItem details for the ComboBox, and this will work automatically.

Many thanks.

+3
source share
4 answers

What I did and solved my problem (there is no guarantee of how correct this is), I use UserControl as the content of the DataTemplate, having the resource declared in UserControl, then it gets initialized every time.

Another thing I haven't tried is setting x:Sharedan attribute false, which I suppose should help with the problem.

0
source

Technically, I think you could, because the line is in the visual tree. But what are you trying to achieve? Probably the best way.

+1
source

, ?

, staticResource, (. ObjectDataProvider), DataGrid ItemSource XAML.

0

You can set it at the DataGrid level as follows:

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 suggest that you can set it at line level if you define a line pattern?

0
source

Source: https://habr.com/ru/post/1742225/


All Articles