Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DatatemplateSelector, Listbox stretch

I'm using DatatemplateSelector in a ListBox.

My data doesn't strecth as needed(grey circle must be at right of listbox)

<ListBox HorizontalAlignment="Stretch" HorizontalContentAlignment="Stretch" SelectionChanged="ListBoxMessagesSelectionChanged" x:Name="listmy" >
    <ListBox.ItemTemplate>
      <DataTemplate>
        <local:SelectorForSearchFriend Content="{Binding}">
          <local:SelectorForSearchFriend.User>
            <DataTemplate>
              <Grid HorizontalAlignment="Stretch">
                <Grid.ColumnDefinitions>
                  <ColumnDefinition Width="3*"/>
                  <ColumnDefinition Width="15*"/>
                  <ColumnDefinition Width="Auto"/>
                </Grid.ColumnDefinitions>
                <Image Grid.Column="0" Width="100" Height="70"/>
                <TextBlock Name="Title" Text="{Binding Title}"/>
                <Ellipse HorizontalAlignment="Right" Fill="#FFB8B8B8" Height="20" Width="20" StrokeThickness="0" Visibility="{Binding IsOnline}" Grid.Column="2" Margin="0,-20,0,0"/>
              </Grid>
            </DataTemplate>
          </local:SelectorForSearchFriend.User>
      </DataTemplate>
    </ListBox.ItemTemplate>
    <ListBox.ItemContainerStyle>
      <Style TargetType="ListBoxItem">
        <Setter Property="HorizontalAlignment" Value="Stretch"/>
        <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
        <Setter Property="Margin" Value="0,4,0,4"/>
      </Style>
    </ListBox.ItemContainerStyle>
  </ListBox>

screenshot

like image 827
SevenDays Avatar asked May 05 '26 22:05

SevenDays


1 Answers

  <phone:PhoneApplicationPage.Resources>
    <Style TargetType="Grid">
        <Setter Property="HorizontalAlignment" Value="Stretch"/>
    </Style>
    <Style TargetType="local:SelectorForSearchFriend">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="local:SelectorForSearchFriend">
                    <ContentPresenter ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}" Margin="{TemplateBinding Padding}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
        <Setter Property="HorizontalAlignment" Value="Stretch"/>
        <Setter Property="VerticalAlignment" Value="Stretch"/>
    </Style>
  </phone:PhoneApplicationPage.Resources>
like image 95
SevenDays Avatar answered May 08 '26 12:05

SevenDays



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!