Select to view content in your preferred language

How to inactivate a split command, before the split process completion

1427
6
07-20-2011 02:49 PM
MuralidharMoka
Emerging Contributor
Here is the normal process for split.

The user clicks on split button, it activates the split command.
Then he draws the splitting line across a graphic. Then split happens.
Now the split command becomes inactive(automatically as usual)
I now do some things in edit completed.

These above are the usual steps

But say the user does this

The user clicks on split button. split command gets activated
Now the user does not draw a line.(say he does a mistake). He clicks on some save button
Now I want the split to get inactivated.
How can I do this. I tried like this  using the code editor.CancelActive.
But still after running that code , the user is still able to draw the splitting line.


Here is my Xaml & C sharp
                    <Grid Grid.Column="4">
                            <StackPanel VerticalAlignment="Center" Width="94" Orientation="Vertical"  ToolTipService.ToolTip="Click to Split Field">
                                <HyperlinkButton Name="CutHyperlinkButton" Click="CutHyperlinkButton_Click"   IsTabStop="False">
                                    <Image Cursor="Hand" Name="SplitFieldUnselectedImage"  Stretch="None"  Source="/Images/splitfield_unselected.png"  />                                 
                                </HyperlinkButton>
                            </StackPanel>
                        </Grid>


            <StackPanel   Height="51" x:Name="SplitFieldDrawingTools" Visibility="Collapsed" Background="White" VerticalAlignment="Top"  DataContext="{Binding ElementName=MyEditor}">
                <StackPanel VerticalAlignment="Center" Width="81" Orientation="Vertical" MouseLeftButtonUp="CancelSplitChangesAction_MouseLeftButtonUp" ToolTipService.ToolTip="Click to Undo Split Field                        changes">
                    <HyperlinkButton Name="SplitCancelButton" Click="UndoSplitButton_Click" Margin="0" Padding="0">
                        <Image Cursor="Hand"   Source="/Images/toolbar/undosplit_unselected.png" />
                    </HyperlinkButton>
                </StackPanel>
                <StackPanel VerticalAlignment="Center" Width="81" Orientation="Vertical" MouseLeftButtonUp="SaveChangesAction_MouseLeftButtonUp" ToolTipService.ToolTip="Click to Save Changes">
                    <HyperlinkButton Name="SaveSplitHyperlinkButton" Click="SaveSplitHyperlinkButton_Click" Command="{Binding Save}" Margin="0" Padding="0">
                        <Image Cursor="Hand" Tag="change"  Source="/Images/toolbar/change_unselected.png" />
                    </HyperlinkButton>
                </StackPanel>
            </StackPanel>


private void CutHyperlinkButton_Click(object sender, RoutedEventArgs e)
        {
            CutHyperlinkButton.Command = editor.Cut;

                ///do something here
          
        }


  private void SaveSplitHyperlinkButton_Click(object sender, RoutedEventArgs e)
        {
            //do some things like close menus

            CutHyperlinkButton.Command = editor.CancelActive; ( This does not work)
        }



  void editor_EditCompleted(object sender, Editor.EditEventArgs e)
        {
            //do some thing
        }
0 Kudos
6 Replies
MuralidharMoka
Emerging Contributor
To exlain my problem easily.
Please look at this sample and do the following steps
http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#EditToolsExplicitSave

1.Click add polygon
2.Click new selection and select the polygon
3.Click cut Selected
4.Now dont draw the splitting line across the graphic
5.Instead Click on Delete Selected button
6.Now try to draw the splitting line ( it is still there, at the 5th action I want to disable the cut command)


Muralidhar Moka
0 Kudos
JenniferNery
Esri Regular Contributor
To cancel a command in code:
if(editor.CancelActive.CanExecute(null))
     editor.CancelActive.Execute(null);


However in the scenario that you have described, Cut is no longer active, since DeleteSelected was the last command activated. The polyline (cutter) is drawn while Cut was the active command. It is expected then that you can continue to draw that polyline but this will not result to a cut since the target feature has been deleted.

To disable an active draw, you can create enable another draw object. This behavior is seen in this sample: http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#ToolkitTemplatePicker When you choose a fill symbol template to add a feature and before completing the draw, you activate another fill symbol template, the previous draw is canceled.
0 Kudos
MuralidharMoka
Emerging Contributor
Thanks for the help. This solved my problem.
Muralidhar Moka
0 Kudos
MuralidharMoka
Emerging Contributor
Thanks for the help. This solved my problem.
Muralidhar Moka


Hi Jenniefer,

When I run this command. This disabled the CutHyperlinkButton.
How do I enable it again.

becuase if I want to do my next split I  need to click on this button
and run this method

private void CutHyperlinkButton_Click(object sender, RoutedEventArgs e)
{
CutHyperlinkButton.Command = editor.Cut;

///do something here

}

Thanks
Muralidhar Moka
0 Kudos
MuralidharMoka
Emerging Contributor
Hi Jennifer
Sorry, If I did not explain my problem well.

The below(your) code worked well and it stopped the split line
your  Code:
if(editor.CancelActive.CanExecute(null))
     editor.CancelActive.Execute(null);

But now It disables the split button it self.It does not enabled until I split that polygon.
I explained my problem in steps below.

What I do is.
1) I select the polygon before doing the split command
2)   I click on split button command with has (editor.cut in it), which is below method
    private void CutHyperlinkButton_Click(object sender, RoutedEventArgs e)
     {
        CutHyperlinkButton.Command = editor.Cut;

        ///do something here

        }
3) Next I dont draw the split line.
4) I hit on the SaveChanges Button. (code of it below)

    private void SaveSplitHyperlinkButton_Click(object sender, RoutedEventArgs e)
        {
          //I copied your lines of code here
         if(editor.CancelActive.CanExecute(null))
          editor.CancelActive.Execute(null);   
         //here I unselect the graphic
        }
   Note: This worked well it disabled the split line
5) After this I observed that the

     SaveSplitHyperlinkButton is disabled.

6) I observed that it gets enabled only when I select the same polygon back again, and if I split that one again. Then only the button gets enabled for splitting other polygons.

Cannot figure why the split command remebers the selected polygon to be split.

Is there any way, I can enable the SaveSplitHyperlinkButton  back again with code.

Thanks for the help.
Muralidhar Moka
0 Kudos
JenniferNery
Esri Regular Contributor
Please try the following sample: http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#EditToolsExplicitSave.

You should find the same behavior that Cut command is only enabled when there is a selected Polyline/Polygon unless AutoSelect is checked, then it is always enabled.

In order to enable Cut again, you need to make a selection first.
0 Kudos