UWP ItemsStackPanel在ListView中拉伸Horizo​​ntalAlignment

时间:2017-09-08 14:43:47

标签: c# listview uwp

我有一个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?

1 个答案:

答案 0 :(得分:2)

尝试在getInt()中将resultset_method = data_result.getClass().getMethod("getInt", String.class); 设为HorizontalContentAlignment。如下所示。

Stretch

有关详细信息,请参阅This答案

相关问题