英文:
How to set thickness of scrollbars in scrollviewer
问题
如何控制DataGrid
控件中作为水平或垂直滚动条一部分显示的滚动条的厚度?我希望它们显示得比目前更"粗"。
备注:为了展示一个带有虚拟数据的DataGrid
示例应用,以下截图基于"Xaml brewer"示例应用,您可以在这里找到它。
我有一个DataGrid
,它始终显示垂直和水平滚动条(我删除了所有非必要的XAML代码):
<Page
xmlns:controls="using:CommunityToolkit.WinUI.UI.Controls"
mc:Ignorable="d">
<Grid>
<controls:DataGrid AutoGenerateColumns="False"
VerticalScrollBarVisibility="Visible"
HorizontalScrollBarVisibility="Visible">
<controls:DataGrid.Columns>
</controls:DataGrid.Columns>
</controls:DataGrid>
</Grid>
</Page>
这是滚动条通常显示的方式,即DataGrid
获得焦点,但鼠标当前没有悬停在其中一个滚动条上。它们显示得很细,以至于我的应用程序用户有时无法注意到它们:
当鼠标当前悬停在其中一个滚动条上时(在这种情况下是底部的水平滚动条),滚动条的显示方式如下。现在这个滚动条显示得更粗,因此更容易看到:
是否有办法使滚动条显示得更粗/设置它们的厚度,或者指定它们应始终以在悬停在它们上方时的方式显示(请参见上面的第二个截图,它们在那种情况下显示得更厚)?
英文:
How can I control the thickness of a horizontal or vertical Scrollbar
that gets displayed in a / as part of a DataGrid
control?
I would like them to be displayed "thicker" than how that are displayed at the moment.
Remark: For the sake of showing an example application with dummy data in a DataGrid
the screenshots below are based on the "Xaml brewer" sample application which you can find here.
I have a DataGrid
that always shows vertical and horizontal scrollbars (I removed all non-essential XAML code):
<Page
xmlns:controls="using:CommunityToolkit.WinUI.UI.Controls"
mc:Ignorable="d">
<Grid>
<controls:DataGrid AutoGenerateColumns="False"
VerticalScrollBarVisibility="Visible"
HorizontalScrollBarVisibility="Visible">
<controls:DataGrid.Columns>
</controls:DataGrid.Columns>
</controls:DataGrid>
</Grid>
</Page>
This is how the scrollbars are displayed normally, i.e. the DataGrid has focus, but the mouse is not currently hovering over one of the scrollbars. They are displayed very thin, so that the users of my application sometimes do not recognize them:
This is how a Scrollbar
is displayed when the mouse is currently hovering over one of them (in this case the horizontal scrollbar at the bottom). Now this one is displayed a bit thicker and thus easier to see:
Is there are way to display the scrollbars thicker / set their thickness, or specify that they should always be displayed in the way they are displayed when hovering over them (see second screenshot above, they are displayed thicker in that case)?
答案1
得分: 2
> Is there are way to display the scrollbars thicker / set their thickness
有没有办法使滚动条更粗/设置它们的厚度
> specify that they should always be displayed in the way they are displayed when hovering over them
指定它们应该始终以悬停在其上时显示的方式显示
英文:
> Is there are way to display the scrollbars thicker / set their thickness
You might be able to re-style the ScrollBar
but an empty ScrollBar
style should give you a WPF-like ScrollBar
.
<controls:DataGrid>
<controls:DataGrid.Resources>
<Style TargetType="ScrollBar" />
</controls:DataGrid.Resources>
</controls:DataGrid>
> specify that they should always be displayed in the way they are displayed when hovering over them
I have published a NuGet package called AK.Toolkit.WinUI3.ScrollBarExtensions for this. Try it out and see if it fits your requirements.
<Page
:
xmlns:controls="using:CommunityToolkit.WinUI.UI.Controls"
xmlns:toolkit="using:AK.Toolkit.WinUI3" />
<controls:DataGrid
toolkit:ScrollBarExtensions.KeepHorizontalExpanded="True"
toolkit:ScrollBarExtensions.KeepVerticalExpanded="True"
HorizontalScrollBarVisibility="Visible"
VerticalScrollBarVisibility="Visible" />
</Page>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论