views:

86

answers:

1

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:

http://www.shrani.si/f/1Y/M6/4eniAdAw/margin.png

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>
+4  A: 

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).

Scott
Ah, good guess. I didn't think of it that way - I assumed a one-to-many StackPanel-to-CheckBoxes ratio, not that each CheckBox was in its own. I guess that begs the question of "why?" but that's not what is being asked here... :)
Wonko the Sane
thanx alot. I was changing the MinWidth prop, but it didnt help. Removing it did help as i want margin between text and not actual checkboxes. Before i do another question, maybe i can ask here ...I would like to get rid of setting width for buttons. What is the way to make buttons globally resize depending on their text in the entire application?Thats one question ... the second is if i have three buttons one next to eachother, how do i set all the same width (the width of the largest button). Hope i make sense...
no9
nevermind, i solved it using uniformgrid !
no9