HiveBrain v1.2.0
Get Started
← Back to all entries
patternMinor

Putting items next to each other

Submitted by: @import:stackexchange-codereview··
0
Viewed 0 times
eachnextitemsputtingother

Problem

I want to put some text next to its label (both of which are text blocks - which are faster than labels as I understand it). The best way I've found for doing this is a stack panel.

I have (repeated 3 times in a control) code like:


        
        
    


Is this the cleanest way to do this, or is there a better control? I was kind of thinking about making a wrapper control around the stack panel, but then I would just end up with:


        

        
    


I guess I could refine it more:



Simplicity at the cost of flexibility. Perhaps instead I should be doing it as a style?

Solution

My opinion is that for simple tasks like in your situation, you should not complicate your XAML. Wrapping a StackPanel around two TextBlock-elements is still pretty clean.

Extracting the code and wrapping it in your own control where you would set the Label and Content surely is an option. But if this only to be done once, I think you're overdoing it. Only when you have to place the same code there a lot of times, your XAML will be cleaner using your own control.

Context

StackExchange Code Review Q#8869, answer score: 3

Revisions (0)

No revisions yet.