How to evenly space items in a horizontal Silverlight Listbox

In Silverlight, I have a Vertical ListBox with a horizontal list box for each item. I want the items in the HorizontalListbox to be evenly spaced across the width of the parent (vertical) ListBox. How can i do this?

   <ListBox x:Name="MachineListBox" Background="Green">
        <ListBox.ItemTemplate>
            <DataTemplate>
            <ListBox ItemsSource="{Binding CoilList}" Background="Red" HorizontalAlignment="Stretch">
                    <ListBox.ItemsPanel>
                        <ItemsPanelTemplate>
                        <StackPanel 
                            HorizontalAlignment="Stretch"  />
                    </ItemsPanelTemplate                                >
                            </ListBox.ItemsPanel>

                    <ListBox.ItemTemplate >
                       <DataTemplate>
                                <TextBlock
                                    Text="{Binding Coil}"
                                     HorizontalAlignment="Stretch"/>
                        </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>
        </DataTemplate>
            </ListBox.ItemTemplate>
    </ListBox>

      

0


source to share


2 answers


I will allow myself to suggest that you use your own control over my own invention. It's called the ProportionalPanel, and it does exactly what you want it to do - space objects evenly. You can use it for ItemsPanel in inner ListBox instead of StackPanel. I also provide source code, so you can customize the logic in any way you want. A related article on my blog is here .



0


source


I think the proportional calibration operator will do what you are looking for. Haven't tried it but it sounds like an option. Width = " *" and Margin="2

*".



0


source







All Articles