【问题标题】:C# WPF ListBox ChatC# WPF 列表框聊天
【发布时间】:2015-05-12 21:03:18
【问题描述】:

我正在开发 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>

【问题讨论】:

  • 这里的问题是什么?能解释清楚点吗?
  • 如何做到最后添加的项目是触摸列表框的底部
  • 我试过 ,但它不起作用。
  • 它有效。你把它放在哪里了?为您的 ListBox 发布更新后的 XAML

标签: c# wpf listbox chat


【解决方案1】:

你需要更新ListBox的内部ItemsPanelTemplate...试试这个:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-04
    • 1970-01-01
    • 2019-08-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多