我正在尝试将 a 添加System.Windows.Controls.ScrollViewer
到 a System.Windows.Forms.TabPage
,但是该函数Add(ScrollViewer)
无效。
有没有办法将 ScrollViewer 添加到TabPage
内置的而不是 XAML 中。
谢谢。
我正在尝试将 a 添加System.Windows.Controls.ScrollViewer
到 a System.Windows.Forms.TabPage
,但是该函数Add(ScrollViewer)
无效。
有没有办法将 ScrollViewer 添加到TabPage
内置的而不是 XAML 中。
谢谢。
由于您已将此标记为 WPF,我猜对 Forms 的引用可能是错误的?
这是选项卡中的页面示例 - 其想法是确保工具栏保持在顶部,状态栏保持在底部(不是 MainWindow 状态栏......)并且中间的内容可以滚动。 .
Dim vScrollViewer As New ScrollViewer
Dim vSP As New StackPanel
With vSP
.HorizontalAlignment = Windows.HorizontalAlignment.Stretch
.VerticalAlignment = Windows.VerticalAlignment.Stretch
End With
Dim vInnerGrid As New Grid
vScrollViewer.Content = vSP
vSP.Children.Add(vInnerGrid)
vScollViewer 可以添加到任何其他控件(例如三行网格的中间)
完整的活动
Private Sub Website_WebPage_Page_Initialized(sender As Object, e As System.EventArgs) Handles Me.Initialized
Try
Dim vScrollViewer As New ScrollViewer
Dim vSP As New StackPanel
With vSP
.HorizontalAlignment = Windows.HorizontalAlignment.Stretch
.VerticalAlignment = Windows.VerticalAlignment.Stretch
End With
Dim vInnerGrid As New Grid
vScrollViewer.Content = vSP
vSP.Children.Add(vInnerGrid)
Dim Col1 As New ColumnDefinition
With Col1
.Width = New GridLength(120)
End With
Dim Col2 As New ColumnDefinition
With Col2
.Width = New GridLength(200, GridUnitType.Star)
End With
With Website_WebPage_Grid
.Background = New SolidColorBrush(Colors.White)
End With
With vInnerGrid
.ColumnDefinitions.Add(Col1)
.ColumnDefinitions.Add(Col2)
End With
For i As Integer = 0 To 11 '
Dim vRow As New RowDefinition
With vRow
If i = 11 Then
.Height = New GridLength(200, GridUnitType.Star)
Else
.Height = New GridLength(35)
End If
End With
vInnerGrid.RowDefinitions.Add(vRow)
Next
Dim UpperRow As New RowDefinition
With UpperRow
.Height = New GridLength(35)
End With
Dim MiddleRow As New RowDefinition
With MiddleRow
.Height = New GridLength(200, GridUnitType.Star)
End With
Dim BottomRow As New RowDefinition
With BottomRow
.Height = New GridLength(35)
End With
With Website_WebPage_Grid
.RowDefinitions.Add(UpperRow)
.RowDefinitions.Add(MiddleRow)
.RowDefinitions.Add(BottomRow)
End With
Dim vToolBar As New ToolBar
With vToolBar
.Height = 35
End With
Grid.SetRow(vToolBar, 0)
Website_WebPage_Grid.Children.Add(vToolBar)
Dim EditButton As New Button
If NewRecord = False Then
With EditButton
.Content = ReturnToolBarImage("Edit.png")
.ToolTip = "Edit the record"
.Name = "WebsiteWebPage_EditButton"
End With
RegisterControl(Website_WebPage_Grid, EditButton, EditButton.Name.ToString)
vToolBar.Items.Add(EditButton)
vToolBar.Items.Add(TS_Separator)
End If
Dim SaveUpdateButton As New Button
With SaveUpdateButton
.Name = "WebsiteWebPage_SaveUpdateButton"
If NewRecord = True Then
.Content = ReturnToolBarImage("Record_Insert.png")
.ToolTip = "Save the record"
Else
.Content = ReturnToolBarImageGrey("Record_Update.png")
.ToolTip = "Update the record"
.IsEnabled = False
End If
End With
RegisterControl(Website_WebPage_Grid, SaveUpdateButton, SaveUpdateButton.Name.ToString)
vToolBar.Items.Add(SaveUpdateButton)
vToolBar.Items.Add(TS_Separator)
Dim OutPutLB As New Label
With OutPutLB
.Name = "WebsiteAdministrator_OutputLB"
.HorizontalAlignment = Windows.HorizontalAlignment.Right
.VerticalAlignment = Windows.VerticalAlignment.Center
.FontSize = 10
End With
RegisterControl(Website_WebPage_Grid, OutPutLB, OutPutLB.Name.ToString)
Grid.SetColumnSpan(OutPutLB, 2)
Grid.SetRow(OutPutLB, 0)
vInnerGrid.Children.Add(OutPutLB)
Dim vName As String = "WebsiteAdministrator_"
For i As Integer = 1 To 7
Dim vLabel As New Label
With vLabel
.FontSize = 10
.VerticalAlignment = Windows.VerticalAlignment.Center
.HorizontalAlignment = Windows.HorizontalAlignment.Left
End With
Dim vTB As New CustomControl.TBx
With vTB
.IsNewRecord = NewRecord
'.Width = 200
End With
Select Case i
Case 1
vLabel.Content = "Page Name"
With vTB
.Width = 200
.Name = vName & "PageNameTB"
End With
Case 2
vLabel.Content = "Meta Description"
With vTB
.Width = 600
.Name = vName & "MetaDescriptionTB"
End With
Case 3
vLabel.Content = "Title"
With vTB
.Width = 400
.Name = vName & "TitleTB"
End With
Case 4
vLabel.Content = "Navigate URL"
With vTB
.Width = 400
.Name = vName & "NavigateURLTB"
End With
Case 5
vLabel.Content = "Menu Text"
With vTB
.Width = 200
.Name = vName & "MenuTextTB"
End With
Case 6
vLabel.Content = "Menu ToolTip"
With vTB
.Width = 400
.Name = vName & "MenuToolTipTB"
End With
Case 7
vLabel.Content = "Menu Position"
With vTB
.Width = 100
.Name = vName & "MenuPositionTB"
End With
End Select
Grid.SetColumn(vLabel, 0)
Grid.SetRow(vLabel, i)
Grid.SetColumn(vTB, 1)
Grid.SetRow(vTB, i)
vInnerGrid.Children.Add(vLabel)
vInnerGrid.Children.Add(vTB)
Next
Grid.SetRow(vScrollViewer, 1)
Website_WebPage_Grid.Children.Add(vScrollViewer)
Dim DP As DockPanel = PageStatusBarDP(Website_WebPage_Grid)
Grid.SetRow(DP, 2)
Grid.SetColumnSpan(DP, 2)
Website_WebPage_Grid.Children.Add(DP)
Catch ex As Exception
EmailError(ex)
End Try
End Sub