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();
 //        }));
 //}
相关推荐
小奶包他干奶奶40 分钟前
Webpack学习——Loader(文件转换器)
前端·学习·webpack
zy happy1 小时前
若依 vue3 报错:找不到模块“@/api/xxxx/xxxxx”或其相应的类型声明。。Vue 3 can not find mod
前端·javascript·vue.js
潘小安1 小时前
Git Worktree + Claude Code:让你的开发效率翻倍的秘密武器
前端
xu_yule2 小时前
Linux_12(进程信号)内核态和用户态+处理信号+不可重入函数+volatile
linux·运维·服务器
meichaoWen2 小时前
【Vue3】vue3的全面学习(一)
前端·javascript·学习
虾..2 小时前
Linux 环境变量&&进程优先级
linux·运维·服务器
Y***h1872 小时前
第二章 Spring中的Bean
java·后端·spring
小猪努力学前端2 小时前
在 React + React Router v7 SSR 项目里做多端适配,我踩的两个坑
前端·react.js
q***d1732 小时前
React桌面应用开发
前端·react.js·前端框架
8***29312 小时前
解决 Tomcat 跨域问题 - Tomcat 配置静态文件和 Java Web 服务(Spring MVC Springboot)同时允许跨域
java·前端·spring