开发者

WPF: Spacing between elements in stackpanel

开发者 https://www.devze.com 2023-01-07 17:14 出处:网络
I have a stackpanel with checkboxes. I cant seem to make same spacing between checkboxes with margin property

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:

WPF: Spacing between elements in stackpanel

(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>
    <Ch开发者_运维问答eckBox 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).

0

精彩评论

暂无评论...
验证码 换一张
取 消