2017-09-08 32 views
0

內UWP ItemsStackPanel拉伸的Horizo​​ntalAlignment我有一個ListView至極始終保持它的最後一項聚焦:一個ListView

<ListView x:Name="invertedListView_lstv" Grid.Row="0" IncrementalLoadingTrigger="Edge" VerticalAlignment="Stretch" Padding="0, 10, 0, 0" SelectionChanged="invertedListView_lstv_SelectionChanged" Margin="0, 0, 0, 10" HorizontalContentAlignment="Stretch"> 
     <ListView.ItemsPanel> 
      <ItemsPanelTemplate> 
       <ItemsStackPanel VerticalAlignment="Bottom" ItemsUpdatingScrollMode="KeepLastItemInView" Grid.ColumnSpan="1"/> 
      </ItemsPanelTemplate> 
     </ListView.ItemsPanel> 
</ListView> 

如果我元素加入到這個名單都顯示在左側。如果我將深綠色的Horizo​​ntalAlignment設置爲Right,它們也會出現在左側。

if (Chat.userAccountId.Equals(msg.fromUser)) 
{ 
    invertedListView_lstv.Items.Insert(0, new SpeechBubbleDownControl() { Text = msg.message, Date = msg.date.ToLocalTime(), HorizontalAlignment = HorizontalAlignment.Right}); 
} 
else 
{ 
    invertedListView_lstv.Items.Insert(0, new SpeechBubbleTopControl() { Text = msg.message, Date = msg.date.ToLocalTime() }); 
} 

Example

有沒有辦法來解決這個問題,在不犧牲ItemsStackPanel的KeepLastItemInView?

回答

2

嘗試設置HorizontalContentAlignmentStretchListView.ItemContainerStyle。如下所示。

<ListView.ItemContainerStyle> 
    <Style TargetType="ListViewItem"> 
     <Setter Property="HorizontalContentAlignment" Value="Stretch" /> 
    </Style> 
</ListView.ItemContainerStyle> 

This答案更多信息