【问题标题】:Validation Error Template Adorner is cut insight a ScrollViewerValidation Error Template Adorner 是一个 ScrollViewer
【发布时间】:2011-04-21 06:31:11
【问题描述】:

我有以下问题。到目前为止,我将我的文本框放在滚动查看器中,我的 ValidationError Adorner 被 ScrollViewer 剪切。我找到了 Adorner 和 ScrollViewer 的一些答案,这些答案说我需要重新模板化我的 scrollviewer 并添加一个 adornerdecorator。但这对我来说毫无意义,也无济于事。 据我所知,Validation Adorner 应该在最近的 AdornerDecorator 中呈现。 ScrollViewer 默认没有 AdornerDecorator。那么有人知道为什么我的 ValidationAdorner 会被砍掉吗?

我也在寻找解决方案:)

编辑:似乎来自 ScrollViewer 模板的 ScrollContentPresenter 会导致问题,因为它默认具有 AdornerLayer。有什么想法可以解决我的问题吗?

EDIT2:

  • 有没有办法在没有 Adornerlayer 的情况下创建新的 ScrollConntentPresenter 模板?
  • 或者有没有办法从 VisualTree 中删除 Adornerlayer?
  • 或者我可以强制 Adornerlayer 在“更高/最高”的 AdornerLayer 中渲染吗?
  • 或者我可以在没有 ScrollViewer 的情况下使用滚动内容吗?

这是我的 xaml:

<UserControl>
  <AdornerDecorator>
    <Grid x:Name="RootControl">
       <Grid.RowDefinitions>
          <RowDefinition Height="auto" MinHeight="50"/>
          <RowDefinition Height="*"/>
       </Grid.RowDefinitions>

       <Grid x:Name="main" Grid.Row="1">
            <Grid.ColumnDefinitions>
                <ColumnDefinition />
                <ColumnDefinition />
            </Grid.ColumnDefinitions>

            <Border x:Name="InputBorder" Grid.Column="0">
                <ScrollViewer VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto">
                    <Grid x:Name="InputContainer" HorizontalAlignment="Stretch">
                        <Grid.RowDefinitions>
                            ...some rows...
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                            ...some columns...
                        </Grid.ColumnDefinitions>

                        <TextBox .../><!--this Validation Adorner get cut by scrollviewer-->

                   </Grid>
                </ScrollViewer> 
            </Border>
       </Grid>
    </Grid>
  </AdornerDecorator>
</UserControl>

这是我的验证模板:

<ControlTemplate x:Key="ValidationTemplate" >
    <DockPanel>
        <AdornedElementPlaceholder Name="MyAdornedElement" />
        <Grid>
            <Border Background="{StaticResource BrushError}" Margin="3,0,0,0" x:Name="ErrorControl" BorderBrush="White" BorderThickness="1">
                <TextBlock Margin="10,3,5,2" 
                        Text="{Binding ElementName=MyAdornedElement,Path=AdornedElement.(Validation.Errors).CurrentItem.ErrorContent}" 
                       Visibility="{Binding ElementName=MyAdornedElement,Path=AdornedElement.Visibility}"
                       Foreground="White" FontWeight="Bold">
                </TextBlock>
            </Border>
            <Path x:Name="path"  Margin="3,0,0,0" Data="M 0,10 L 10,0 " Fill="{StaticResource BrushError}"
                        StrokeThickness="2" Stroke="White"
                        />
        </Grid>
    </DockPanel>
</ControlTemplate>

【问题讨论】:

    标签: wpf .net-4.0 scrollviewer adorner


    【解决方案1】:

    行为是有意的。 ScrollViewer 能够隐藏它的一些内容(即位于范围内的内容)。为此类未剪辑的内容显示 Adorner 会导致 UI 异常。

    您应该能够在 ValidationTemplate 中执行的操作是将 Grid 元素放入 Popup 控件中。请尝试并报告它是否有效。

    【讨论】:

    • 只需移动窗口 :) 弹出窗口停留,装饰器随您移动。
    • 我同意,弹出窗口并不是真正的解决方案!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多