I have a stackpanel with checkboxes. I cant seem to make same spacing between checkboxes with margin property
Can some1 tell me what am i doing wrong?
The code below gives me this:
(source: shrani.si)
As you can see, the spacing between elements is not constant !
<StackPanel MinWidth="150" cal:Bind.Model="{Binding}" Orientation="Horizontal">
<StackPanel.Resources>
<Style TargetType="{x:Type CheckBox}">
<Setter Property="Margin" Value="0,0,20,0"/>
</Style>
</StackPanel.Resources>
<CheckBox IsChecked="{Binding IsShown}" Content="{Binding ModuleName, Converter={StaticResource localizeModuleAndFunctionConverter}}"
cal:Message.Attach="[Event Click] = [Action FilterShownModuleFunctions]" />
</StackPanel>
I'm guessing your problem is your MinWidth="150" property. I think you've got a total of 5 stackpanels right now. You have 4 stack panels each holding their own checkbox. Then I'm assuming you've got a 5th stack panel holding your 4 stack panels.
If this is true... then the problem is that each of your checkboxes are in a stack panel of 150 width (minimum) but your third stack panel is larger than 150 because the text is so long that it must be larger to contain the entire text (plus your margin of 20).
Remove the MinWidth="150" and I think you will get a margin of 20 between the text of each checkbox. (if you want the even spacing between the actual boxes of the checkboxes, then you should keep your minwidth but make it large enough that it is at least as wide as the checkbox containing the longest text).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With