我尝试在默认的scrollvIEwer样式中重写滚动条边距.只需修改样式中的边距,滚动条magin设置正确的值.但滚动条移动时,scrollvIEwer中的内容会保持静态.我该如何修复它还是有另一种方法来设置scrollvIEwer中滚动条的余量更容易吗?
<Style targettype="ScrollVIEwer"> <Setter Property="HorizontalContentAlignment" Value="left" /> <Setter Property="VerticalContentAlignment" Value="top" /> <Setter Property="VerticalScrollbarVisibility" Value="Visible" /> <Setter Property="padding" Value="4"/> <Setter Property="borderThickness" Value="1"/> <Setter Property="borderBrush"> <Setter.Value> <linearGradIEntBrush EndPoint="0.5,1" StartPoint="0.5,0"> <GradIEntStop color="#FFA3AEB9" Offset="0"/> <GradIEntStop color="#FF8399A9" Offset="0.375"/> <GradIEntStop color="#FF718597" Offset="0.375"/> <GradIEntStop color="#FF617584" Offset="1"/> </linearGradIEntBrush> </Setter.Value> </Setter> <Setter Property="Template"> <Setter.Value> <ControlTemplate targettype="ScrollVIEwer"> <border CornerRadius="2" borderBrush="{TemplateBinding borderBrush}" borderThickness="{TemplateBinding borderThickness}"> <GrID Background="{TemplateBinding Background}"> <GrID.RowDeFinitions> <RowDeFinition Height="*"/> <RowDeFinition Height="auto"/> </GrID.RowDeFinitions> <GrID.ColumnDeFinitions> <ColumnDeFinition WIDth="*"/> <ColumnDeFinition WIDth="auto"/> </GrID.ColumnDeFinitions> <ScrollContentPresenter x:name="ScrollContentPresenter" Cursor="{TemplateBinding Cursor}" margin="{TemplateBinding padding}" ContentTemplate="{TemplateBinding ContentTemplate}"/> <Rectangle GrID.Column="1" GrID.Row="1" Fill="#FFE9EEF4"/> <Scrollbar x:name="VerticalScrollbar" WIDth="18" IsTabStop="False" Visibility="{TemplateBinding ComputedVerticalScrollbarVisibility}" GrID.Column="1" GrID.Row="0" OrIEntation="Vertical" VIEwportSize="{TemplateBinding VIEwportHeight}" `enter code here` Maximum="{TemplateBinding ScrollableHeight}" Minimum="0" Value="{TemplateBinding VerticalOffset}" margin="0,20,0"/> <Scrollbar x:name="HorizontalScrollbar" Height="18" IsTabStop="False" Visibility="{TemplateBinding ComputedHorizontalScrollbarVisibility}" GrID.Column="0" GrID.Row="1" OrIEntation="Horizontal" VIEwportSize="{TemplateBinding VIEwportWIDth}" Maximum="{TemplateBinding ScrollableWIDth}" Minimum="0" Value="{TemplateBinding HorizontalOffset}" margin="-1,-1,-1"/> </GrID> </border> </ControlTemplate> </Setter.Value> </Setter>解决方法 我为垂直Scrollbar制作了margin =“10,10,20”,它工作得很好.
ScrollVIEwer包含一个用于测试目的的DataGrID.
XAML:
<ScrollVIEwer HorizontalAlignment="left" Height="152" margin="25,42,0" VerticalAlignment="top" WIDth="449"> <ScrollVIEwer.Template> <ControlTemplate targettype="{x:Type ScrollVIEwer}"> <GrID x:name="GrID" Background="{TemplateBinding Background}"> <GrID.ColumnDeFinitions> <ColumnDeFinition WIDth="*"/> <ColumnDeFinition WIDth="auto"/> </GrID.ColumnDeFinitions> <GrID.RowDeFinitions> <RowDeFinition Height="*"/> <RowDeFinition Height="auto"/> </GrID.RowDeFinitions> <Rectangle x:name="Corner" GrID.Column="1" Fill="{DynamicResource {x:Static Systemcolors.ControlBrushKey}}" GrID.Row="1"/> <ScrollContentPresenter x:name="PART_ScrollContentPresenter" CanContentScroll="{TemplateBinding CanContentScroll}" CanHorizontallyScroll="False" CanVerticallyScroll="False" ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}" GrID.Column="0" margin="{TemplateBinding padding}" GrID.Row="0"/> <Scrollbar x:name="PART_VerticalScrollbar" automationPropertIEs.automationID="VerticalScrollbar" Cursor="Arrow" GrID.Column="1" Maximum="{TemplateBinding ScrollableHeight}" Minimum="0" GrID.Row="0" Visibility="{TemplateBinding ComputedVerticalScrollbarVisibility}" Value="{Binding VerticalOffset,Mode=OneWay,relativeSource={relativeSource TemplatedParent}}" VIEwportSize="{TemplateBinding VIEwportHeight}" margin="10,20"/> <Scrollbar x:name="PART_HorizontalScrollbar" automationPropertIEs.automationID="HorizontalScrollbar" Cursor="Arrow" GrID.Column="0" Maximum="{TemplateBinding ScrollableWIDth}" Minimum="0" OrIEntation="Horizontal" GrID.Row="1" Visibility="{TemplateBinding ComputedHorizontalScrollbarVisibility}" Value="{Binding HorizontalOffset,relativeSource={relativeSource TemplatedParent}}" VIEwportSize="{TemplateBinding VIEwportWIDth}"/> </GrID> </ControlTemplate> </ScrollVIEwer.Template> <DataGrID x:name="dataGrID" ItemsSource="{Binding Mode=OneWay}"> <DataGrID.DataContext> <local:MyDataCollection/> </DataGrID.DataContext> </DataGrID> </ScrollVIEwer>总结
以上是内存溢出为你收集整理的c# – 如何仅使用xaml在scrollviewer中设置滚动条的余量全部内容,希望文章能够帮你解决c# – 如何仅使用xaml在scrollviewer中设置滚动条的余量所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)