I have a user of one of my applications who is getting a exception when he uses the Window Classic theme.The exception occurs with the following code:
' Add to listbox and scroll to end
'
Dim iLast As UInt32 = lstStatus.Items.Add(theStatus)
If VisualTreeHelper.GetChildrenCount(lstStatus) > 0 Then
Dim oBorder As Border = VisualTreeHelper.GetChild(lstStatus, 0)
Dim oScrollViewer As ScrollViewer = VisualTreeHelper.GetChild(oBorder, 0)
oScrollViewer.ScrollToBottom()
End If
The exception is thrown on the line assigning the return of "GetChild" to a Border variable. With Windows Classic theme the child control returned is a "ClassicBorderDecorator" and there is no cast to a "Border".
The code is attempting to scroll the listbox to the end to ensure the last added item is visible. Is there a way to handle the Classic theme here?
Note my code was based upon an answer to a question here: WPF ListBox Scroll to end automatically
Sid