Partial Public Class ScrollViewerThumbnail
Inherits Windows.Controls.Control
Public Sub New()
DefaultStyleKeyProperty.OverrideMetadata(TypeOf(ScrollViewerThumbnail), New Windows.FrameworkPropertyMetadata(TypeOf(ScrollViewerThumbnail)))
End Sub
Public ReadOnly ScrollViewerProperty = Windows.DependencyProperty.Register("ScrollViewer", ScrollViewer.GetType, TypeOf(ScrollViewerThumbnail), New Windows.UIPropertyMetadata(Nothing))
Public Property ScrollViewer() As Windows.Controls.ScrollViewer
Get
Return
End Get
Set(ByVal value As Windows.Controls.ScrollViewer)
End Set
End Property
End Class
I guess it comes down to translating the C# function typeof.... it's not TypeOf() however obvious it seems...
I haven't really looked at the code at all, but this is what I get if you take the code you linked to and run it through the code converter here:
Code:
Public Class ScrollViewerThumbnail
Inherits Control
Shared Sub New()
DefaultStyleKeyProperty.OverrideMetadata(GetType(ScrollViewerThumbnail), New FrameworkPropertyMetadata(GetType(ScrollViewerThumbnail)))
End Sub
Public Property ScrollViewer() As ScrollViewer
Get
Return DirectCast(GetValue(ScrollViewerProperty), ScrollViewer)
End Get
Set(ByVal value As ScrollViewer)
SetValue(ScrollViewerProperty, value)
End Set
End Property
' Using a DependencyProperty as the backing store for ScrollViewer. This enables animation, styling, binding, etc...
Public Shared ReadOnly ScrollViewerProperty As DependencyProperty = DependencyProperty.Register("ScrollViewer", GetType(ScrollViewer), GetType(ScrollViewerThumbnail), New UIPropertyMetadata(Nothing))
End Class
Private Const PART_Highlight As String = "PART_Highlight"
Public Overrides Sub OnApplyTemplate()
MyBase.OnApplyTemplate()
Dim partHighlight As Windows.Controls.Primitives.Thumb
partHighlight = DirectCast(Me.Template.FindName(PART_Highlight, Me), Windows.Controls.Primitives.Thumb)
partHighlight.DragDelta += partHighlight_DragDelta
End Sub
Private Sub partHighlight_DragDelta(ByVal sender As Object, ByVal e as Windows.Controls.Primitives.DragDeltaEventArgs)
ScrollViewer.ScrollToVerticalOffset(ScrollViewer.VerticalOffset + e.VerticalChange)
ScrollViewer.ScrollToHorizontalOffset(ScrollViewer.HorizontalOffset + e.HorizontalChange)
End Sub
The bold line is the one giving me trouble, I can see it's not right, but I don't really understand what it is supposed to do, so have no idea what it should be...
''Controls' is an undeclared namespace. Line x, position y.' XML is not valid.
The type 'Controls.ScrollViewerThumbnail'was not found. Verify that you are not missing an assembly reference and that all referenced assemblies have been built.
Imports System.Windows.Media
Partial Public Class ScrollViewerThumbnail
Inherits Windows.Controls.Control
Public Sub New()
DefaultStyleKeyProperty.OverrideMetadata(GetType(ScrollViewerThumbnail), New Windows.FrameworkPropertyMetadata(GetType(ScrollViewerThumbnail)))
End Sub
Public Property ScrollViewer() As Windows.Controls.ScrollViewer
Get
Return DirectCast(GetValue(ScrollViewerProperty), Windows.Controls.ScrollViewer)
End Get
Set(ByVal value As Windows.Controls.ScrollViewer)
SetValue(ScrollViewerProperty, value)
End Set
End Property
Public Property HighlightFill() As Brush
Get
Return DirectCast(GetValue(HighlightFillProperty), Brush)
End Get
Set(ByVal value As Brush)
SetValue(HighlightFillProperty, value)
End Set
End Property
Public Shared ReadOnly ScrollViewerProperty As Windows.DependencyProperty = Windows.DependencyProperty.Register("ScrollViewer", GetType(ScrollViewerThumbnail), GetType(ScrollViewerThumbnail), New Windows.UIPropertyMetadata(Nothing))
Public Shared ReadOnly HighlightFillProperty As Windows.DependencyProperty = Windows.DependencyProperty.Register("HighlightFill", GetType(Brush), GetType(ScrollViewerThumbnail), New Windows.UIPropertyMetadata(New SolidColorBrush(Color.FromArgb(128, 255, 255, 0))))
Private Const ThumbName As String = "ThumbHighlight"
Public Overrides Sub OnApplyTemplate()
MyBase.OnApplyTemplate()
Dim PartHighlight As Windows.Controls.Primitives.Thumb
PartHighlight = DirectCast(Me.Template.FindName(ThumbName, Me), Windows.Controls.Primitives.Thumb)
AddHandler PartHighlight.DragDelta, AddressOf PartHighlight_DragDelta
End Sub
Private Sub PartHighlight_DragDelta(ByVal sender As Object, ByVal e As Windows.Controls.Primitives.DragDeltaEventArgs)
ScrollViewer.ScrollToVerticalOffset(ScrollViewer.VerticalOffset + e.VerticalChange)
ScrollViewer.ScrollToHorizontalOffset(ScrollViewer.HorizontalOffset + e.HorizontalChange)
End Sub
End Class
How do I do that? Can't find a property z-index.....
[edit]
I don't think this will help though. My window is divided into a 2x2 grid:
* A TabControl in (0,0)
* The ScrollViewer in (0,1) with RowSpan=2
* The ScrollViewerThumbnail in (1,0)
And that's all.... So there's nothing to get in the way of the ScrollViewerThumbnail.
When I put the cursor in the <Controls:ScrollViewerThumbnail .... /> tag, the correct area in my window gets highlighted, so I think it is showing up, it's just not displaying anything. :S
[/edit]
I agree that its unlikely it is the Z index in light of what you have just said, but to make sure, you can set the z index of a control by code like this:
vb Code:
Grid.SetZIndex(Grid_Name_Here, 10) 'sets the grid to being 10th in the z order
Note that not all controls have that method available though (which is why I have used a Grid as an example as I know that works), so its possible the Thumb control does not.
I did some more debugging, and I when I pause the application and add the ScrollViewerThumbnail to my watch window, I see that the ScrollViewer property (i.e. the reference to the big map) is Nothing. I have no idea how this can be, the reference is right there in the XAML, and I practically copy/pasted that from the site.
I finally got it to work!!!
First I noticed I was using a Custom Control instead of a straighforward Class, so I changed that, but no luck.
Then I tried setting the ScrollViewer property from code and found an error in the line:
Code:
Public Shared ReadOnly ScrollViewerProperty As Windows.DependencyProperty = Windows.DependencyProperty.Register("ScrollViewer", GetType(ScrollViewerThumbnail), GetType(ScrollViewerThumbnail), New Windows.UIPropertyMetadata(Nothing))
It should be:
Code:
Public Shared ReadOnly ScrollViewerProperty As Windows.DependencyProperty = Windows.DependencyProperty.Register("ScrollViewer", GetType(ScrollViewer), GetType(ScrollViewerThumbnail), New Windows.UIPropertyMetadata(Nothing))
But still, not working!
Then I copy/pasted the XAML into Generic.xaml again, and voila. No idea what was wrong with it, and frankly I'm fed up with staring at this particular piece of code, so I'll just assume a typo somewhere and leave it at that.
On that note, it is worth pursuing a CodeBank for WCF, WPF etc related code samples? That way submissions like this could be grouped in one place. Just a thought?
@Hamish, you can create your own thread in the code bank, follow the sticky's instructions for rules etc, and just drop your code in there, with example usage etc.