Search code examples
wpfxamlstackpaneldockpanel

WPF: Element Justification


Is there a way to justify three or more elements in WPF along the window size, in such a way that it would look like this:

[button]        [button]        [button]        [button]
________________________________________________________

I tried searching for ways using dockpanel/stackpanel, but they only seem to use two elements (for attaching one to the left, and one to the right, for example.)


Solution

  • here is a sample using UniformGrid

        <UniformGrid Columns="4">
            <Button Content="1" />
            <Button Content="2" />
            <Button Content="3" />
            <Button Content="4" />
        </UniformGrid>
    

    if you do not want to fix the columns to 4 then fix the rows to 1 and all the buttons will be uniformly spaced

        <UniformGrid Rows="1">
            <Button Content="1" />
            <Button Content="2" />
            <Button Content="3" />
            <Button Content="4" />
            <Button Content="5" />
            <Button Content="6" />
        </UniformGrid>