Change background property of shape in code behind

2 posts, 0 answers
  1. Michael
    Michael avatar
    39 posts
    Member since:
    Jan 2012

    Posted 14 Feb 2013 Link to this post

    Hy telerik team,

    i want to change the background of a shape in code behind.

    I have a class "ShapeBase". In ShapeBase i have a boolean property "IsMouseOver".
    If IsMouseOver is true i want to change the background. 
    If it is false the background should be set to my default background.

    Is that possible?
    Setting the "Background" property doesn't work.

    cheers mike!
  2. Pavel R. Pavlov
    Pavel R. Pavlov avatar
    1236 posts

    Posted 19 Feb 2013 Link to this post

    Hi mike,

    I am not sure that I understand your requirements. Can you please elaborate on your scenario? Why do you need to change the background of the shape in code behind? As far as I understand you need to implement a custom visual state on mouse over. Please note that such behavior can be easily achieved by editing the default style of the RadDiagramShape. In your case this might be a better approach. You can find more information about extracting templates in this article.

    For your convenience I extracted and edited the default template of the RadDiagramShape. Also, I implemented an animation in the MouseOver visual state. Please note that the animation will be executed only during the MouseOver visual state. This means that once the mouse isn't over the shape, the background color of the control will reflect its normal VisualState settings - basically the default background value.

    I changed the MouseOver state of a RadDiagramShape by adding the following code:

    <VisualState x:Name="MouseOver">
            <ObjectAnimationUsingKeyFrames Duration="0"
                <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource MyBrush}" />

    Please take a look at the attached project and let me know if it works for you.

    All the best,
    Pavel R. Pavlov
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Back to Top