C#WPF :我正在尝试在网格周围添加一个简单的滚动条。网格是一个标签项。我用scrollViewer封闭了网格,并且只是为了检查而使它可见,虽然我也更喜欢自动。但滚动条不起作用。 我想要的是:整个东西没有被我的笔记本电脑屏幕容纳,所以水平滚动应该让我看到其他部分。整个东西被包含在网格中,所以我想把它放在scrollviewer标签下是有意义的。有人请帮帮我。
<TabControl Name="tabControl" VerticalContentAlignment="Stretch" HorizontalAlignment="Stretch" TabStripPlacement="Left" Grid.Row="0" Grid.Column="0" >
<TabItem Name="AssessTab" Header="Assess" ClipToBounds="True">
<ScrollViewer ScrollViewer.HorizontalScrollBarVisibility="Visible" Background="Green" ScrollViewer.VerticalScrollBarVisibility="Visible">
<Grid Height="Auto" Name="StackPanel1" Width="Auto" ClipToBounds="True">
<Grid.RowDefinitions>
<RowDefinition Height="29" />
<RowDefinition Height="70*" MinHeight="200" />
<RowDefinition Height="35"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="70" />
<ColumnDefinition Width="56" />
<ColumnDefinition Width="1043"/>
<ColumnDefinition Width="10" />
<ColumnDefinition Width="156*" />
</Grid.ColumnDefinitions>
<Button Content="Count All" HorizontalAlignment="Left" Margin="3,5,0,3.8" Name="CountAllProjectsButton" Width="75" Grid.ColumnSpan="2" Click="CountAllProjectsButton_Click" ToolTip="Scan the petrel project and populate the objects count."/>
<DataGrid Grid.Row="1" Grid.ColumnSpan="3" AutoGenerateColumns="True" Height="Auto" HorizontalAlignment="Stretch" HorizontalContentAlignment="Stretch" x:Name="PetrelSummaryGrid" VerticalAlignment="Stretch" Width="Auto" MinWidth="150" ItemsSource="{Binding}" AlternationCount="2" CanUserAddRows="False" CanUserDeleteRows="False" ClipToBounds="True" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto" ClipboardCopyMode="IncludeHeader" AutoGeneratingColumn="PetrelSummaryGrid_AutoGeneratingColumn">
<DataGrid.ContextMenu>
<ContextMenu>
<MenuItem Header="Check All" Click="MenuItem_Click" />
<MenuItem Header="UnCheck All" Click="MenuItem_Click_1" />
<MenuItem Header="Check Selected" CommandParameter="{Binding RelativeSource={RelativeSource Self}, Path=Parent}" Click="MenuItem_Click_2"/>
<MenuItem Header="UnCheck Selected" CommandParameter="{Binding RelativeSource={RelativeSource Self}, Path=Parent}" Click="MenuItem_Click_2"/>
<MenuItem Header="Copy WKT" Tag="SK" Click="MenuItem_Click_4" />
<MenuItem Header="Copy Petrel WKT" Tag="PETREL" Click="MenuItem_Click_4" />
</ContextMenu>
</DataGrid.ContextMenu>
<DataGrid.RowStyle>
<Style TargetType="DataGridRow">
<Style.Triggers>
<DataTrigger Binding="{Binding Path=IsError}" Value="true">
<Setter Property="Background">
<Setter.Value>
<SolidColorBrush Color="Red" Opacity="0.8"/>
</Setter.Value>
</Setter>
</DataTrigger>
</Style.Triggers>
</Style>
</DataGrid.RowStyle>
</DataGrid>
<GridSplitter Grid.Row="2" Grid.ColumnSpan="5" Width="Auto" HorizontalAlignment="Stretch" Margin="0,1" Name="gridSplitter7" VerticalAlignment="Top" Height="8" />
<GridSplitter Grid.Row="1" Grid.RowSpan="3" Grid.Column="3" Height="Auto" HorizontalAlignment="Stretch" Margin="0,0,0,0" Name="gridSplitter5" VerticalAlignment="Stretch" Width="8" />
<tk:DataGrid Grid.RowSpan="4" Grid.Column="4" FrozenColumnCount="1" AutoGenerateColumns="False" Height="Auto" Name="AssessmentGrid" Width="Auto" MinWidth="100" HorizontalAlignment="Stretch" HorizontalContentAlignment="Stretch" VerticalAlignment="Stretch" ItemsSource="{Binding}" HorizontalScrollBarVisibility="Visible" VerticalScrollBarVisibility="Visible" ClipboardCopyMode="IncludeHeader">
<tk:DataGrid.Columns>
<tk:DataGridTextColumn Header="Feature" Binding="{Binding Path=Feature, Mode=OneWay}" />
<tk:DataGridTextColumn Header="Duration" Binding="{Binding Path=Duration, Mode=TwoWay, StringFormat={}\{0:F\}}" Visibility="Collapsed"/>
<tk:DataGridTextColumn Header="Units" Binding="{Binding Path=Units, Mode=OneWay}" Visibility="Collapsed"/>
<tk:DataGridTextColumn Header="Quantity" Binding="{Binding Path=Quantity, Mode=OneWay}" />
<tk:DataGridTextColumn Header="Minutes" Binding="{Binding Path=Minutes, Mode=OneWay}" Visibility="Collapsed"/>
<tk:DataGridTextColumn Header="Days" Binding="{Binding Path=Days, Mode=OneWay, StringFormat={}\{0:F\}}" Visibility="Collapsed"/>
</tk:DataGrid.Columns>
</tk:DataGrid>
<Button Content="Cancel Count" x:Name="CancelCountButton" Grid.Column="1" HorizontalAlignment="Left" Margin="12,5,0,0" Width="Auto" Height="20" VerticalAlignment="Top" Grid.ColumnSpan="2" Click="CancelCountButton_Click"/>
<Button Content="Save Assessment " Height="20" HorizontalAlignment="Left" Margin="40,5,0,0" Name="SaveAssessmentButton" VerticalAlignment="Top" Width="Auto" Grid.Column="2" Grid.ColumnSpan="2" Click="SaveAssessmentButton_Click" ToolTip="Save the Assesment to XML for future use."/>
<Label Name="lblAssessVisualIndicator" Content="!" FontWeight="Bold" FontSize="14" Foreground="Red" Height="Auto" HorizontalAlignment="Left" HorizontalContentAlignment="Left" Margin="135,0,0,5" Grid.Column="2" Width="20" Visibility="Visible" ToolTip="Unsaved data present in the assesment grid."/>
<Button Content="Load Assessment" Height="20" HorizontalAlignment="Left" Margin="150,4,0,0" Name="LoadAssessmentButton" VerticalAlignment="Top" Width="Auto" Grid.Column="2" IsEnabled="True" Click="LoadAssessmentButton_Click" ToolTip="Load previosely saved assesment."/>
<ProgressBar Height="18" HorizontalAlignment="Stretch" Width="Auto" Margin="35,0,11,4" Name="prgBarAsses" VerticalAlignment="Bottom" Grid.Row="2" Grid.Column="1" Grid.ColumnSpan="2"/>
<Label Content="Progress" HorizontalAlignment="Left" Margin="35,0,0,4" VerticalAlignment="Bottom" RenderTransformOrigin="0.484,0" Width="73" Grid.ColumnSpan="2" Grid.Row="2" />
</Grid>
</ScrollViewer>
</TabItem>