简体   繁体   English

DatatemplateSelector,Listbox stretch

[英]DatatemplateSelector, Listbox stretch

I'm using DatatemplateSelector in a ListBox. 我在ListBox中使用DatatemplateSelector。

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>

截图

  <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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在列表框模板中对齐TextBlock = Stretch? - How to align TextBlock = Stretch in a listbox template? 在ListBox的DataTemplate中设置Horizo​​ntalAligment =“Stretch”时出现问题 - Problem setting HorizontalAligment=“Stretch” in ListBox's DataTemplate 在分组列表框视图中拉伸标题宽度 - Stretch header width in grouped listbox view LongListSelector和DataTemplateSelector - LongListSelector and DataTemplateSelector WPF中的DataTemplateSelector - DataTemplateSelector in WPF Horizo​​ntalContentAlign =“ Stretch”并更改列表框Windows Phone 8中的突出显示背景颜色 - HorizontalContentAlign=“Stretch” and change highlight background color in listbox Windows Phone 8 当ListBox ItemTemplate中的网格分为两列时,子文本框不会拉伸 - Child textbox will not stretch when grid in ListBox ItemTemplate is split into two columns 如何在ListBox内拉伸网格列? - How can I stretch grid columns inside a ListBox? 如何获得ListBox ItemTemplate以在Windows 10通用版本中水平拉伸ListBox的整个宽度? - How to get a ListBox ItemTemplate to stretch horizontally the full width of the ListBox in Windows 10 universal? 引用父DataTemplateSelector的DataTemplateSelector中的DataTemplate? - DataTemplate within a DataTemplateSelector referencing the parent DataTemplateSelector?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM