我是WPF的新手,我試圖爲正在開發的應用創建儀表板界面。我的問題如下:水平滾動問題
我有一個datagrid將包含我的數據。這個數據網格在網格中,因爲我需要特殊部分的超級鏈接。我在數據表中插入了一個測試行,它顯示正常,但網格中的datagrid元素似乎有自己的滾動條。超級標題行和數據網格行都從窗口延伸出來,但只有datagrid行會滾動。當datagrid行滾動時,2個可見的超級標頭保持在同一個位置。以下是我的xaml代碼來生成接口。我曾嘗試在scrollviewer中包裝網格,並將超級標題的行的水平滾動條設置爲可見,但目前爲止沒有任何工作。如果我至少可以讓超級標題滾動,至少我可以嘗試創建一個事件處理程序,以在移動數據網格滾動條時移動超級標題。對不起,如果這看起來有點亂碼,但我還沒喝過咖啡,而且我還有偏頭痛,這是程序員要體驗的最好的事情之一。 在此先感謝
<Canvas HorizontalAlignment="Center" Height="508" VerticalAlignment="Top" Width="1366" Margin="-4,4,2,-7">
<Grid Canvas.Top="2">
<Grid.RowDefinitions>
<RowDefinition Height="2*"/>
<RowDefinition Height="2*"/>
</Grid.RowDefinitions>
<Grid Grid.Row="0" ScrollViewer.CanContentScroll="True">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="{Binding ElementName=grid, Path=RowHeaderWidth}" />
<ColumnDefinition Width="{Binding ElementName=TypeCol, Path=ActualWidth}" />
<ColumnDefinition Width="{Binding ElementName=NCRCol, Path=ActualWidth}" />
<ColumnDefinition Width="{Binding ElementName=StatusCol, Path=ActualWidth}" />
<ColumnDefinition Width="{Binding ElementName=PStkCol, Path=ActualWidth}" />
<ColumnDefinition Width="{Binding ElementName=DfStkCol, Path=ActualWidth}" />
<ColumnDefinition Width="{Binding ElementName=QtyCol, Path=ActualWidth}" />
<ColumnDefinition Width="{Binding ElementName=DfCol, Path=ActualWidth}" />
<ColumnDefinition Width="{Binding ElementName=DfDateCol, Path=ActualWidth}" />
<ColumnDefinition Width="{Binding ElementName=b1, Path=ActualWidth}" />
<ColumnDefinition Width="{Binding ElementName=CCodeCol, Path=ActualWidth}" />
<ColumnDefinition Width="{Binding ElementName=ByCol, Path=ActualWidth}" />
<ColumnDefinition Width="{Binding ElementName=InvAssignCol, Path=ActualWidth}" />
<ColumnDefinition Width="{Binding ElementName=InvCommentsCol, Path=ActualWidth}" />
<ColumnDefinition Width="{Binding ElementName=b2, Path=ActualWidth}" />
<ColumnDefinition Width="{Binding ElementName=CStepNoCol, Path=ActualWidth}" />
<ColumnDefinition Width="{Binding ElementName=CActionCol, Path=ActualWidth}" />
<ColumnDefinition Width="{Binding ElementName=CAssignCol, Path=ActualWidth}" />
<ColumnDefinition Width="{Binding ElementName=CReqCol, Path=ActualWidth}" />
<ColumnDefinition Width="{Binding ElementName=CComplCol, Path=ActualWidth}" />
<ColumnDefinition Width="{Binding ElementName=MCostCol, Path=ActualWidth}" />
<ColumnDefinition Width="{Binding ElementName=LabourCol, Path=ActualWidth}" />
<ColumnDefinition Width="{Binding ElementName=b3, Path=ActualWidth}" />
<ColumnDefinition Width="{Binding ElementName=PStepCol, Path=ActualWidth}" />
<ColumnDefinition Width="{Binding ElementName=PActionCol, Path=ActualWidth}" />
<ColumnDefinition Width="{Binding ElementName=PAssignedCol, Path=ActualWidth}" />
<ColumnDefinition Width="{Binding ElementName=PReqCol, Path=ActualWidth}" />
<ColumnDefinition Width="{Binding ElementName=PCompCol, Path=ActualWidth}" />
<ColumnDefinition Width="{Binding ElementName=PDateCol, Path=ActualWidth}" />
</Grid.ColumnDefinitions>
<TextBlock Text="INVESTIGATION" Height="20" Grid.Column="10" Grid.ColumnSpan="5" Grid.Row="0"/>
<TextBlock Text="CORRECTIVE ACTION" Height="20" Grid.Column="15" Grid.ColumnSpan="8" Grid.Row="0" />
<TextBlock Text="PREVENTATIVE ACTION" Height="20" Grid.Column="23" Grid.ColumnSpan="6" Grid.Row="0"/>
</Grid>
<DataGrid x:Name="grid" Grid.Row="1" Grid.Column="0" CanUserAddRows="False" HorizontalAlignment="Center" VerticalAlignment="Top" Width="1524" Canvas.Top="44" HeadersVisibility="Column" AutoGenerateColumns="False" CanUserReorderColumns="False" CanUserResizeColumns="False" Canvas.Left="-180" CellEditEnding="grid_CurrentCellChanged" Margin="0,0,881,0">
<DataGrid.Columns>
<DataGridTextColumn x:Name="TypeCol" Binding="{Binding Type}" Header="Type" Width="50" IsReadOnly="True"/>
<DataGridTextColumn x:Name="NCRCol" Binding="{Binding NCR}" Header="NCR" Width="100" IsReadOnly="True"/>
<DataGridTextColumn x:Name="StatusCol" Binding="{Binding Status}" Header="Status" Width="50"/>
<DataGridTextColumn x:Name="PStkCol" Binding="{Binding PStkCode}" Header="Parent Stock Code" Width="120 " IsReadOnly="True"/>
<DataGridTextColumn x:Name="DfStkCol" Binding="{Binding DfStkCode}" Header="Defective Stock Code" Width="125" IsReadOnly="True"/>
<DataGridTextColumn x:Name="QtyCol" Binding="{Binding Qty}" Header="Quantity" Width="120" IsReadOnly="True"/>
<DataGridTextColumn x:Name="DfCol" Binding="{Binding Defect}" Header="Defect" Width="100" IsReadOnly="True"/>
<DataGridTextColumn x:Name="DfDateCol" Binding="{Binding Defect Date}" Header="Defect Date" Width="100" IsReadOnly="True"/>
<DataGridTemplateColumn x:Name="b1" Width="20" IsReadOnly="True"/>
<DataGridTextColumn x:Name="CCodeCol" Header ="Cause Code" Width ="80" />
<DataGridTextColumn x:Name="ByCol" Header ="By" Width ="80"/>
<DataGridTextColumn x:Name="InvAssignCol" Header ="Assigned To" Width ="100" />
<DataGridTextColumn x:Name="InvCommentsCol" Header ="Comments" Width ="100" />
<DataGridTemplateColumn x:Name="b2" Width="20" IsReadOnly="True"/>
<DataGridTextColumn x:Name="CStepNoCol" Header ="Step No" Width ="60" />
<DataGridTextColumn x:Name="CActionCol" Header ="Action" Width ="100" />
<DataGridTextColumn x:Name="CAssignCol" Header ="Assigned To" Width ="100"/>
<DataGridTextColumn x:Name="CReqCol" Header ="Reqd By" Width ="100" />
<DataGridTextColumn x:Name="CComplCol" Header ="Completed By" Width ="100"/>
<DataGridTextColumn x:Name="MCostCol" Header="Material Cost($)" Width="100"/>
<DataGridTextColumn x:Name="LabourCol" Header="Labour (Hrs)" Width="100"/>
<DataGridTemplateColumn x:Name="b3" Width="20" IsReadOnly="True"/>
<DataGridTextColumn x:Name="PStepCol" Header="Step No" Width="60"/>
<DataGridTextColumn x:Name="PActionCol" Header="Action" Width="100"/>
<DataGridTextColumn x:Name="PAssignedCol" Header="Assigned To" Width="100"/>
<DataGridTextColumn x:Name="PReqCol" Header="Reqd By" Width="100"/>
<DataGridTextColumn x:Name="PCompCol" Header="Completed By" Width="100"/>
<DataGridTextColumn x:Name="PDateCol" Header="Completed Date" Width="100"/>
</DataGrid.Columns>
</DataGrid>
</Grid>
</Canvas>
我按照你說的,目前發生的事情,但你可以指定你怎麼會喜歡這個改變?你想要一切使用滾動條?你不想使用滾動條? – MoonBoots89
對不起,基本上我想要的是一個單一的滾動條來控制具有數據的數據網格行和包含超級標題的行,在這個階段有一個數據網格行的滾動條。我可以得到滾動條的標題出現,但它不起作用 –