本文介绍了超出其尺寸的UserControl的内容由包含该UserControl的Scrollviewer裁剪.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的所有人,

在我的WPF项目中,我具有带有Scrollviewer的MainWindow. Scrollviewwer内部是我在单独的xaml文件中定义的UserControl1(继承自UserControl).该UserControl1中定义了Rectangle,并且该矩形超出了UserControl1的尺寸,即其下边缘在UserControl1的下边缘下方.矩形不是由UserControl1裁剪的,而是由Scrollviewer裁剪的.

如果这还不够清楚,那么这里是更精确的解释(2个xaml文件的内容,它们描述了我的2个类MainWindow和UserControl1):

MainWindow.xaml:

Dear all,

In my WPF project I have MainWindow with Scrollviewer in it. Inside the Scrollviewwer is UserControl1 (which inherits from UserControl) that I defined in separate xaml file. That UserControl1 has Rectangle defined in it and that rectangle exceeds dimensions of the UserControl1, namely its lower edge is beneath lower edge of the UserControl1. The rectangle is not clipped by UserControl1 but is by the Scrollviewer.

If this is not clear enough, here is more precise explanation (contents of 2 xaml files which describes my 2 classes MainWindow and UserControl1):

MainWindow.xaml:

<Window

    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

    xmlns:local="clr-namespace:clippingIsue1"

    x:Class="clippingIsue1.MainWindow"

    x:Name="Window"

    Title="MainWindow"

    Width="640" Height="480">
    <Grid x:Name="LayoutRoot" Background="White">
        <ScrollViewer x:Name="scv" HorizontalAlignment="Left" Margin="73,108,0,0" Width="242" Background="Silver" Height="70" VerticalAlignment="Top">
            <local:UserControl1 x:Name="uc1" Width="Auto" Height="39" VerticalAlignment="Top"/>
        </ScrollViewer>
    </Grid>
</Window>



UserControl1.xaml



UserControl1.xaml

<UserControl

    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"

    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"

    mc:Ignorable="d"

    x:Class="clippingIsue1.UserControl1"

    x:Name="UserControl" Width="371.5" Height="30">
    <Grid x:Name="LayoutRoot" Background="#FF9D0404">
        <Rectangle x:Name="rt" Fill="#FF5A5AD2" Stroke="Black" Height="200" Margin="8,8,8,-178"/>
    </Grid>
</UserControl>




我的问题是:

1.为什么会这样?
2.我该怎么做才能使Scrollviewer不能裁剪Rectangle,使其也超出Scrollviewer的尺寸,或者允许滚动,以便用户可以向下滚动以查看矩形的其余部分?

在此先谢谢您.




My questions are:

1. Why is this happening?
2. What can I do to make my Scrollviewer either not clip the Rectangle, so it exceeds Scrollviewer dimensions, too, or allow scrolling, so that user can scroll down to see the rest of the rectangle?

Thanks in advance.

推荐答案

<UserControl

    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"

    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"

    mc:Ignorable="d"

    x:Class="clippingIsue1.UserControl1"

    x:Name="UserControl" Width="371.5" Height="Auto">
    <Grid x:Name="LayoutRoot" Background="#FF9D0404">
        <Rectangle x:Name="rt" Fill="#FF5A5AD2" Stroke="Black" Margin="8,8,8,8"/>
    </Grid>
</UserControl>



这篇关于超出其尺寸的UserControl的内容由包含该UserControl的Scrollviewer裁剪.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-18 11:56