XAML ScrollView扩展效果

时间:2018-07-13 03:11:57

标签: c# xaml

在上下文中,我制作了一个Calendar控件,该控件可以保存几天,每天垂直显示24小时。它必须看起来像这样:

为了更好地查看放大图像

图片1  enter image description here

现在,我的问题是,当我滚动到顶部外观时,显示如下:

图片2 enter image description here

然后,当我滚动到底部外观时,返回图1。

对我来说,它看起来像XAML错误。但是也许我做错了。

有一种方法可以防止这种行为?

代码:

DAY:

<UserControl x:Class="MyNS.Recursos.Controles.Controls.Calendar.CalendarDayViewControl"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:local="clr-namespace:MyNS.Recursos.Controles.Controls.Calendar"
             mc:Ignorable="d" 
             d:DesignHeight="1152" 
             d:DesignWidth="800"
             x:Name="ThisCalendarDay">
    <Grid x:Name="DayViewGrd" 
          MouseMove="DayViewGrd_MouseMove"
          MouseEnter="DayViewGrd_MouseEnter"
          MouseLeave="DayViewGrd_MouseLeave" 
          MouseUp="DayViewGrd_MouseUp">
        <Border BorderThickness="0,0,1,0" BorderBrush="Orange">
            <Grid>
                <Grid Background="White">
                    <Grid.RowDefinitions>
                        <RowDefinition/>
                        <RowDefinition/>
                        <RowDefinition/>
                        <RowDefinition/>
                        <RowDefinition/>
                        <RowDefinition/>
                        <RowDefinition/>
                        <RowDefinition/>
                        <RowDefinition/>
                        <RowDefinition/>
                        <RowDefinition/>
                        <RowDefinition/>
                        <RowDefinition/>
                        <RowDefinition/>
                        <RowDefinition/>
                        <RowDefinition/>
                        <RowDefinition/>
                        <RowDefinition/>
                        <RowDefinition/>
                        <RowDefinition/>
                        <RowDefinition/>
                        <RowDefinition/>
                        <RowDefinition/>
                        <RowDefinition/>
                    </Grid.RowDefinitions>
                    <local:CalendarHourViewControl  Grid.Row="0"/>
                    <local:CalendarHourViewControl  Grid.Row="1"/>
                    <local:CalendarHourViewControl  Grid.Row="2"/>
                    <local:CalendarHourViewControl  Grid.Row="3"/>
                    <local:CalendarHourViewControl  Grid.Row="4"/>
                    <local:CalendarHourViewControl  Grid.Row="5"/>
                    <local:CalendarHourViewControl  Grid.Row="6"/>
                    <local:CalendarHourViewControl  Grid.Row="7"/>
                    <local:CalendarHourViewControl  Grid.Row="8"/>
                    <local:CalendarHourViewControl  Grid.Row="9"/>
                    <local:CalendarHourViewControl  Grid.Row="10"/>
                    <local:CalendarHourViewControl  Grid.Row="11"/>
                    <local:CalendarHourViewControl  Grid.Row="12"/>
                    <local:CalendarHourViewControl  Grid.Row="13"/>
                    <local:CalendarHourViewControl  Grid.Row="14"/>
                    <local:CalendarHourViewControl  Grid.Row="15"/>
                    <local:CalendarHourViewControl  Grid.Row="16"/>
                    <local:CalendarHourViewControl  Grid.Row="17"/>
                    <local:CalendarHourViewControl  Grid.Row="18"/>
                    <local:CalendarHourViewControl  Grid.Row="19"/>
                    <local:CalendarHourViewControl  Grid.Row="20"/>
                    <local:CalendarHourViewControl  Grid.Row="21"/>
                    <local:CalendarHourViewControl  Grid.Row="22"/>
                    <local:CalendarHourViewControl  Grid.Row="23"/>
                </Grid>
            </Grid>
        </Border>
    </Grid>
</UserControl>

小时:

<UserControl x:Class="MyNS.Recursos.Controles.Controls.Calendar.CalendarHourViewControl"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:local="clr-namespace:MyNS.Recursos.Controles.Controls.Calendar"
             mc:Ignorable="d" 
             d:DesignHeight="450" d:DesignWidth="800">
    <Grid x:Name="HourGrd">
        <Grid.RowDefinitions>
            <RowDefinition/>
            <RowDefinition/>
        </Grid.RowDefinitions>
        <Line X1="0" X2="{Binding ElementName=HourGrd,Path=ActualWidth}" Y1="0" Y2="0" VerticalAlignment="Bottom" Stroke="DarkGray" StrokeThickness="0.3"/>
        <Line X1="0" X2="{Binding ElementName=HourGrd,Path=ActualWidth}" Y1="0" Y2="0" VerticalAlignment="Bottom" Stroke="DarkGray" StrokeThickness="0.5" Grid.Row="1"/>
    </Grid>
</UserControl>

这是我的容器,每天都会以编程方式添加。

容器:

<UserControl x:Class="MyNS.Recursos.Controles.Controls.Calendar.CalendarViewerControl"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:local="clr-namespace:MyNS.Recursos.Controles.Controls.Calendar"
             mc:Ignorable="d" 
             d:DesignHeight="1152" 
             d:DesignWidth="800"
             x:Name="THisCalendarViewerControl">
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        <Grid Background="Orange">
        </Grid>
        <ScrollViewer x:Name="HeadersScrll" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden" Grid.Column="1" ScrollChanged="HeadersScrll_ScrollChanged">
            <Grid x:Name="HeadersGrd" Background="Orange">
            </Grid>
        </ScrollViewer>
        <ScrollViewer x:Name="HoursScrll" VerticalScrollBarVisibility="Hidden" HorizontalScrollBarVisibility="Visible" Grid.Row="1" ScrollChanged="HoursScrll_ScrollChanged">
            <Grid x:Name="HoursGrd"
                  Height="{Binding ElementName=THisCalendarViewerControl,Path=DayHeigth}">
                <Grid.RowDefinitions>
                    <RowDefinition/>
                    <RowDefinition/>
                    <RowDefinition/>
                    <RowDefinition/>
                    <RowDefinition/>
                    <RowDefinition/>
                    <RowDefinition/>
                    <RowDefinition/>
                    <RowDefinition/>
                    <RowDefinition/>
                    <RowDefinition/>
                    <RowDefinition/>
                    <RowDefinition/>
                    <RowDefinition/>
                    <RowDefinition/>
                    <RowDefinition/>
                    <RowDefinition/>
                    <RowDefinition/>
                    <RowDefinition/>
                    <RowDefinition/>
                    <RowDefinition/>
                    <RowDefinition/>
                    <RowDefinition/>
                    <RowDefinition/>
                </Grid.RowDefinitions>
                <local:CalendarHourHeaderViewControl Am="True" Hour="00"/>
                <local:CalendarHourHeaderViewControl Am="True" Hour="01" Grid.Row="1"/>
                <local:CalendarHourHeaderViewControl Am="True" Hour="02" Grid.Row="2"/>
                <local:CalendarHourHeaderViewControl Am="True" Hour="03" Grid.Row="3"/>
                <local:CalendarHourHeaderViewControl Am="True" Hour="04" Grid.Row="4"/>
                <local:CalendarHourHeaderViewControl Am="True" Hour="05" Grid.Row="5"/>
                <local:CalendarHourHeaderViewControl Am="True" Hour="06" Grid.Row="6"/>
                <local:CalendarHourHeaderViewControl Am="True" Hour="07" Grid.Row="7"/>
                <local:CalendarHourHeaderViewControl Am="True" Hour="08" Grid.Row="8"/>
                <local:CalendarHourHeaderViewControl Am="True" Hour="09" Grid.Row="9"/>
                <local:CalendarHourHeaderViewControl Am="True" Hour="10" Grid.Row="10"/>
                <local:CalendarHourHeaderViewControl Am="True" Hour="11" Grid.Row="11"/>
                <local:CalendarHourHeaderViewControl AmPm="p.m." Hour="12" Grid.Row="12"/>
                <local:CalendarHourHeaderViewControl AmPm="p.m." Hour="01" Grid.Row="13"/>
                <local:CalendarHourHeaderViewControl AmPm="p.m." Hour="02" Grid.Row="14"/>
                <local:CalendarHourHeaderViewControl AmPm="p.m." Hour="03" Grid.Row="15"/>
                <local:CalendarHourHeaderViewControl AmPm="p.m." Hour="04" Grid.Row="16"/>
                <local:CalendarHourHeaderViewControl AmPm="p.m." Hour="05" Grid.Row="17"/>
                <local:CalendarHourHeaderViewControl AmPm="p.m." Hour="06" Grid.Row="18"/>
                <local:CalendarHourHeaderViewControl AmPm="p.m." Hour="07" Grid.Row="19"/>
                <local:CalendarHourHeaderViewControl AmPm="p.m." Hour="08" Grid.Row="20"/>
                <local:CalendarHourHeaderViewControl AmPm="p.m." Hour="09" Grid.Row="21"/>
                <local:CalendarHourHeaderViewControl AmPm="p.m." Hour="10" Grid.Row="22"/>
                <local:CalendarHourHeaderViewControl AmPm="p.m." Hour="11" Grid.Row="23"/>
            </Grid>
        </ScrollViewer>
        <ScrollViewer x:Name="DaysScrll" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Visible" Grid.Row="1" Grid.Column="1" ScrollChanged="DaysScrll_ScrollChanged">
            <Grid x:Name="DaysGrd" Grid.Column="1" Grid.Row="1" Height="{Binding ElementName=THisCalendarViewerControl,Path=DayHeigth}">
            </Grid>
        </ScrollViewer>
    </Grid>
</UserControl>

0 个答案:

没有答案