Silverlight: sets the width of items in ItemsControl for stretching

I have an ItemsControl element that fills from top to bottom, but I can not get its children to occupy the entire width of the ItemsControl element:

alt text

I basically need to stretch the green bits to fill the width of the control (as shown by the blue bits).

I tried things like setting the property HorizontalAlignmentof a template element to Stretch, and I even tried to bind its property Widthto the width of the ItemsControl, but it didn't work.

It should be direct, but this is something that I just can’t understand ...

Edit: here is an ItemTemplate (all this is an ItemTemplate, which itself contains an ItemsControl linked to a list of child objects):

<DataTemplate>
    <Border CornerRadius="5" Background="#ddd">
        <StackPanel>
            <TextBlock Text="{Binding Name}" FontSize="18" Foreground="#bbb"/>
            <ItemsControl ItemsSource="{Binding PlugIns}">
                <ItemsControl.ItemsPanel>
                    <ItemsPanelTemplate>
                        <toolkit:WrapPanel HorizontalAlignment="Stretch" />
                    </ItemsPanelTemplate>
                </ItemsControl.ItemsPanel>
                <ItemsControl.ItemTemplate>
                    <DataTemplate>
                        <StackPanel Margin="10,0,10,10" Tag="{Binding}" 
                                MouseEnter="StackPanel_MouseEnter">
                            <Border Child="{Binding Icon}" />
                            <TextBlock Text="{Binding Name}" />
                        </StackPanel>
                    </DataTemplate>
                </ItemsControl.ItemTemplate>
            </ItemsControl>
        </StackPanel>
    </Border>
</DataTemplate>
+3
2

, , , . , ItemsControl , , :)

<ItemsControl>
    <ItemsControl.Template>
        <ControlTemplate>
            <ScrollViewer Padding="{TemplateBinding Padding}">
                <ItemsPresenter />
            </ScrollViewer>
        </ControlTemplate>
    </ItemsControl.Template>
    ...
</ItemsControl>
+1

ListBoxItem HorizontalContentAlignment, Style ListBox ItemContainerStyle : -

 <ListBox ....>
  <ListBox.ItemContainerStyle>
    <Style TargetType="ListBoxItem">
      <Setter Property="HorizontalContentAlignment" Value="Stretch" />
    </Style>
  </ListBox.ItemContainerStyle>
+3

Source: https://habr.com/ru/post/1738018/


All Articles