验证错误模板装饰器被切入 ScrollViewer 洞察

发布于 2024-11-02 08:38:22 字数 3080 浏览 3 评论 0原文

我有以下问题。到目前为止,我将我的文本框放在滚动查看器中,我的 ValidationError Adorner 被 ScrollViewer 剪切了。我找到了 Adorner 和 ScrollViewer 的一些答案,它们说我需要重新模板化我的滚动查看器并添加一个 adornerdecorator。但这对我来说毫无意义,也没有帮助。 据我所知,验证装饰器应该在最近的 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>

i have the following problem. as far a i put my Textboxes in a scrollviewer my ValidationError Adorner get cut by the ScrollViewer. i found some answers to Adorner and ScrollViewer which say i need to retemplate my scrollviewer and add an adornerdecorator. but this makes no sense to me and it doesnt help either.
as far as i know should the Validation Adorner rendered in the nearest AdornerDecorator. the ScrollViewer by default has no AdornerDecorator. so does anybody know why my ValidationAdorner get cut?

I also looking for a solution :)

EDIT: it seems the ScrollContentPresenter which comes from the ScrollViewer Template cause the problem, because it has a AdornerLayer by default. Any ideas how to solve my issue?

EDIT2:

  • is there a way to create a new ScrollConntentPresenter Template without a Adornerlayer?
  • or is there a way to remove a the Adornerlayer from the VisualTree?
  • or can i force the Adornerlayer to render in a" higher/most top" AdornerLayer?
  • or can i have Scrolling Content without a ScrollViewer?

here is my 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>

here is my Validation Template:

<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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

场罚期间 2024-11-09 08:38:22

该行为是有意的。 ScrollViewer 能够隐藏它的一些内容(即位于范围内的内容)。为此类不会被剪切的内容显示装饰器会导致奇怪的 UI。

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

the behavior is intended. A ScrollViewer is able to hide some of it's contents (ie the content lying in the extent). Showing an Adorner for such content that doesn't get clipped, results in a strange UI.

What you should be able to do in the ValidationTemplate though is putting the Grid element inside a Popup control. Please try that and report if it worked.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文