Posted 14 June 2019, 8:42 am EST
Hi Esha,
Thanks for your quick response. I am able to get a LinearGradientBrush from the theme using the following code:
Public Function getThemeBackgroundBrush(path As String,
defaultColor As Color,
Optional brushRectangle As Rectangle = Nothing,
Optional theme As C1Theme = Nothing) As Brush
Dim tbb As ThemeBrushBase = Nothing
If theme Is Nothing Then theme = getApplicationTheme()
Dim bg = theme.GetBackgroundBrushStr(path)
ThemeBrushBase.TryDecodeFromString(bg, tbb)
If tbb Is Nothing Then
defaultColor = getThemeBackgroundColor(path)
Return New SolidBrush(defaultColor)
Else
If brushRectangle.Width = 0 Then
brushRectangle = New Rectangle(0, 0, 16, 16)
End If
Dim brush = tbb.GetBrush(brushRectangle)
If brush Is Nothing Then
defaultColor = getThemeBackgroundColor(path)
brush = New SolidBrush(defaultColor)
End If
'If brush.GetType = GetType(Drawing2D.LinearGradientBrush) Then
' Dim bb = DirectCast(brush, System.Drawing.Drawing2D.LinearGradientBrush)
' Dim tt = DirectCast(tbb, ThemeMultiColorLinearBrush)
' Console.WriteLine("getThemeBackgroundBrush r:{0}", brushRectangle.ToString)
'End If
Return brush
End If
End Function
The only bug is that I cannot figure out how your developers calculate the “location” of the brushRectangle used by ThemeBrushBase to create the brush used by the treeview to paint the background. The size of the brushRectangle is always correct, but the location may or may not be. I use the RowPanel.Bounds for the location and size for the brush calculation. Perhaps there is some other rectangle I should be using.
As for “It’s by design. We don’t use brushes for custom styles in winforms”, that is a cop out. I can’t believe that the practicality of having a themed treeview should be lost simply because of using the advanced functionality of a CustomContentPresenter.