Avalonia ListBox移除鼠标悬浮、选中样式

XML 复制代码
   <ListBox
       Name="MessagesItemsControl"
       Background="Transparent"
       BorderThickness="0"
       ItemsSource="{Binding Messages}"
       ScrollViewer.HorizontalScrollBarVisibility="Disabled"
       ScrollViewer.VerticalScrollBarVisibility="Auto"
       SelectedItem="{Binding CurrentMessage}">
       <ListBox.Styles>
           <Style Selector="ListBoxItem:selected /template/ ContentPresenter">
               <Setter Property="Background" Value="Transparent" />
           </Style>
           <Style Selector="ListBoxItem:not(:focus) /template/ ContentPresenter#PART_ContentPresenter">
               <Setter Property="Background" Value="Transparent" />
           </Style>
           <Style Selector="ListBoxItem:pointerover /template/ ContentPresenter#PART_ContentPresenter">
               <Setter Property="Background" Value="Transparent" />
           </Style>
           <Style Selector="ListBoxItem:pressed /template/ ContentPresenter#PART_ContentPresenter">
               <Setter Property="Background" Value="Transparent" />
           </Style>
       </ListBox.Styles>
       <ListBox.ItemsPanel>
           <ItemsPanelTemplate>
               <VirtualizingStackPanel />
           </ItemsPanelTemplate>
       </ListBox.ItemsPanel>
       <ListBox.ItemTemplate>
           <DataTemplate DataType="vm:ChatMessageViewModel">
               <chat:ChatMessageView Margin="2,0,6,0" />
           </DataTemplate>
       </ListBox.ItemTemplate>
   </ListBox>

操作滚动条

cs 复制代码
  //MessagesItemsControl.AttachedToVisualTree += (_, __) =>
  //{
  //    Avalonia.Threading.Dispatcher.UIThread.Post(() =>
  //    {
  //        var chatScrollViewer = MessagesItemsControl.FindDescendantOfType<ScrollViewer>();
  //        HookScrollEvents(chatScrollViewer);
  //    });
  //};

 //private void HookScrollEvents(ScrollViewer? ChatScrollViewer)
 //{
 //    if (ChatScrollViewer == null)
 //        return;

 //    //  ListBox  SelectedItem change
 //    MessagesItemsControl
 //        .GetObservable(ListBox.SelectedItemProperty)
 //        .Subscribe(new AnonymousObserver<object?>(_ =>
 //        {
 //            _scrollToEnd = true;
 //        }));

 //    // ScrollViewer.ExtentProperty
 //    ChatScrollViewer
 //        .GetObservable(ScrollViewer.ExtentProperty)
 //        .Subscribe(new AnonymousObserver<Size>(_ =>
 //        {
 //            double bottomThreshold = 50;
 //            double distanceToBottom = ChatScrollViewer.Extent.Height -
 //                                       (ChatScrollViewer.Offset.Y + ChatScrollViewer.Viewport.Height);

 //            bool isNearBottom = ChatScrollViewer.Extent.Height <= ChatScrollViewer.Viewport.Height
 //                                || distanceToBottom <= bottomThreshold;

 //            if (isNearBottom || _scrollToEnd)
 //            {
 //                ChatScrollViewer.ScrollToEnd();
 //                _scrollToEnd = false;
 //            }
 //        }));

 //    // windows change(Bounds)
 //    this.GetObservable(BoundsProperty)
 //        .Subscribe(new AnonymousObserver<Rect>(_ =>
 //        {
 //            ChatScrollViewer.ScrollToEnd();
 //        }));
 //}
相关推荐
YDS8292 分钟前
SpringCloud —— 配置管理
java·spring·spring cloud
乂爻yiyao3 分钟前
Java 的云原生困局与破局
java·开发语言·云原生
C182981825754 分钟前
traceId 传递-MQ
java
低保和光头哪个先来7 分钟前
CSS+JS实现单例老虎机切换图片动画
前端·javascript·css
小鸡脚来咯9 分钟前
java web后端开发流程
java·开发语言·git
北友舰长11 分钟前
基于Springboot+thymeleaf快递管理系统的设计与实现【Java毕业设计·安装调试·代码讲解】
java·spring boot·mysql·校园管理·快递·快递系统
我爱烤冷面12 分钟前
kotlin项目实现Java doc的方案:使用Dokka
java·开发语言·kotlin·dokka
xinxinhenmeihao12 分钟前
长效住宅静态IP有什么好处?是选择动态IP还是静态IP好?
服务器·网络·tcp/ip
jian1105813 分钟前
android java转kotlin,kotlin转java
android·java·kotlin
IT_陈寒15 分钟前
Vue3性能优化实战:这5个技巧让我的应用加载速度提升了40%
前端·人工智能·后端