/// <summary> /// Gets a wrapped element mapped by the <paramref name="wrapOption"/>. /// </summary> /// <param name="wrappedGrid">The wrapped grid.</param> /// <param name="wrapOption">The wrap option that is used, which will be mapped to the control. The value <see cref="WrapControlServiceWrapOptions.All"/> is not allowed and will throw an exception.</param> /// <returns> /// <see cref="FrameworkElement"/> or <c>null</c> if the element is not found. /// </returns> /// <exception cref="ArgumentNullException">The <paramref name="wrappedGrid"/> is <c>null</c>.</exception> /// <exception cref="ArgumentOutOfRangeException">The <paramref name="wrapOption"/> is <see cref="WrapControlServiceWrapOptions.All"/>.</exception> public FrameworkElement GetWrappedElement(Grid wrappedGrid, WrapControlServiceWrapOptions wrapOption) { Argument.IsNotNull("wrappedGrid", wrappedGrid); if (wrapOption == WrapControlServiceWrapOptions.All) { throw new ArgumentOutOfRangeException("wrapOption"); } switch (wrapOption) { case WrapControlServiceWrapOptions.GenerateInlineInfoBarMessageControl: return(GetWrappedElement(wrappedGrid, WrapControlServiceControlNames.InfoBarMessageControlName)); case WrapControlServiceWrapOptions.GenerateWarningAndErrorValidatorForDataContext: return(GetWrappedElement(wrappedGrid, WrapControlServiceControlNames.WarningAndErrorValidatorName)); } return(null); }
/// <summary> /// Wraps the specified framework element. /// </summary> /// <param name="frameworkElement">The framework element.</param> /// <param name="wrapOptions">The wrap options.</param> /// <param name="buttons">The buttons to add.</param> /// <param name="parentContentControl">The parent content control.</param> /// <returns><see cref="Grid"/> that contains the wrapped content.</returns> /// <remarks> /// The framework element that is passed must be disconnected from the parent first. It is recommended to first check whether a /// framework element can be wrapped by using the <see cref="CanBeWrapped"/> method. /// This method will automatically handle the disconnecting of the framework element from the parent is the <paramref name="parentContentControl"/> /// is passed. /// </remarks> public Grid Wrap(FrameworkElement frameworkElement, WrapControlServiceWrapOptions wrapOptions, DataWindowButton[] buttons, ContentControl parentContentControl) { Argument.IsNotNull("frameworkElement", frameworkElement); Argument.IsNotNull("buttons", buttons); if (!string.IsNullOrWhiteSpace(frameworkElement.Name)) { if (frameworkElement.Name.StartsWith(WrapControlServiceControlNames.MainContentHolderName)) { return((Grid)frameworkElement); } } if (parentContentControl != null) { SetControlContent(parentContentControl, null); } var mainContent = frameworkElement; // Create the outside grid, so the inner grid is never the same as the main content holder var outsideGrid = new Grid(); outsideGrid.Name = WrapControlServiceControlNames.MainContentHolderName.GetUniqueControlName(); if (Application.Current != null) { outsideGrid.Resources.MergedDictionaries.Add(Application.Current.Resources); } #region Generate buttons #if !NETFX_CORE if (buttons.Length > 0) { // Add wrappanel containing the buttons var buttonsWrapPanel = new WrapPanel(); buttonsWrapPanel.Name = WrapControlServiceControlNames.ButtonsWrapPanelName; #if SILVERLIGHT buttonsWrapPanel.Style = Application.Current.Resources["DataWindowButtonContainerStyle"] as Style; #else buttonsWrapPanel.SetResourceReference(FrameworkElement.StyleProperty, "DataWindowButtonContainerStyle"); #endif foreach (var dataWindowButton in buttons) { var button = new Button(); if (dataWindowButton.CommandBindingPath != null) { button.SetBinding(ButtonBase.CommandProperty, new Binding(dataWindowButton.CommandBindingPath)); } else { button.Command = dataWindowButton.Command; } if (dataWindowButton.ContentBindingPath != null) { Binding contentBinding = new Binding(dataWindowButton.ContentBindingPath); if (dataWindowButton.ContentValueConverter != null) { contentBinding.Converter = dataWindowButton.ContentValueConverter; } button.SetBinding(ButtonBase.ContentProperty, contentBinding); } else { button.Content = dataWindowButton.Text; } if (dataWindowButton.VisibilityBindingPath != null) { Binding visibilityBinding = new Binding(dataWindowButton.VisibilityBindingPath); if (dataWindowButton.VisibilityValueConverter != null) { visibilityBinding.Converter = dataWindowButton.VisibilityValueConverter; } button.SetBinding(ButtonBase.VisibilityProperty, visibilityBinding); } #if NET button.SetResourceReference(FrameworkElement.StyleProperty, "DataWindowButtonStyle"); button.IsDefault = dataWindowButton.IsDefault; button.IsCancel = dataWindowButton.IsCancel; #else button.Style = Application.Current.Resources["DataWindowButtonStyle"] as Style; #endif if (dataWindowButton.IsDefault) { button.Name = WrapControlServiceControlNames.DefaultOkButtonName; } else if (dataWindowButton.IsCancel) { button.Name = WrapControlServiceControlNames.DefaultCancelButtonName; } buttonsWrapPanel.Children.Add(button); } // Create dockpanel that will dock the buttons underneath the content var subDockPanel = new DockPanel(); subDockPanel.LastChildFill = true; DockPanel.SetDock(buttonsWrapPanel, Dock.Bottom); subDockPanel.Children.Add(buttonsWrapPanel); // Add actual content subDockPanel.Children.Add(frameworkElement); // The dockpanel is now the main content mainContent = subDockPanel; } #endif #endregion #region Generate internal grid // Create grid var internalGrid = new Grid(); internalGrid.Name = WrapControlServiceControlNames.InternalGridName; internalGrid.Children.Add(mainContent); // Grid is now the main content mainContent = internalGrid; #endregion #region Generate WarningAndErrorValidator if (Enum <WrapControlServiceWrapOptions> .Flags.IsFlagSet(wrapOptions, WrapControlServiceWrapOptions.GenerateWarningAndErrorValidatorForDataContext)) { // Create warning and error validator var warningAndErrorValidator = new WarningAndErrorValidator(); warningAndErrorValidator.Name = WrapControlServiceControlNames.WarningAndErrorValidatorName; warningAndErrorValidator.SetBinding(WarningAndErrorValidator.SourceProperty, new Binding()); // Add to grid internalGrid.Children.Add(warningAndErrorValidator); } #endregion #region Generate InfoBarMessageControl #if !NETFX_CORE if (Enum <WrapControlServiceWrapOptions> .Flags.IsFlagSet(wrapOptions, WrapControlServiceWrapOptions.GenerateInlineInfoBarMessageControl) || Enum <WrapControlServiceWrapOptions> .Flags.IsFlagSet(wrapOptions, WrapControlServiceWrapOptions.GenerateOverlayInfoBarMessageControl)) { // Create info bar message control var infoBarMessageControl = new InfoBarMessageControl(); infoBarMessageControl.Name = WrapControlServiceControlNames.InfoBarMessageControlName; infoBarMessageControl.Content = mainContent; if (Enum <WrapControlServiceWrapOptions> .Flags.IsFlagSet(wrapOptions, WrapControlServiceWrapOptions.GenerateOverlayInfoBarMessageControl)) { infoBarMessageControl.Mode = InfoBarMessageControlMode.Overlay; } // This is now the main content mainContent = infoBarMessageControl; } #endif #endregion // Set content of the outside grid outsideGrid.Children.Add(mainContent); if (parentContentControl != null) { SetControlContent(parentContentControl, outsideGrid); } return(outsideGrid); }
/// <summary> /// Wraps the specified framework element without any buttons. /// </summary> /// <param name="frameworkElement">The framework element.</param> /// <param name="wrapOptions">The wrap options.</param> /// <param name="parentContentControl">The parent content control.</param> /// <returns> /// <see cref="Grid"/> that contains the wrapped content. /// </returns> /// <remarks> /// The framework element that is passed must be disconnected from the parent first. It is recommended to first check whether a /// framework element can be wrapped by using the <see cref="CanBeWrapped"/> method. /// <para /> /// This method will automatically handle the disconnecting of the framework element from the parent is the <paramref name="parentContentControl"/> /// is passed. /// </remarks> public Grid Wrap(FrameworkElement frameworkElement, WrapControlServiceWrapOptions wrapOptions, ContentControl parentContentControl = null) { return(Wrap(frameworkElement, wrapOptions, new DataWindowButton[] { }, parentContentControl)); }
/// <summary> /// Gets a wrapped element mapped by the <paramref name="wrapOption"/>. /// </summary> /// <typeparam name="T">Type of the control to return.</typeparam> /// <param name="wrappedGrid">The wrapped grid.</param> /// <param name="wrapOption">The wrap option that is used, which will be mapped to the control. The value <see cref="WrapControlServiceWrapOptions.All"/> is not allowed and will throw an exception.</param> /// <returns> /// <see cref="FrameworkElement"/> or <c>null</c> if the element is not found. /// </returns> /// <exception cref="ArgumentNullException">The <paramref name="wrappedGrid"/> is <c>null</c>.</exception> /// <exception cref="ArgumentOutOfRangeException">The <paramref name="wrapOption"/> is <see cref="WrapControlServiceWrapOptions.All"/>.</exception> public T GetWrappedElement <T>(Grid wrappedGrid, WrapControlServiceWrapOptions wrapOption) where T : FrameworkElement { return(GetWrappedElement(wrappedGrid, wrapOption) as T); }
/// <summary> /// Wraps the specified framework element without any buttons. /// </summary> /// <param name="frameworkElement">The framework element.</param> /// <param name="wrapOptions">The wrap options.</param> /// <param name="parentContentControl">The parent content control.</param> /// <returns> /// <see cref="Grid"/> that contains the wrapped content. /// </returns> /// <remarks> /// The framework element that is passed must be disconnected from the parent first. It is recommended to first check whether a /// framework element can be wrapped by using the <see cref="CanBeWrapped"/> method. /// <para /> /// This method will automatically handle the disconnecting of the framework element from the parent is the <paramref name="parentContentControl"/> /// is passed. /// </remarks> public Grid Wrap(FrameworkElement frameworkElement, WrapControlServiceWrapOptions wrapOptions, ContentControl parentContentControl = null) { return(Wrap(frameworkElement, wrapOptions, ArrayShim.Empty <DataWindowButton>(), parentContentControl)); }