How can Combobox selection change Checkbox isChecked

1067
4
Jump to solution
03-07-2022 09:58 AM
JonathanDewalt
New Contributor II

Hello,  I can do this blindfolded with the old ArcObjects and windows forms.  But am either getting old or something because it has me stumped with the new pro DAML model.   I have a combobox defined in DAML that resides on the ribbon.  I also have a checkbox.  The comobox contains a list of point-based feature layers.  What I want to happen, is when a user selects a layer from the combobox, I want the checkbox isChecked to be set to true if the selected layer contains selected features.  I have no problem getting the selection feature count but I have no idea how to get to the checkbox to set its value.  Is there a way to reference the checkbox from the combobox?  I have also created a variable in the module that both can see controls can see but changes to the variable don't migrate back to the checkbox.  In the old days, I would either directly reference the checkbox from the combobox or have a public event that the checkbox is listening for.

0 Kudos
1 Solution

Accepted Solutions
CharlesMacleod
Esri Regular Contributor

Ribbon controls defined in DAML are a bit different from _user_ controls defined in XAML (ie via WPF) as u mention. One possibility is to store a reference to the ribbon checkbox in your Module. U will also have to deal with the situation of a/the combo box being clicked before the checkbox on the ribbon has been loaded (ie Ribbon controls are typically null until they are clicked).

Something like....

internal class Module1 : Module
  {
    private static Module1 _this = null;
    //Capture the checkbox here
    public CheckBox CheckBox { get; set; } = null;

//Eg a ribbon or "DAML" combo
internal class ComboBox1 : ComboBox {
 ...
 protected override void OnSelectionChange(ComboBoxItem item) {
   //have we been "made" before the checkbox?
   if (Module1.Current.CheckBox == null)
    //load it then
    _  = FrameworkApplication.GetPlugInWrapper("ProAppModule1_CheckBox1");

   //Check/Uncheck
   Module1.Current.CheckBox.IsChecked = !Module1.Current.CheckBox.IsChecked;
   ...

//DAML Checkbox on the ribbon
internal class CheckBox1 : CheckBox {

  public CheckBox1() {
    //wire up the Module property
    Module1.Current.CheckBox = this;
  }
  //handle on click for when the user _does_ actually click it
  protected override void OnClick() {
    //TODO - whatever u need to do to keep everything in-sync
    //...
    base.OnClick();
  }

 

 

 

 

 

View solution in original post

0 Kudos
4 Replies
DHuantes
New Contributor III

Yes.  Completely agree.  XAML is definitely not as intuitive as WinForms but works well once you figure it out... 🙂 

Unfortunately, I've not placed any checkboxes or combo boxes on the Ribbon as of yet.  I've mostly used the Ribbon a button to launch dockpane's and dialogs or a MapTool.  On Dockpane's and Dialog's you get a code behind (i.e. *.xaml.cs that is paired with the *.xaml page).  

 

I can almost picture what you're trying to do and see that it would be done using the Config.daml for your Add-In but if you could post a picture of the UI you're trying to implement that would help.  Also I think it is a bit easier if it's on a Dockpane or in a custom dialog but just my $0.02.  Where is the checkbox?  Is it on another button on the ribbon or somewhere else? Look forward to seeing what you got.

In that environment (i.e. dockpane or dialog) you assign a name to the CheckBox and you can reference it in your code-behind by that name as shown below: 

// Checkbox in XAML with Name (Sample.xaml)
// ...
<CheckBox x:Name="cbMyCheckBox" IsChecked="false" />
//...

// The checkbox in XAML above can be referenced in Sample.xaml.cs
// As shown below and the IsChecked is a read/write boolean property
void SomeMethod()
{
     cbMyCheckBox.IsChecked = true;
}

May not be what you're asking but thought I'd show it anyway... 

0 Kudos
JonathanDewalt
New Contributor II

Hello,  I attached a screen shot for your reference.  I started off with a dockpane and the combobox and checkbox combination works.  I have a variable that is set when the user selects a point layer from the combobox.  The variable is true/false as to whether the selected layer contains selected features.  The checkbox uses databinding and connects its IsChecked setting to the variable.  This works.  Now as I have been developing this tool I  decided that perhaps all the users settings that appear in the dockpane should be on a properties page instead.  Now if i move all my properties off the dockpane, there isn't much left so I moved the combobox and two checkboxes along with the run button to the ribbon.  I just can't get the checkboxes to change when the combobox item is changed. 

ComboBox.png

This is what the tool creates

Sample.png

 

0 Kudos
GintautasKmieliauskas
Regular Contributor II

Hi,

 For your solution it is better to use "customControl" as in sample RibbonControls . You have to copy all controls you need from docpane xaml to custom control xaml and all code related to xaml to custom control viewmodel. 

0 Kudos
CharlesMacleod
Esri Regular Contributor

Ribbon controls defined in DAML are a bit different from _user_ controls defined in XAML (ie via WPF) as u mention. One possibility is to store a reference to the ribbon checkbox in your Module. U will also have to deal with the situation of a/the combo box being clicked before the checkbox on the ribbon has been loaded (ie Ribbon controls are typically null until they are clicked).

Something like....

internal class Module1 : Module
  {
    private static Module1 _this = null;
    //Capture the checkbox here
    public CheckBox CheckBox { get; set; } = null;

//Eg a ribbon or "DAML" combo
internal class ComboBox1 : ComboBox {
 ...
 protected override void OnSelectionChange(ComboBoxItem item) {
   //have we been "made" before the checkbox?
   if (Module1.Current.CheckBox == null)
    //load it then
    _  = FrameworkApplication.GetPlugInWrapper("ProAppModule1_CheckBox1");

   //Check/Uncheck
   Module1.Current.CheckBox.IsChecked = !Module1.Current.CheckBox.IsChecked;
   ...

//DAML Checkbox on the ribbon
internal class CheckBox1 : CheckBox {

  public CheckBox1() {
    //wire up the Module property
    Module1.Current.CheckBox = this;
  }
  //handle on click for when the user _does_ actually click it
  protected override void OnClick() {
    //TODO - whatever u need to do to keep everything in-sync
    //...
    base.OnClick();
  }

 

 

 

 

 

0 Kudos