Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to avoid RowDefinition duplication?

Tags:

c#

wpf

I have 15-20 rows, some of them are different but most of them are similar:

        <RowDefinition Height="Auto" />

And I want to avoid code duplication, because it's about 10 rows, which goes one by one. How can it be done?

It can be done in code without XAML, but I think it is wrong way to solve this problem.

like image 776
AKhimself Avatar asked Feb 12 '26 05:02

AKhimself


1 Answers

I don't think it's possible to somehow shorthand declaration of grid rows, especially when not all of them have the Height property set to "Auto". You could try using an attached dependency property as demonstrated here.

Please note that this example specifies the number of grid rows and you can see it sets the Height property of each row programmatically. You may have to decide what Height to assign to each row in a more complex way. Although this solution might prove to be more aesthetic in XAML, it may be more complicated to implement and you might have a hard time assigning the proper Height for each row. Personally it seems easier to just declare each row as Visual Studio will allow collapsing the tag and a nice, clear aspect.

I hope this helps!

like image 157
Florin Bombeanu Avatar answered Feb 16 '26 01:02

Florin Bombeanu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!