ScrollViewer,WPF的问题

时间:2011-11-29 08:54:54

标签: wpf

栏移动,但内容不会滚动。

有什么想法吗?

我想制作一份工作时间表

<Window x:Class="WpfMiGantt.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525" xmlns:my="http://schemas.microsoft.com/winfx/2006/xaml/presentation/ribbon">
    <Grid ShowGridLines="True">
        <ScrollViewer HorizontalScrollBarVisibility="Visible" VerticalScrollBarVisibility="Visible"  >
            <Border Width="1000" Height="1000"/>
        </ScrollViewer >
        <Grid ShowGridLines="True">
            <Grid.RowDefinitions>
                <RowDefinition Height="30"/>      
                <RowDefinition Height="30"/>
            </Grid.RowDefinitions>
            <Grid Grid.Row="1" ShowGridLines="True" >
                <Grid.ColumnDefinitions >
                    <ColumnDefinition Width="60" />
                    <ColumnDefinition Width="60"  />
                    <ColumnDefinition  Width="60"/>
                    <ColumnDefinition  Width="60"/>
                    <ColumnDefinition  Width="60"/>
                    <ColumnDefinition  Width="60"/>
                    <ColumnDefinition  Width="60"/>
                    <ColumnDefinition  Width="60"/>
                    <ColumnDefinition  Width="60"/>
                    <ColumnDefinition  Width="60"/>
                    <ColumnDefinition  Width="60"/>
                    <ColumnDefinition  Width="60"/>
                    <ColumnDefinition  Width="60"/>
                    <ColumnDefinition  Width="60"/>
                    <ColumnDefinition  Width="60"/>
                    <ColumnDefinition  Width="60"/>
                    <ColumnDefinition  Width="60"/>
                    <ColumnDefinition  Width="60"/>
                    <ColumnDefinition  Width="60"/>
                    <ColumnDefinition  Width="60"/>
                </Grid.ColumnDefinitions>
                <my:RibbonTextBox Height="23"  Label="6:00" Grid.Column="0" Grid.Row="0" HorizontalAlignment="Left" Margin="0" Name="ribbonTextBox0" VerticalAlignment="Center" />
                <my:RibbonTextBox Height="23"  Label="6:30" Grid.Column="1" Grid.Row="0" HorizontalAlignment="Left" Margin="0" Name="ribbonTextBox1" VerticalAlignment="Center" />
                <my:RibbonTextBox Height="23"  Label="7:00" Grid.Column="2" Grid.Row="0" HorizontalAlignment="Left" Margin="0" Name="ribbonTextBox2" VerticalAlignment="Center" />
                <my:RibbonTextBox Height="23"  Label="7:30" Grid.Column="3" Grid.Row="0" HorizontalAlignment="Left" Margin="0" Name="ribbonTextBox3" VerticalAlignment="Center" />
                <my:RibbonTextBox Height="23"  Label="8:00" Grid.Column="4" Grid.Row="0" HorizontalAlignment="Left" Margin="0" Name="ribbonTextBox4" VerticalAlignment="Center" />
                <my:RibbonTextBox Height="23"  Label="8:30" Grid.Column="5" Grid.Row="0" HorizontalAlignment="Left" Margin="0" Name="ribbonTextBox5" VerticalAlignment="Center" />
                <my:RibbonTextBox Height="23"  Label="9:00" Grid.Column="6" Grid.Row="0" HorizontalAlignment="Left" Margin="0" Name="ribbonTextBox6" VerticalAlignment="Center" />
                <my:RibbonTextBox Height="23"  Label="10:00" Grid.Column="7" Grid.Row="0" HorizontalAlignment="Left" Margin="0" Name="ribbonTextBox7" VerticalAlignment="Center" />
                <my:RibbonTextBox Height="23"  Label="10:30" Grid.Column="8" Grid.Row="0" HorizontalAlignment="Left" Margin="0" Name="ribbonTextBox8" VerticalAlignment="Center" />
                <my:RibbonTextBox Height="23"  Label="11:00" Grid.Column="9" Grid.Row="0" HorizontalAlignment="Left" Margin="0" Name="ribbonTextBox9" VerticalAlignment="Center" />
                <my:RibbonTextBox Height="23"  Label="11:30" Grid.Column="10" Grid.Row="0" HorizontalAlignment="Left" Margin="0" Name="ribbonTextBox10" VerticalAlignment="Center" />
                <my:RibbonTextBox Height="23"  Label="12:00" Grid.Column="11" Grid.Row="0" HorizontalAlignment="Left" Margin="0" Name="ribbonTextBox11" VerticalAlignment="Center" />
                <my:RibbonTextBox Height="23"  Label="12:30" Grid.Column="12" Grid.Row="0" HorizontalAlignment="Left" Margin="0" Name="ribbonTextBox12" VerticalAlignment="Center" />
                <my:RibbonTextBox Height="23"  Label="13:00" Grid.Column="13" Grid.Row="0" HorizontalAlignment="Left" Margin="0" Name="ribbonTextBox13" VerticalAlignment="Center" />
                <my:RibbonTextBox Height="23"  Label="13:30" Grid.Column="14" Grid.Row="0" HorizontalAlignment="Left" Margin="0" Name="ribbonTextBox14" VerticalAlignment="Center" />
                <my:RibbonTextBox Height="23"  Label="14:00" Grid.Column="15" Grid.Row="0" HorizontalAlignment="Left" Margin="0" Name="ribbonTextBox15" VerticalAlignment="Center" />
                <my:RibbonTextBox Height="23"  Label="14:30" Grid.Column="16" Grid.Row="0" HorizontalAlignment="Left" Margin="0" Name="ribbonTextBox16" VerticalAlignment="Center" />
                <my:RibbonTextBox Height="23"  Label="15:00" Grid.Column="17" Grid.Row="0" HorizontalAlignment="Left" Margin="0" Name="ribbonTextBox17" VerticalAlignment="Center" />

            </Grid>
            <my:RibbonButton Label="Fecha" Grid.Column="0" Grid.Row="0"  Content="Button"  Height="30" HorizontalAlignment="Center" Margin="0" Name="ribbonButton0" VerticalAlignment="Center" Width="Auto" />
            <my:RibbonButton Label=""  Grid.Column="0" Grid.Row="1" Content="Button"  Height="30" HorizontalAlignment="Center" Margin="0" Name="ribbonButton1" VerticalAlignment="Top" Width="75" />
            <my:RibbonButton Content="Button" Grid.Column="2" Grid.ColumnSpan="2" Height="23" HorizontalAlignment="Left" Margin="38,8,0,0" Name="ribbonButton2" VerticalAlignment="Top" Width="75" />
        </Grid>
    </Grid>
</Window>

我认为线条的顺序是关键。

PD:你在codeplex或WPF中看到过类似的项目吗? 4

1 个答案:

答案 0 :(得分:3)

我怀疑你希望滚动条在Grid上运行。在这种情况下,您必须在ScrollViewer中使用网格

<ScrollViewer HorizontalScrollBarVisibility="Visible" VerticalScrollBarVisibility="Visible"  >
        <Grid ShowGridLines="True" Width="1000" Height="1000">
            ...rest of grid content
        </Grid>
    </ScrollViewer >
相关问题