public static void AddRenderedActions(Grid uiContainer, IList <AdaptiveAction> actions, AdaptiveRenderContext context, AdaptiveInternalID actionSetId) { if (!context.Config.SupportsInteractivity) { return; } ActionsConfig actionsConfig = context.Config.Actions; int maxActions = actionsConfig.MaxActions; List <AdaptiveAction> actionsToProcess = GetActionsToProcess(actions, maxActions, context); if (actionsToProcess.Any()) { var uiActionBar = new UniformGrid(); if (actionsConfig.ActionsOrientation == ActionsOrientation.Horizontal) { uiActionBar.Columns = actionsToProcess.Count(); } else { uiActionBar.Rows = actionsToProcess.Count(); } uiActionBar.HorizontalAlignment = (HorizontalAlignment)Enum.Parse(typeof(HorizontalAlignment), actionsConfig.ActionAlignment.ToString()); uiActionBar.VerticalAlignment = VerticalAlignment.Bottom; uiActionBar.Style = context.GetStyle("Adaptive.Actions"); // For vertical, we want to subtract the top margin of the first button int topMargin = actionsConfig.ActionsOrientation == ActionsOrientation.Horizontal ? context.Config.GetSpacing(actionsConfig.Spacing) : context.Config.GetSpacing(actionsConfig.Spacing) - actionsConfig.ButtonSpacing; uiActionBar.Margin = new Thickness(0, topMargin, 0, 0); uiContainer.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto }); Grid.SetRow(uiActionBar, uiContainer.RowDefinitions.Count - 1); uiContainer.Children.Add(uiActionBar); bool isInline = (actionsConfig.ShowCard.ActionMode == ShowCardActionMode.Inline); int iPos = 0; // See if all actions have icons, otherwise force the icon placement to the left IconPlacement oldConfigIconPlacement = actionsConfig.IconPlacement; bool allActionsHaveIcons = true; foreach (AdaptiveAction action in actionsToProcess) { if (string.IsNullOrEmpty(action.IconUrl)) { allActionsHaveIcons = false; break; } } if (!allActionsHaveIcons) { actionsConfig.IconPlacement = IconPlacement.LeftOfTitle; } // indicates showcard has not been seen if it's set false; meaningful only if it's used // when inline is supported bool hasSeenInlineShowCard = false; foreach (AdaptiveAction action in actionsToProcess) { // add actions var uiAction = context.Render(action) as Button; if (uiAction == null) { context.Warnings.Add(new AdaptiveWarning(-1, $"action failed to render" + $"and valid fallback wasn't present")); continue; } if (actionsConfig.ActionsOrientation == ActionsOrientation.Horizontal) { if (uiActionBar.Children.Count > 0) // don't apply left margin to the first item { uiAction.Margin = new Thickness(actionsConfig.ButtonSpacing, 0, 0, 0); } } else { uiAction.Margin = new Thickness(0, actionsConfig.ButtonSpacing, 0, 0); } if (actionsConfig.ActionsOrientation == ActionsOrientation.Horizontal) { Grid.SetColumn(uiAction, iPos++); } uiActionBar.Children.Add(uiAction); if (action is AdaptiveShowCardAction showCardAction && isInline) { if (actionSetId != null) { // the button's context is used as key for retrieving the corresponding showcard uiAction.SetContext(actionSetId); if (!hasSeenInlineShowCard) { // Define a new row to contain all the show cards uiContainer.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto }); // it's first showcard of the peers, create a new list context.PeerShowCardsInActionSet[actionSetId] = new List <FrameworkElement>(); } hasSeenInlineShowCard = true; Grid uiShowCardContainer = new Grid(); uiShowCardContainer.Style = context.GetStyle("Adaptive.Actions.ShowCard"); uiShowCardContainer.DataContext = showCardAction; uiShowCardContainer.Visibility = Visibility.Collapsed; var padding = context.Config.Spacing.Padding; // set negative margin to expand the wrapper to the edge of outer most card uiShowCardContainer.Margin = new Thickness(-padding, actionsConfig.ShowCard.InlineTopMargin, -padding, -padding); var showCardStyleConfig = context.Config.ContainerStyles.GetContainerStyleConfig(actionsConfig.ShowCard.Style); uiShowCardContainer.Background = context.GetColorBrush(showCardStyleConfig.BackgroundColor); // render the card var uiShowCardWrapper = (Grid)context.Render(showCardAction.Card); uiShowCardWrapper.Background = context.GetColorBrush("Transparent"); uiShowCardWrapper.DataContext = showCardAction; uiShowCardContainer.Children.Add(uiShowCardWrapper); context.ActionShowCards.Add(uiAction, uiShowCardContainer); // added the rendered show card as a peer context.PeerShowCardsInActionSet[actionSetId].Add(uiShowCardContainer); // define where in the rows of the parent Grid the show card will occupy // and add it to the parent Grid.SetRow(uiShowCardContainer, uiContainer.RowDefinitions.Count - 1); uiContainer.Children.Add(uiShowCardContainer); } else { context.Warnings.Add(new AdaptiveWarning(-1, $"button's corresponding showCard" + $" couldn't be added since the action set the button belongs to has null as internal id")); } } } // Restore the iconPlacement for the context. actionsConfig.IconPlacement = oldConfigIconPlacement; } }
public static void SetItemsIconPlacement(TabControl tabControl, IconPlacement value) { tabControl.SetValue(ItemsIconPlacementProperty, value); }
public static void SetIconPlacement(Label label, IconPlacement value) { label.SetValue(IconPlacementProperty, value); }
public static void SetIconPlacement(Button button, IconPlacement value) { button.SetValue(IconPlacementProperty, value); }
public static void SetIconPlacement(ListBoxItem listBoxItem, IconPlacement value) { listBoxItem.SetValue(IconPlacementProperty, value); }
public static void SetItemsIconPlacement(ListBox listBox, IconPlacement value) { listBox.SetValue(ItemsIconPlacementProperty, value); }
public static void SetIconPlacement(TabItem tabItem, IconPlacement value) { tabItem.SetValue(IconPlacementProperty, value); }
public static void SetIconPlacement(RepeatButton repeatButton, IconPlacement value) { repeatButton.SetValue(IconPlacementProperty, value); }
public static void RenderActions(Grid uiContainer, IList <AdaptiveAction> actions, AdaptiveRenderContext context) { if (!context.Config.SupportsInteractivity) { return; } ActionsConfig actionsConfig = context.Config.Actions; int maxActions = actionsConfig.MaxActions; List <AdaptiveAction> actionsToProcess = GetActionsToProcess(actions, maxActions, context); if (actionsToProcess.Any()) { var uiActionBar = new UniformGrid(); if (actionsConfig.ActionsOrientation == ActionsOrientation.Horizontal) { uiActionBar.Columns = actionsToProcess.Count(); } else { uiActionBar.Rows = actionsToProcess.Count(); } uiActionBar.HorizontalAlignment = (HorizontalAlignment)Enum.Parse(typeof(HorizontalAlignment), actionsConfig.ActionAlignment.ToString()); uiActionBar.VerticalAlignment = VerticalAlignment.Bottom; uiActionBar.Style = context.GetStyle("Adaptive.Actions"); // For vertical, we want to subtract the top margin of the first button int topMargin = actionsConfig.ActionsOrientation == ActionsOrientation.Horizontal ? context.Config.GetSpacing(actionsConfig.Spacing) : context.Config.GetSpacing(actionsConfig.Spacing) - actionsConfig.ButtonSpacing; uiActionBar.Margin = new Thickness(0, topMargin, 0, 0); uiContainer.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto }); Grid.SetRow(uiActionBar, uiContainer.RowDefinitions.Count - 1); uiContainer.Children.Add(uiActionBar); bool isInline = (actionsConfig.ShowCard.ActionMode == ShowCardActionMode.Inline); int iPos = 0; // See if all actions have icons, otherwise force the icon placement to the left IconPlacement oldConfigIconPlacement = actionsConfig.IconPlacement; bool allActionsHaveIcons = true; foreach (AdaptiveAction action in actionsToProcess) { if (string.IsNullOrEmpty(action.IconUrl)) { allActionsHaveIcons = false; break; } } if (!allActionsHaveIcons) { actionsConfig.IconPlacement = IconPlacement.LeftOfTitle; } foreach (AdaptiveAction action in actionsToProcess) { // add actions var uiAction = (Button)context.Render(action); if (uiAction == null) { continue; } if (actionsConfig.ActionsOrientation == ActionsOrientation.Horizontal) { if (uiActionBar.Children.Count > 0) // don't apply left margin to the first item { uiAction.Margin = new Thickness(actionsConfig.ButtonSpacing, 0, 0, 0); } } else { uiAction.Margin = new Thickness(0, actionsConfig.ButtonSpacing, 0, 0); } if (actionsConfig.ActionsOrientation == ActionsOrientation.Horizontal) { Grid.SetColumn(uiAction, iPos++); } uiActionBar.Children.Add(uiAction); if (action is AdaptiveShowCardAction showCardAction) { // Only support 1 level of showCard if (isInline && context.CardDepth == 1) { Grid uiShowCardContainer = new Grid(); uiShowCardContainer.Style = context.GetStyle("Adaptive.Actions.ShowCard"); uiShowCardContainer.DataContext = showCardAction; uiShowCardContainer.Margin = new Thickness(0, actionsConfig.ShowCard.InlineTopMargin, 0, 0); uiShowCardContainer.Visibility = Visibility.Collapsed; // render the card var uiShowCardWrapper = (Grid)context.Render(showCardAction.Card); uiShowCardWrapper.Background = context.GetColorBrush("Transparent"); uiShowCardWrapper.DataContext = showCardAction; // Remove the card padding var innerCard = (Grid)uiShowCardWrapper.Children[0]; innerCard.Margin = new Thickness(0); uiShowCardContainer.Children.Add(uiShowCardWrapper); // Add to the list of show cards in context context.ActionShowCards.Add(uiAction, uiShowCardContainer); context.ActionShowCardsKeys.Enqueue(uiAction); } } } // Restore the iconPlacement for the context. actionsConfig.IconPlacement = oldConfigIconPlacement; } }
public static void SetIconPlacement(ToggleButton toggleButton, IconPlacement value) { toggleButton.SetValue(IconPlacementProperty, value); }