开发者

WPF DataGrid: Resource per row?

开发者 https://www.devze.com 2022-12-27 22:54 出处:网络
Is there a way to xamly set a StaticResource per row in a DataGrid accessing it from all the columns?

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号