我正在使用C#WPF聊天应用程序。我希望它看起来像Skype聊天,所以最后添加的项目正在触摸ListBox的底部。

屏幕截图:



<ListBox Name="ListBoxMain" Grid.Column="1" Grid.Row="1">
        <ListBox.ItemTemplate>
            <DataTemplate>
                <WrapPanel>
                    <TextBlock Text="{Binding User}" FontWeight="Bold" />
                    <TextBlock Text=": " FontWeight="Bold" />
                    <TextBlock Text="{Binding Text}" Width="225" TextWrapping="Wrap" HorizontalAlignment="Stretch" />
                </WrapPanel>
            </DataTemplate>
        </ListBox.ItemTemplate>
    </ListBox>

最佳答案

您需要更新ItemsPanelTemplate的内部ListBox ...尝试以下操作:

<ListBox Name="ListBoxMain" Grid.Column="1" Grid.Row="1">
    <ListBox.ItemTemplate>
        <DataTemplate>
            <WrapPanel>
                <TextBlock Text="{Binding User}" FontWeight="Bold" />
                <TextBlock Text=": " FontWeight="Bold" />
                <TextBlock Text="{Binding Text}" Width="225" TextWrapping="Wrap" HorizontalAlignment="Stretch" />
            </WrapPanel>
        </DataTemplate>
    </ListBox.ItemTemplate>
    <ListBox.ItemsPanel>
        <ItemsPanelTemplate>
            <StackPanel VerticalAlignment="Bottom"/>
        </ItemsPanelTemplate>
    </ListBox.ItemsPanel>
</ListBox>

关于c# - C#WPF ListBox聊天,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/30187416/

10-14 22:54