简体   繁体   English

带有扩展器的ScrollViewer

[英]ScrollViewer with Expanders

I have a ScrollViewer in my Silverlight project which contains expanders with content. 我的Silverlight项目中有一个ScrollViewer,其中包含带有内容的扩展器。 The VerticalScrollBarVisibility is set to Auto and HorizontalScrollBarVisibility set to Disabled as it is not needed. 由于不需要将VerticalScrollBarVisibility设置为Auto,将Horizo​​ntalScrollBarVisibility设置为Disabled。 The problem is when I expand one or more expanders so that the Vertical scrollbar is visible, it pushes the content within the expander slightly to the left. 问题是当我展开一个或多个扩展器以使“垂直”滚动条可见时,它会将扩展器中的内容稍微向左推。 How can I make it so when the (Vertical) scrollbar appears that it doesn't push expanders/content to the left? 当(垂直)滚动条出现时,如何将扩展器/内容不向左推,我该怎么做?

I cannot upload images so uploaded expanded example to TinyPic: 我无法上传图片,因此上传的扩展示例已上传到TinyPic:

http://i42.tinypic.com/xvamd.png http://i42.tinypic.com/xvamd.png

Sample code available at http://pastebin.com/khPR8nPF 示例代码可从http://pastebin.com/khPR8nPF获得

Thanks! 谢谢!

You could do something like: 您可以执行以下操作:

<ScrollViewer Name="scrollViewer1"
              Grid.Row="1"
              Grid.ColumnSpan="2"
              VerticalAlignment="Stretch"
              VerticalContentAlignment="Stretch"
              BorderBrush="{x:Null}"
              VerticalScrollBarVisibility="Auto">
  <!-- New Bit -->
  <ScrollViewer.Style>
    <Style TargetType="{x:Type ScrollViewer}">
      <Style.Resources>
        <Thickness x:Key="InvisScrollBarDimension"
                    Bottom="0"
                    Left="0"
                    Right="{StaticResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}"
                    Top="0" />
      </Style.Resources>
      <Setter Property="Margin"
              Value="{StaticResource InvisScrollBarDimension}" />
      <Style.Triggers>
        <Trigger Property="ComputedVerticalScrollBarVisibility"
                  Value="Visible">
          <Setter Property="Margin"
                  Value="0" />
        </Trigger>
      </Style.Triggers>
    </Style>
  </ScrollViewer.Style>
  ...

Concept is pretty much give the ScrollViewer a right Margin based on System parameter VerticalScrollBarWidthKey when the Scrollbar is not visible which the Trigger for ComputedVerticalScrollBarVisibility helps us determine and reset it to 0 when Scrollbar is visible. Scrollbar不可见时,可以根据系统参数VerticalScrollBarWidthKeyScrollViewer正确的Margin这个概念几乎可以给ScrollViewer提供帮助,而当Scrollbar可见时, ComputedVerticalScrollBarVisibilityTrigger可以帮助我们确定它并将其重置为0。

This should give the no jitter effect at run-time. 这将在运行时不产生抖动效果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM