Take the 2-minute tour ×
Code Review Stack Exchange is a question and answer site for peer programmer code reviews. It's 100% free, no registration required.

So I want to put some text next to it's lable. (both of which are text blocks - which are faster than lables as I understand it) The best way i've found for doing this is a strack panel.

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

    <StackPanel  Grid.Column="1" Grid.Row="2" Grid.ColumnSpan="2" Orientation="Horizontal">
        <TextBlock Text="Start:" FontWeight="DemiBold" VerticalAlignment="Bottom" HorizontalAlignment="Left"/>
        <TextBlock  Text="12:00pm"  VerticalAlignment="Bottom" HorizontalAlignment="Left" Margin="5,0"/>
    </StackPanel>

Is this the cleanest, way to do this, oris there a better control. I was kind of thinkingabout may i should make a wrapper control around the stack panel - but then i just would end up with:

    <LabeledTextBlock Grid.Column="1" Grid.Row="2" Grid.ColumnSpan="2">
<LabledTextBlock.Label>
        <TextBlock Text="Start:" FontWeight="DemiBold" VerticalAlignment="Bottom" HorizontalAlignment="Left"/>
</LabledTextBlock.Label>
        <TextBlock  Text="12:00pm"  VerticalAlignment="Bottom" HorizontalAlignment="Left" Margin="5,0"/>
    </LabeledTextBlock >

I Guess I could refine it more:

<LabeledContent Grid.Column="1" Grid.Row="2" Grid.ColumnSpan="2" Label="Start" Content="12:00pm"/>

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

giving me:

share|improve this question
add comment

1 Answer 1

up vote 2 down vote accepted

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.