Themed Treeview with CustomContentPresenter

Posted by: kbj on 13 June 2019, 8:36 am EST

    • Post Options:
    • Link

    Posted 13 June 2019, 8:36 am EST - Updated 4 October 2022, 1:06 am EST

    In an earlier (over a year ago) post I showed that there is a problem with the treeview when it is themed and uses a CustomContentPresenter. This has not been fixed.

    To recap, selected nodes are not painted correctly. The complex workaround works with the significant exception that themes that use gradient backgrounds are not rendered correctly. The brush rectangle “size” is correct, but there does not seem to be a way to calculate the correct brush rectangle “location” (example 1 vs example 3).

  • Posted 14 June 2019, 3:39 am EST

    Hello,

    I could observe the said issue with the 4.0.20191.363 builds. However, observations are a bit different from yours (as per your screenshot).

    I observe a single color on selection of a node, instead of the gradient color effect. An application showing the same is attached for your reference.

    I am getting in touch with the concerned team over the issue (Internal Tracking ID: 341779) and will notify you once I receive any information.

    Regards,

    Esha

    CustomNodes_new_mod.zip

  • Posted 14 June 2019, 4:17 am EST

    Hello,

    As per the development team:

    It’s by design. We don’t use brushes for custom styles in winforms.

    But CustomContentPresenter has Style property. This property supports brushes with gradients. You need to use BackColor2, GammaCorrection, GradientCenter and other properties from Style property.

    Thanks.

  • 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.

  • Posted 17 June 2019, 7:28 am EST

    Hello,

    Allow me to discuss the same with the team.

    Will get back to you once it is done.

    Thanks.

  • Posted 17 June 2019, 10:06 am EST

    Hi,

    I have a workaround for your case, please check attached sample, sorry this code uses System.Reflection. I created request about support gradients from themes for CustomContentPresenter.CustomNodes_gradient.zip

  • Posted 21 June 2019, 9:27 am EST

    Hi Konstantin,

    Your workaround worked perfectly!

    Thanks,

    Kingman

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels