示例#1
0
        public void ApplyLayout(LayoutEventArgs e)
        {
            if (e == null)
                return;

            this.Content = e.Content;
            Map = e.Map;

            if (e.AttributeTableContainer != null)
            {
                if (e.AttributeTableContainer.Content == null)
                {
                    AttributeDisplay = new AttributeDisplay()
                    {
                        FeatureDataGrid = new FeatureDataGrid(),
                        AutoScrollToGraphic = AutoScrollRowOnMouseOver,
                        FilterFeaturesByMapExtent = FilterFeaturesOnMapExtentChanged,
                    };
                    e.AttributeTableContainer.Content = AttributeDisplay;
                }
                else
                {
                    FeatureDataGrid featureDataGrid = e.AttributeTableContainer.Content as FeatureDataGrid;
                    if (featureDataGrid != null)
                    {
                        e.AttributeTableContainer.Content = null; // remove from parent
                        AttributeDisplay = new AttributeDisplay()
                        {
                            FeatureDataGrid = featureDataGrid,
                            AutoScrollToGraphic = AutoScrollRowOnMouseOver,
                            FilterFeaturesByMapExtent = FilterFeaturesOnMapExtentChanged,
                        };
                        e.AttributeTableContainer.Content = AttributeDisplay;
                    }
                }
                if (AttributeDisplay != null && AttributeDisplay.FeatureDataGrid != null)
                {
                    try
                    {
                        Binding binding = XamlReader.Load("<Binding xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\" xmlns:extensibility=\"http://schemas.esri.com/arcgis/client/extensibility/2010\" Path=\"GraphicsLayer.(extensibility:LayerProperties.IsEditable)\" />") as Binding;
                        binding.Converter = new ReverseBooleanConverter();
                        binding.Source = AttributeDisplay;
                        BindingOperations.SetBinding(AttributeDisplay.FeatureDataGrid, DataGrid.IsReadOnlyProperty, binding);
                    }
                    catch
                    {
                        //Swallow
                    }

                    // workaround to avoid issue where initial load of attribute table (DataGrid) crashes 
                    // Silverlight when table includes columns with numeric field names.  
                    GraphicsLayer layer = AttributeDisplay.FeatureDataGrid.GraphicsLayer;
                    AttributeDisplay.FeatureDataGrid.GraphicsLayer = null;

                    ToggleTableCommand cmd = new ToggleTableCommand();

                    RoutedEventHandler loaded = null;
                    loaded = (o, args) =>
                    { 
                        cmd.Execute(null);
                        AttributeDisplay.FeatureDataGrid.Loaded -= loaded;
                        AttributeDisplay.FeatureDataGrid.GraphicsLayer = layer;
                    };

                    AttributeDisplay.FeatureDataGrid.Loaded += loaded;
                    cmd.Execute(null);
                }
            }

            if (e.ScaleBarContainer != null && e.ScaleBarContainer.Content == null)
            {
                e.ScaleBarContainer.Content = ScaleBar = new ScaleBar()
                {
                    TargetWidth = 150,
                    MapUnit = MapUnit.Undefined,
                };
            }

            if (e.ProgressIndicatorContainer != null && e.ProgressIndicatorContainer.Content == null)
            {
                e.ProgressIndicatorContainer.Content = ProgressGauge = new ProgressGauge();
            }

            if (e.AttributionDisplayContainer != null && e.AttributionDisplayContainer.Content == null)
            {
                e.AttributionDisplayContainer.Content = AttributionDisplayControl = new AttributionDisplayControl() { 
                    Foreground = e.AttributionDisplayContainer.Foreground,
                };
                AttributionDisplayControl.SetBinding(FrameworkElement.VisibilityProperty, new System.Windows.Data.Binding("Visibility") { Source = e.AttributionDisplayContainer, Mode = System.Windows.Data.BindingMode.TwoWay });
            }

            Editor = MapApplication.Current.FindObjectInLayout(ControlNames.EDITORWIDGET) as EditorWidget;
            if (e.EditorConfigContainer != null && e.EditorConfigContainer.Content == null)
            {
                EditorConfigControl = new GenericConfigControl();
                EditorConfigControl.Name = "EditorConfiguration";
                EditorConfigControl.Title = Controls.Resources.Strings.ConfigureEditorWidget;
                EditorConfigControl.Command = new ConfigureEditorCommand() { Map = Map };
                ElementExtensions.SetIsConfigurable(EditorConfigControl, true);
                object[] attributes = typeof(ToggleEditCommand).GetCustomAttributes(typeof(DisplayNameAttribute), false);
                if (attributes.Length > 0 && !string.IsNullOrEmpty(((DisplayNameAttribute)attributes[0]).Name))
                    ElementExtensions.SetDisplayName(EditorConfigControl, ((DisplayNameAttribute)attributes[0]).Name);
                e.EditorConfigContainer.Content = EditorConfigControl;

                // When done in XAML the binding doesn't work properly until the editorwidget is made visible.
                if (Editor != null)
                {
                    BindingOperations.SetBinding(Editor, EditorWidget.AlwaysDisplayDefaultTemplatesProperty, new Binding("DataContext.AlwaysDisplayDefaultTemplates") { Source = e.EditorConfigContainer });
                    BindingOperations.SetBinding(Editor, EditorWidget.AutoCompleteProperty, new Binding("DataContext.AutoComplete") { Source = e.EditorConfigContainer, Mode = BindingMode.TwoWay });
                    BindingOperations.SetBinding(Editor, EditorWidget.AutoSelectProperty, new Binding("DataContext.AutoSelect") { Source = e.EditorConfigContainer });
                    BindingOperations.SetBinding(Editor, EditorWidget.ContinuousProperty, new Binding("DataContext.Continuous") { Source = e.EditorConfigContainer });
                    BindingOperations.SetBinding(Editor, EditorWidget.EditVerticesEnabledProperty, new Binding("DataContext.EditVerticesEnabled") { Source = e.EditorConfigContainer });
                    BindingOperations.SetBinding(Editor, EditorWidget.FreehandProperty, new Binding("DataContext.Freehand") { Source = e.EditorConfigContainer, Mode = BindingMode.TwoWay });
                    BindingOperations.SetBinding(Editor, EditorWidget.MaintainAspectRatioProperty, new Binding("DataContext.MaintainAspectRatio") { Source = e.EditorConfigContainer });
                    BindingOperations.SetBinding(Editor, EditorWidget.MoveEnabledProperty, new Binding("DataContext.MoveEnabled") { Source = e.EditorConfigContainer });
                    BindingOperations.SetBinding(Editor, EditorWidget.RotateEnabledProperty, new Binding("DataContext.RotateEnabled") { Source = e.EditorConfigContainer });
                    BindingOperations.SetBinding(Editor, EditorWidget.ScaleEnabledProperty, new Binding("DataContext.ScaleEnabled") { Source = e.EditorConfigContainer });
                    BindingOperations.SetBinding(Editor, EditorWidget.LayerIDsProperty, new Binding("DataContext.LayerIds") { Source = e.EditorConfigContainer });
                }
            }

            ContentControl container = MapApplication.Current.FindObjectInLayout(ControlNames.ADDCONTENTCONTROLCONTAINER) as ContentControl;
            if (container != null)
            {
                AddContentDialog addContentDialog = new AddContentDialog()
                {
                    DataSourceProvider = DataSourceProvider,
                    ConnectionsProvider = ConnectionsProvider,
                    BorderThickness = new Thickness(0),
                    Map = Map,
                };
                addContentDialog.LayerAdded += AddContentDialog_LayerAdded;
                addContentDialog.LayerAddFailed += AddContentDialog_LayerAddFailed;
                container.Content = addContentDialog;
            }

            container = MapApplication.Current.FindObjectInLayout(ControlNames.MAPCONTENTS_CONTROL_CONTAINER_NAME) as ContentControl;
            if (container != null)
            {
                MapContents = new EsriMapContents.MapContents();
                MapContents.Name = ControlNames.MAPCONTENTS_CONTROL_NAME;
                ElementExtensions.SetIsConfigurable(MapContents, true);
                object[] attributes = typeof(ToggleMapContentsCommand).GetCustomAttributes(typeof(DisplayNameAttribute), false);
                if (attributes.Length > 0 && !string.IsNullOrEmpty(((DisplayNameAttribute)attributes[0]).Name))
                    ElementExtensions.SetDisplayName(MapContents, ((DisplayNameAttribute)attributes[0]).Name);
                MapContents.Map = Map;
                container.Content = MapContents;

                // Push container foreground and background to Map Contents
                Binding b = new Binding("Foreground") { Source = container };
                MapContents.SetBinding(EsriMapContents.MapContents.ForegroundProperty, b);
                b = new Binding("Background") { Source = container };
                MapContents.SetBinding(EsriMapContents.MapContents.BackgroundProperty, b);
            }

            if (Editor != null)
                Editor.Map = Map;

            WindowManager.FloatingWindowStyle = LayoutStyleHelper.Instance.GetStyle(WindowManager.FloatingWindowStyleKey);

            // Set the logic to be executed when an authentication challenge occurs
            IdentityManager.Current.ChallengeMethod = OnChallenge;
            if (!listeningToCredentials)
            {
                // Listen for changes in the application environment's set of credentials, setting a flag to 
                // ensure that this is only done once.
                listeningToCredentials = true;
                UserManagement.Current.Credentials.CollectionChanged += Credentials_CollectionChanged;
            }

            AttachToControlEvents();
            SubscribeToSymbolConfigProviderEvents();
        }
        /// <summary>
        /// MapProperty property changed handler.
        /// </summary>
        /// <param name="d">AttributionDisplayControl that changed its Map.</param>
        /// <param name="e">Event arguments.</param>
        private static void OnMapPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            AttributionDisplayControl source = d as AttributionDisplayControl;

            source.onMapPropertyChanged();
        }