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();
 //        }));
 //}
相关推荐
cuijiecheng20181 天前
Linux下inih库的使用
linux·运维·服务器
tao3556671 天前
【用AI学前端】准备工作
前端·人工智能
利刃大大1 天前
【Vue】自定义指令directives && 指令钩子 && IntersectionObserver
前端·javascript·vue.js
共享家95271 天前
搭建 AI 聊天机器人:”我的人生我做主“
前端·javascript·css·python·pycharm·html·状态模式
惊讶的猫1 天前
探究StringBuilder和StringBuffer的线程安全问题
java·开发语言
jmxwzy1 天前
Spring全家桶
java·spring·rpc
Halo_tjn1 天前
基于封装的专项 知识点
java·前端·python·算法
珠海西格1 天前
“主动预防” vs “事后补救”:分布式光伏防逆流技术的代际革命,西格电力给出标准答案
大数据·运维·服务器·分布式·云计算·能源
Fleshy数模1 天前
从数据获取到突破限制:Python爬虫进阶实战全攻略
java·开发语言
像少年啦飞驰点、1 天前
零基础入门 Spring Boot:从“Hello World”到可上线的 Web 应用全闭环指南
java·spring boot·web开发·编程入门·后端开发