ProWindow Control Basics Help

1195
3
Jump to solution
07-06-2022 11:17 AM
RichardFairhurst
MVP Honored Contributor

I am in the process of converting an Add-In from VB ArcObjects to an ArcGIS Pro Add-In written in C#.  The original Add-In was designed using Windows Forms as modal Dialogs.  The documentation for the Event Model and Properties of Windows Forms was easy to understand and implement for the adding and using controls on the form.

The ProWindow UI template appears to be the closest equivalent to a Windows Form for the ArcGIS Pro Add-In.  I have created a project with a ProWindow and added WPF controls that replicate my original Windows Form dialog, but I I don't know anything about what to do after that.  The Microsoft documentation examples for WPF are causing errors and I don't understand how to connect the dots.

For example, how do I add a button to a ProWindow and handle the button Click event to open a MessageBox saying the button was clicked as the stub code that I can eventually replace.

 

Tags (3)
0 Kudos
1 Solution

Accepted Solutions
KenBuja
MVP Esteemed Contributor

Here's how I have my ProWindow coded. I have several button that have their Click method in the xaml.cs file. First, I dragged a Button from the Common WPF Controls Toolbox onto the Window to create a Cancel button, which will just close the window

wpf1.png

Then I modified the code in the .xaml file to format it and to add in some properties and events. Simply by typing in Click, Visual Studios offers to create the stub code

<Button x:Name="Cancel" Margin="10,10,0,5" HorizontalContentAlignment="Center" VerticalContentAlignment="Center"
        Click="Cancel_Click"
        >
  <TextBlock Margin="5,0">Cancel</TextBlock>
</Button>

In the xaml.cs file, I have this code to close the window

    private void Cancel_Click(object sender, RoutedEventArgs e)
    {
      DialogResult = false;
      this.Close();
    }

View solution in original post

0 Kudos
3 Replies
KenBuja
MVP Esteemed Contributor

Here's how I have my ProWindow coded. I have several button that have their Click method in the xaml.cs file. First, I dragged a Button from the Common WPF Controls Toolbox onto the Window to create a Cancel button, which will just close the window

wpf1.png

Then I modified the code in the .xaml file to format it and to add in some properties and events. Simply by typing in Click, Visual Studios offers to create the stub code

<Button x:Name="Cancel" Margin="10,10,0,5" HorizontalContentAlignment="Center" VerticalContentAlignment="Center"
        Click="Cancel_Click"
        >
  <TextBlock Margin="5,0">Cancel</TextBlock>
</Button>

In the xaml.cs file, I have this code to close the window

    private void Cancel_Click(object sender, RoutedEventArgs e)
    {
      DialogResult = false;
      this.Close();
    }

0 Kudos
RichardFairhurst
MVP Honored Contributor

Thanks.  That is what I was looking for.  Is this in the Documentation somewhere?  Even if it is, I like having fundamental coding techniques like this posted in the community, since Google does a much better jobs of listing posts in response to searches than it does pages from the SDK documentation.

0 Kudos
KenBuja
MVP Esteemed Contributor

A lot of what I've learned about WPF has been through other sources. My first stop was here, which gives a very basic understand of how to work with it in general. Once I determined that I needed a modal window for this particular operation, I searched more on Google for information about ProWindows than the SDK documentation

0 Kudos