Select to view content in your preferred language

Expand/Collapse a toolbar

1484
7
10-05-2010 07:46 AM
ShaningYu
Honored Contributor
I created a toolbar, e.g. the BaseMap Switch tool bar that allows me to switch from one basemap to another.   Then I created a control toolbar.  By clicking a button, the BaseMap Switch toolbar can be either expanded or collapsed.

I wrote a piece of code (see below), but I don't know how to set the value for the BaseMap Toolbar's visibility (or something else). 

If you have the experience, please share it with me.  Thanks.


        private void SetTool(Button btn)
        {
            _Parent = (MainPage)System.Windows.Application.Current.RootVisual;
            _Parent.UnsetTool();
            btn.Background = (Brush)Application.Current.Resources["ButtonHighlightBrush"];
            _btnCurrentTool = btn;
            if (btn == btnMapSwitch)
            {
                //_Parent.MyBaseMaps.Visibility = "Collapse";  // can't be a string, what should be?
            }
            ...
         }
0 Kudos
7 Replies
JenniferNery
Esri Regular Contributor
If you need to set the map's Visibility property, you can do the following (just as you would with any other UIElement)
 
this.MyMap.Visibility = System.Windows.Visibility.Collapsed;

where MyMap is the name of the map.
If you need a specific layer on your map to set it's Visible property, you can do the following:
this.MyMap.Layers["StreetMap"].Visible = false;

where "StreetMap" is the ID of the Layer that you need affected.
0 Kudos
ShaningYu
Honored Contributor
Tried
this._Map.Visibility = System.Windows.Visibility.Collapsed;
but receive NullReferenceException
since this._Map is null
Could you tell what is wrong in the following code:
        private MainPage _Parent;
        private Map _Map;
        public void SetParent(MainPage TheParent)
        {
            // Assumes that MainPage supports SetCursor and UnsetTool
            _Parent = TheParent;
        }

        public void SetMap(Map TheMap)
        {
            _Map = TheMap;
        }
Thanks.
0 Kudos
JenniferNery
Esri Regular Contributor
It is actually very difficult to know where your app can be failing because I do not know the actual program flow. I would suggest putting a breakpoint to where you set _Map, if this code is not hit, then maybe SetMap is not called or the parameter, TheMap, is null.
0 Kudos
ShaningYu
Honored Contributor
Still got error.  I run debug and receive  NullReferenceException at the piece of code below
    public class ToggleVisibilityAction : TargetedTriggerAction<UIElement> {
        protected override void Invoke(object parameter)
        {
            this.Target.Visibility = this.Target.Visibility == Visibility.Visible ?
                Visibility.Collapsed : Visibility.Visible;
        }
    }
Because this.Target is Null.  The related codes are below:
In MainPage.xaml
    <unb:SwitchMap x:Name="MyBaseMaps" ...
In Toolbar.xaml
   <actions:ToggleVisibilityAction TargetName="MainPage.MyBaseMaps" />

I am not sure the parameter I set for the TargetName is correct.
Thanks for you toview it and provide your feedback.
0 Kudos
ShaningYu
Honored Contributor
Problem solved.  Closed.
0 Kudos
EtienneAraya
Emerging Contributor
Problem solved.  Closed.


Can you explain how solve this problem. I have similar issue.


Thank's
0 Kudos
DominiqueBroux
Esri Frequent Contributor
<actions:ToggleVisibilityAction TargetName="MainPage.MyBaseMaps" />

I am not sure the parameter I set for the TargetName is correct.


TargetName must be a name declared in the same xaml file. In this case, your code should be :
<actions:ToggleVisibilityAction TargetName="MyBaseMaps" />

AFAIK there is no way to reference a name declared in another xaml file.
0 Kudos