简体   繁体   中英

Space inside Wrap panel

I creating buttons from db list, that's my .xaml file

<Controls:MetroWindow
    <ItemsControl x:Name="itemsList" Height="500" Width="550" >
        <ItemsControl.ItemTemplate>
            <DataTemplate DataType="local:Hall">

                <ToggleButton x:Name="ToggleButton"
                    Click="ItemButtonClick"
                    Width="35"
                    Height="35"
                    HorizontalAlignment="Center"
                    VerticalAlignment="Center"
                    Margin="5">
                    <TextBlock TextWrapping="Wrap" TextAlignment="Center" Text="{Binding number}"/>
                </ToggleButton>
            </DataTemplate>
        </ItemsControl.ItemTemplate>
        <ItemsControl.ItemsPanel>
            <ItemsPanelTemplate>

            <WrapPanel Margin="50" VerticalAlignment="Center" HorizontalAlignment="Center">
            </WrapPanel>
        </ItemsPanelTemplate>
        </ItemsControl.ItemsPanel>
    </ItemsControl>
</Controls:MetroWindow>

Is it possible to achieve something like this below on the picture? I need space in this places between buttons

内部间距

Maybe you can use a solution like this . You can have different values for numbers and return them accordingly. In your case something like this should work:

Create a property in your class called eg Margin.

public Thickness Margin {
    get {
        int multiplier = 1;
        if (number == 2 || number == 8) multiplier = 2;

        return new Thickness(5, 5, 5 * multiplier, 5);
    }
}

In XAML:

Margin="{Binding Margin}"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM