This is a migrated thread and some comments may be shown as answers.

SelectAll command override not working properly

5 Answers 118 Views
Diagram
This is a migrated thread and some comments may be shown as answers.
ODB
Top achievements
Rank 1
ODB asked on 12 Jun 2018, 11:40 AM

Hi,

My application it's using the diagram and i needed to override the SelectAll() command since i have a special shape in the diagram i dont want to get deleted. This is the first shape added to the diagram. So diagram.Items[0].

I've created the newbinding as follows

 var controlAllBinding = new CommandBinding(DiagramCommands.SelectAll, OnSelectAllExecute, OnCanSelect);            CommandManager.RegisterClassCommandBinding(typeof(PatternDiagram), controlAllBinding);

And the implementation

  private static void OnSelectAllExecute(object sender, ExecutedRoutedEventArgs e)
        {
            var diagram = (sender as PatternDiagram);
            diagram.SelectAll();
            (diagram.Items[0] as RadDiagramShape).IsSelected = false; //This works
            (diagram.Items[1] as RadDiagramShape).IsSelected = false; //This works
        }

        private static void OnCanSelect(object sender, CanExecuteRoutedEventArgs e)
        {
            e.canExecute = true;

            e.Handled = true;
        }

 

However there are a few other items that are not RadDiagramShapes but they inherited from it (ProductShape : RadDiagramShape), there are 2 kinds of this products, the ones that are enabled and the ones that are disabled using the IsEnabled property.

So:

- 2 RadDiagramShapes (Rectangles) [CANNOT BE DELETED]

- 3 ProductShapes (IsEnabled = true) [SHOULD BE DELETED AND SELECTABLE]

- 3 ProductShapes (IsEnabled = false) [SHOULD NOT BE DELETED]

If i try to use a foreach inside the diagram.Items or diagram.SelectedItems and after that i try to check which ones are disabled and when i get them i try to use IsSelected = false (because i dont want them to be selected or deleted) it is not working.

I've tried to modify CanSelect, SelectAll, CanDelete, DeleteExecute, PreviewSelectionChange, SelectionChange with no luck.

Is there maybe about the ProductShape class that is not working? The class only has 2 properties and a predefined style.

 

Is there any way i can achieve this?

Thanks

5 Answers, 1 is accepted

Sort by
0
Vladimir Stoyanov
Telerik team
answered on 14 Jun 2018, 02:24 PM
Hello,

Thank you for the provided code snippets.

Based on them I prepared a sample project which correctly excludes the disabled shapes from selection. Can you check it out and see how it differs from the setup at your side? If I am missing something, may I ask you to share what you are doing differently on your side? 

I am looking forward to your reply.

Regards,
Vladimir Stoyanov
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
0
ODB
Top achievements
Rank 1
answered on 20 Jun 2018, 07:37 AM

Hello Vladimir,

Unfortunately the code you've provided is not working, not even in the project you share with me.

I'm using the latest build of Telerik UI for WPF.

You can find the implementation of the class here:

https://www.dropbox.com/s/1vvoqcwx5q4nmba/ProductShape.cs?dl=0

Do you think there is a workaround available?

Thanks

0
Martin Ivanov
Telerik team
answered on 21 Jun 2018, 07:58 AM
Hello,

I think that the AllowDelete property of the shape might work in your scenario. Can you try setting the property to False on the shapes that you don't want to delete and let me know how it goes? This way you won't need to handle the SelectAll command.

Regards,
Martin Ivanov
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
0
ODB
Top achievements
Rank 1
answered on 21 Jun 2018, 08:59 AM

This does not work since it prevents all shapes from being deleted (Select All + Delete) however it does not remove the disabled ones (or any...)

any other workaround?

Thanks

0
Martin Ivanov
Telerik team
answered on 22 Jun 2018, 11:36 AM
Hello,

The AllowDelete property is available also in the RadDiagramShape class so you can set it per shape. For example:
<telerik:RadDiagramShape AllowDelete="False" IsEnabled="False" />
You can even bind AllowDelete to IsEnabled using the following code:
<telerik:RadDiagramShape AllowDelete="{Binding RelativeSource={RelativeSource Mode=Self}, Path=IsEnabled}" IsEnabled="False" />

Regards,
Martin Ivanov
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
Tags
Diagram
Asked by
ODB
Top achievements
Rank 1
Answers by
Vladimir Stoyanov
Telerik team
ODB
Top achievements
Rank 1
Martin Ivanov
Telerik team
Share this question
or