How to Change Color of Shapes Background in Diagram Not using SettingsPane.(in WPF)

2 Answers 27 Views
Diagram
kim
Top achievements
Rank 1
Iron
kim asked on 12 Jul 2021, 08:07 AM

I Want to Change Color of Shapes Background.

So, I tried change backgound of SelectedItem(SelectedShape) in ViewModel. then, Not changed. 

I checked SelectedShape background property.

It changed.

but Not in the View.

And I tried using behind-code. but I failed.

there's My Code.

1.XAML

<telerik:RadDiagram x:Name="diagram" GraphSource="{Binding GraphSource}" SelectedItem="{Binding SelectedShape, Mode=TwoWay}"

<telerik:RadDiagram.ShapeStyle>
      <Style TargetType="telerik:RadDiagramShape">
           <Setter Property="Position" Value="{Binding Position, Mode=TwoWay}"/>
           <Setter Property="Geometry" Value="{Binding Geometry, Mode=TwoWay}"/>
           <Setter Property="Background" Value="{Binding Background, Mode=TwoWay}"/>
        </Style>
</telerik:RadDiagram.ShapeStyle>

<telerik:RadButton Width="100" Height="30" Content="ChangeColor" Command="{Binding ColorCommand}"/>

 

 

2. ViewModel

private void ChageBrush(object param)
        {
selectedShape.Background = new BrushConverter().ConvertFromString(SelectedBrushColor) as SolidColorBrush;
}

 

thanks.

Martin Ivanov
Telerik team
commented on 15 Jul 2021, 07:14 AM

This setup seems correct. The only thing that I've noticed is that the ChangeBrush method is setting a field named selectedShape. From the SelectedItem's binding it looks like there is also a corresponding property called SelectedShape. In order to reflect the change in the UI, you will probably need to set the property SelectedShape, instead of the field selectedShape. And also to raise the PropertyChanged event.

I've attached a small example showing this approach. I hope it helps.

2 Answers, 1 is accepted

Sort by
0
Psyduck
Top achievements
Rank 4
Bronze
Bronze
Bronze
answered on 12 Jul 2021, 09:18 AM

Hello.

Please check my sample.

There is no problem with my source. The point is to change the background color by clicking on the shape.

I'm guessing there is something wrong with your source binding or something.

 

0
kim
Top achievements
Rank 1
Iron
answered on 13 Jul 2021, 12:12 AM

sorry, I can't...

I think GraphSource problem. I use Toolbox. 

because selectedshape.background property is  changed.

but Not in the View.

Psyduck
Top achievements
Rank 4
Bronze
Bronze
Bronze
commented on 13 Jul 2021, 03:53 AM | edited

Sorry, I didn't understand your problem. You wait for the manager's reply.
Also, if you provide a sample source or image, I'll look into it.
Tags
Diagram
Asked by
kim
Top achievements
Rank 1
Iron
Answers by
Psyduck
Top achievements
Rank 4
Bronze
Bronze
Bronze
kim
Top achievements
Rank 1
Iron
Share this question
or