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();
 //        }));
 //}
相关推荐
中东大鹅1 分钟前
如何理解SpringBoot starters的自动装配
java·spring boot·后端
执笔诉情殇〆20 分钟前
SpringBoot3(若依框架)集成Mybatis-Plus和单元测试功能,以及问题解决
java·spring boot·junit·mybatis-plus
OEC小胖胖23 分钟前
架构篇(一):告别MVC/MVP,为何“组件化”是现代前端的唯一答案?
前端·架构·mvc
汤姆大聪明25 分钟前
SSM框架中关于Spring MVC的技术问题
java·spring·mvc
alien爱吃蛋挞25 分钟前
【JavaEE】Spring Web MVC(上)
前端·spring·java-ee
~央千澈~38 分钟前
Go、Node.js、Python、PHP、Java五种语言的直播推流RTMP协议技术实施方案和思路-优雅草卓伊凡
java·python·go·node
拾光拾趣录39 分钟前
一个 ID 溢出引发的线上资损
前端·javascript
液态不合群42 分钟前
JavaScript 编年史:探索前端界巨变的幕后推手
开发语言·前端·javascript
拾光拾趣录1 小时前
一个链接,两种命运
前端
yzx9910131 小时前
JS与Go:编程语言双星的碰撞与共生
java·数据结构·游戏·小程序·ffmpeg