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();
 //        }));
 //}
相关推荐
JiKun几秒前
一键配置 Web 前端开发环境(PowerShell 自动化脚本)
前端·windows·程序员
合作小小程序员小小店6 分钟前
web网页开发,在线%考试,教资,题库%系统demo,基于vue,html,css,python,flask,随机分配,多角色,前后端分离,mysql数据库
前端·vue.js·后端·前端框架·flask
peiwang2458 分钟前
Linux系统中CoreDump的生成与调试
java·linux·开发语言
顾漂亮12 分钟前
Redis深度探索
java·redis·后端·spring·缓存
努力也学不会java12 分钟前
【Spring】Spring事务和事务传播机制
java·开发语言·人工智能·spring boot·后端·spring
慧一居士13 分钟前
ES6(ECMAScript 2015)功能介绍,使用场景,对应功能点完整使用示例
前端
kkkkk02110617 分钟前
《从 0 到 1 毫秒:用 Rust + Axum 0.8 打造支持 HTTP/3 的零拷贝文件服务器》
服务器·http·rust
吃饺子不吃馅23 分钟前
了解微前端:为何 Web Component 是绕不开的关键技术?
前端·javascript·架构
hookserver24 分钟前
企业微信聚合应用系统,ipad协议接口
java·http·微信·企业微信·ipad
恋猫de小郭28 分钟前
第一台 Andriod XR 设备发布,Jetpack Compose XR 有什么不同?对原生开发有何影响?
android·前端·flutter