Listbox Conversation verhält sich etwas natürlicher

This commit is contained in:
2025-05-13 11:17:11 +02:00
parent 45e512d7e0
commit 69f0b7ef6e
3 changed files with 26 additions and 4 deletions

View File

@@ -294,6 +294,16 @@ namespace BeWo.Core
return null;
}
public static void ScrollToTop(ListBox listBox)
{
if (VisualTreeHelper.GetChildrenCount(listBox) > 0)
{
Border border = (Border)VisualTreeHelper.GetChild(listBox, 0);
ScrollViewer scrollViewer = (ScrollViewer)VisualTreeHelper.GetChild(border, 0);
scrollViewer.ScrollToTop();
}
}
public static void ScrollToBottom(ListBox listBox)
{
if (VisualTreeHelper.GetChildrenCount(listBox) > 0)

View File

@@ -122,7 +122,8 @@
ItemsSource="{Binding VMList}"
ScrollViewer.CanContentScroll="False"
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
SelectedItem="{Binding SelectedVM, Mode=TwoWay}">
SelectedItem="{Binding SelectedVM, Mode=TwoWay}"
SelectionChanged="listbox_conversations_SelectionChanged">
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
@@ -221,7 +222,10 @@
Content="Senden"
Visibility="Visible" />
</Grid>
<Grid Grid.Column="1" Grid.RowSpan="2" Margin="4">
<Grid
Grid.RowSpan="2"
Grid.Column="1"
Margin="4">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="0" />
<ColumnDefinition Width="*" />

View File

@@ -31,7 +31,7 @@ namespace BeWo.View.Detail.AI
{
InitializeComponent();
((INotifyCollectionChanged)listbox_messages.Items).CollectionChanged += listbox_conversations_SelectionChanged;
((INotifyCollectionChanged)listbox_messages.Items).CollectionChanged += listbox_messages_SelectionChanged;
popup_settings.Closed += (s, e) => ViewModel.UpdateConfig();
@@ -62,7 +62,15 @@ namespace BeWo.View.Detail.AI
ViewModel.ReloadConversationsCommand.Execute(null);
}
private void listbox_conversations_SelectionChanged(object sender, NotifyCollectionChangedEventArgs e)
private void listbox_conversations_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (ViewModel.IsNewConversationVisible)
BeWoWpfUtils.ScrollToTop(listbox_conversations);
else
listbox_conversations.ScrollIntoView(listbox_conversations.SelectedItem);
}
private void listbox_messages_SelectionChanged(object sender, NotifyCollectionChangedEventArgs e)
{
BeWoWpfUtils.ScrollToBottom(listbox_messages);
}