我有一个Windows窗体应用程序,需要一个带有宽垂直滚动条的数据网格。我构建了一个包含带滚动条的DataGrid的WPF用户控件;我还构建了一个简单的Windows窗体测试表单,其中包含一个ElementHost元素来托管用户控件。
测试表格完全符合要求,显示宽的垂直滚动条。但是,当我在现有的WinForms应用程序中执行完全相同的操作时(我添加了一个带有用户控件的ElementHost作为子项),滚动条无处可寻(即使数据远远低于ElementHost的大小)。
似乎测试表单和我的应用程序之间的行为应该是相同的 - 如果行为不同而没有代码差异,我该如何调试呢?
<UserControl x:Class="OrdersGrid.OrdersGrid"
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:app="clr-namespace:OrdersGrid"
mc:Ignorable="d" Width="1014" Height="494"
>
<UserControl.Resources>
<app:StatusToBackgroundConverter x:Key="StatusToBackgroundConverter"/>
</UserControl.Resources>
<Grid Margin="0,0,0,0" Height="494">
<DataGrid HorizontalAlignment="Left" Margin="1,1,0,0" VerticalAlignment="Top" Height="492" Width="1012" x:Name="ordersGrid"
SelectionChanged="DataGrid_SelectionChanged" AutoGenerateColumns="False" DataContext="orders" EnableRowVirtualization="True"
VerticalScrollBarVisibility="Visible" >
<DataGrid.Resources>
<Style TargetType="ScrollBar">
<Setter Property="Width" Value="50"/>
<Setter Property="MinWidth" Value="50"/>
<Setter Property="Visibility" Value="Visible" />
</Style>
<Style TargetType="DataGridCellsPresenter">
<Setter Property="FontSize" Value="16"/>
</Style>
<SolidColorBrush x:Key="{x:Static DataGrid.FocusBorderBrushKey}" Color="#FF000000"/>
</DataGrid.Resources>
<DataGrid.ColumnHeaderStyle>
<Style TargetType="DataGridColumnHeader">
<Setter Property="FontSize" Value="16"></Setter>
<Setter Property="Height" Value="30"/>
<Setter Property="Foreground" Value="Blue"/>
</Style>
</DataGrid.ColumnHeaderStyle>
<DataGrid.RowStyle>
<Style TargetType="DataGridRow">
<Setter Property="Background" Value="{Binding RelativeSource={RelativeSource Self},Path=Item.Status,Converter={StaticResource StatusToBackgroundConverter}}"/>
</Style>
</DataGrid.RowStyle>
<DataGrid.Columns>
<DataGridTextColumn x:Name="orderId" Width="35" Binding="{Binding Num}" Header="" SortMemberPath="Num"/>
<DataGridTextColumn x:Name="shipDate" Width="90" Binding="{Binding ShipDate}" Header="Ship Date" SortMemberPath="ShipDate"/>
<DataGridTextColumn x:Name="Shipper" Width="55" Binding="{Binding Shipper}" Header="Via" SortMemberPath="Shipper"/>
<DataGridTextColumn x:Name="ArrivDate" Width="95" Binding="{Binding ArrivDate}" Header="Must Arrive"/>
<DataGridTextColumn x:Name="CustomerName" Width="120" Binding="{Binding customerName}" Header="Customer"/>
<DataGridTextColumn x:Name="AddressCode" Width="95" Binding="{Binding PRSTADCD}" Header="ADCD"/>
<DataGridTextColumn x:Name="CityState" Width="125" Binding="{Binding CityState}" Header="City State"/>
<DataGridTextColumn x:Name="OrderNum" Width="105" Binding="{Binding OrderNum}" Header="Order Num"/>
<DataGridTextColumn x:Name="CasesEaches" Width="95" Header="Order" Binding="{Binding BinCasesEaches}"/>
<DataGridTextColumn x:Name="CustPONum" Width="95" Binding="{Binding CustPONum}" Header="Cust PO" Visibility="Hidden"/>
<DataGridTextColumn x:Name="Status" Width="100" Binding="{Binding Status}" Header="Status" Visibility="Visible" SortMemberPath="Status"/>
<DataGridTextColumn x:Name="SortKey" Width="95" Binding="{Binding SortKey}" Visibility="Hidden"/>
<DataGridTextColumn x:Name="PickedBy" Width="95" Binding="{Binding PickedBy}" Visibility="Hidden"/>
<DataGridTextColumn x:Name="ClosedBy" Width="95" Binding="{Binding ClosedBy}" Visibility="Hidden"/>
<DataGridTextColumn x:Name="ClosedShortBy" Width="95" Binding="{Binding ClosedShortBy}" Visibility="Hidden"/>
</DataGrid.Columns>
</DataGrid>
</Grid>