単純なscrollviewer(pnlDayScroller)を作成しましたが、水平スクロールを実行するために別の水平スクロールバー(関連付けられたスクローラー)が必要です。以下のコードですべて動作します。関連するスクローラーの可視性をバインドする必要があります。
これを常に非表示に設定しているため、これをスクロールビューアの水平テンプレート部分の可視性プロパティに単純にバインドすることはできません。これを行うために私が考えることができる唯一の方法は、関連するスクローラーの可視性を次のような関数にバインドすることです。
If associatedScroller.scrollableWidth > 0 then
associatedScroller.visibility = visibility.visible
else
associatedScroller.visibility = visibility.collapsed
end if
これは可能ですか?もしそうなら、どうすればいいですか?
Private Sub pnlDayScroller_Loaded(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles pnlDayScroller.Loaded
Dim binViewport, binMax, binMin, binSChange, binLChange As Binding
Dim horizontalScrollBar As Primitives.ScrollBar = CType(pnlDayScroller.Template.FindName("PART_HorizontalScrollBar", pnlDayScroller), Primitives.ScrollBar)
binViewport = New Binding("ViewportSize")
binViewport.Mode = BindingMode.OneWay
binViewport.Source = horizontalScrollBar
associatedScroller.SetBinding(Primitives.ScrollBar.ViewportSizeProperty, binViewport)
binMax = New Binding("Maximum")
binMax.Mode = BindingMode.OneWay
binMax.Source = horizontalScrollBar
associatedScroller.SetBinding(Primitives.ScrollBar.MaximumProperty, binMax)
binMin = New Binding("Minimum")
binMin.Mode = BindingMode.OneWay
binMin.Source = horizontalScrollBar
associatedScroller.SetBinding(Primitives.ScrollBar.MinimumProperty, binMin)
binSChange = New Binding("SmallChange")
binSChange.Mode = BindingMode.OneWay
binSChange.Source = horizontalScrollBar
associatedScroller.SetBinding(Primitives.ScrollBar.SmallChangeProperty, binSChange)
binLChange = New Binding("LargeChange")
binLChange.Mode = BindingMode.OneWay
binLChange.Source = horizontalScrollBar
associatedScroller.SetBinding(Primitives.ScrollBar.LargeChangeProperty, binLChange)
End Sub
Private Sub associatedScroller_Scroll(ByVal sender As System.Object, ByVal e As System.Windows.RoutedPropertyChangedEventArgs(Of Double)) Handles associatedScroller.ValueChanged
pnlDayScroller.ScrollToHorizontalOffset(e.NewValue)
end sub
フォローアップ(JustABillに感謝):
このコードを上記のpnlDayScrollerサブに追加しました(scrollableWidthはscrollviewerのプロパティであり、scrollbarではないことを発見しましたが、maximumプロパティは代わりに使用できる結果を提供します)
binVisibility = New Binding("Maximum")
binVisibility.Mode = BindingMode.OneWay
binVisibility.Source = horizontalScrollBar
binVisibility.Converter = New ScrollableConverter
associatedScroller.SetBinding(Primitives.ScrollBar.VisibilityProperty, binVisibility)
そして私はこのクラスを作成しました
Public Class ScrollableConverter
Implements IValueConverter
Public Function Convert(ByVal value As Object, ByVal targetType As Type, ByVal parameter As Object,
ByVal culture As System.Globalization.CultureInfo) As Object Implements IValueConverter.Convert
Dim dblMaximum As Double
If targetType IsNot GetType(Visibility) Then
Throw New InvalidOperationException("The target must be a visibility")
Else
dblMaximum = CType(value, Double)
Debug.WriteLine("Value of double is " & dblMaximum)
If dblMaximum > 0 Then
Return Visibility.Visible
Else
Return Visibility.Collapsed
End If
End If
End Function
Public Function ConvertBack(ByVal value As Object, ByVal targetType As Type, ByVal parameter As Object,
ByVal culture As System.Globalization.CultureInfo) As Object Implements IValueConverter.ConvertBack
Throw New NotSupportedException()
End Function
End Class
そして、問題は解決されました。