lundi 30 mars 2015

WPF Checkbox align to top left with multiline content

I've got a WPF Treeview with HierachicalDatatemplates for the nodes. The Child nodes are containing checkboxes for selecting the children. So far so good.


The content of the childnode should be a checkbox with multiline content several Textboxes and according to the viewmodel some pics.


When I put the content inside the checkbox, the box is always displayed in the vertical center of the content. But I want the checkbox to be on the top left of the content.


Here is an example WPF code:



<Window x:Class="Spielwiese.MainWindow" xmlns="http://ift.tt/o66D3f" xmlns:x="http://ift.tt/mPTqtT" Title="MainWindow" Height="350" Width="525">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>

<!--THIS IS WHAT I LIKE TO USE-->
<CheckBox Grid.Column="0" Margin="5">
<StackPanel>
<TextBlock Text="Some text" />
<TextBlock Text="Some more text" />
<TextBlock Text="a lot of more text" />
</StackPanel>
</CheckBox>


<!--THIS IS MY ACTUAL WORKAROUND-->
<Grid Grid.Column="1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="auto" />
<ColumnDefinition Width="auto" />
</Grid.ColumnDefinitions>
<CheckBox Grid.Column="0" Margin="0,3,5,0" />
<StackPanel Grid.Column="1">
<TextBlock Text="Some text" />
<TextBlock Text="Some more text" />
<TextBlock Text="a lot of more text" />
</StackPanel>
</Grid>
</Grid>


I would prefer the content to be inside the checkbock because of the selection of the nodes. I already tried to set verticalcontentalignment for the checkbock but it changed nothing.


Maybe somone has already solution for this little problem.





Aucun commentaire:

Enregistrer un commentaire