Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
ScrollViewer模板的WPF参考ScrollContentPresenter_Wpf_Templates_Controls_Scrollviewer - Fatal编程技术网

ScrollViewer模板的WPF参考ScrollContentPresenter

ScrollViewer模板的WPF参考ScrollContentPresenter,wpf,templates,controls,scrollviewer,Wpf,Templates,Controls,Scrollviewer,我有一个WPF ScrollViewer,我想访问它模板的ScrollContentPresenter 如果希望访问ScrollViewer的ScrollContentPresenter,可以使用 与其尝试从ScrollViewer往下看,也许您想从内容向上绑定一些东西 比如: <Grid Width={Binding Path=ActualWidth RelativeBinding={RelativeBinding FindAncestor, AncestorType={x:Type S

我有一个WPF ScrollViewer,我想访问它模板的ScrollContentPresenter

如果希望访问ScrollViewer的ScrollContentPresenter,可以使用


与其尝试从ScrollViewer往下看,也许您想从内容向上绑定一些东西

比如:

<Grid Width={Binding Path=ActualWidth RelativeBinding={RelativeBinding FindAncestor, AncestorType={x:Type ScrollContentPresenter}}}>

注意:这种语法可能不是100%正确,这是我不知道的

这不是我想要的。我需要做的是获取对现有ScrollViewer的ScrollContentPresenter的引用。基本上,我需要得到这个ScrollContentPresenter bc的实际宽度,我需要测量滚动条的内部边界。我想做的是通过Ccode获得对ScrollContentPresenter的引用。也许我可以使用VisualTreeHelper来实现这一点,或者通过ScrollViewer的模板找到ScrollContentPresenter。
<Style x:Key="LeftScrollViewer" TargetType="{x:Type ScrollViewer}">
 <Setter Property="OverridesDefaultStyle" Value="True"/>
 <Setter Property="Template">
 <Setter.Value>
  <ControlTemplate TargetType="{x:Type ScrollViewer}">
    <Grid>
      <Grid.ColumnDefinitions>
        <ColumnDefinition Width="Auto"/>
        <ColumnDefinition/>
      </Grid.ColumnDefinitions>
      <Grid.RowDefinitions>
        <RowDefinition/>
        <RowDefinition Height="Auto"/>
      </Grid.RowDefinitions>

      <ScrollContentPresenter Grid.Column="1"/>

      <ScrollBar Name="PART_VerticalScrollBar"
        Value="{TemplateBinding VerticalOffset}"
        Maximum="{TemplateBinding ScrollableHeight}"
        ViewportSize="{TemplateBinding ViewportHeight}"
        Visibility="{TemplateBinding ComputedVerticalScrollBarVisibility}"/>
      <ScrollBar Name="PART_HorizontalScrollBar"
        Orientation="Horizontal"
        Grid.Row="1"
        Grid.Column="1"
        Value="{TemplateBinding HorizontalOffset}"
        Maximum="{TemplateBinding ScrollableWidth}"
        ViewportSize="{TemplateBinding ViewportWidth}"
        Visibility="{TemplateBinding ComputedHorizontalScrollBarVisibility}"/>

    </Grid>
   </ControlTemplate>
  </Setter.Value>
 </Setter>
</Style>
<Grid Width={Binding Path=ActualWidth RelativeBinding={RelativeBinding FindAncestor, AncestorType={x:Type ScrollContentPresenter}}}>