public SnackBarLayout(SnackBarOptions options) { RowDefinitions.Add(new RowDefinition()); ColumnDefinitions.Add(new ColumnDefinition()); #if UWP Background = options.BackgroundColor.ToBrush(); var messageLabel = new TextBlock { Text = options.MessageOptions.Message, FontSize = options.MessageOptions.FontSize, FontFamily = new FontFamily(options.MessageOptions.FontFamily), Foreground = options.MessageOptions.Foreground.ToBrush() }; #else Background = options.BackgroundColor.ToBrush(); var messageLabel = new Label { Content = options.MessageOptions.Message, FontSize = options.MessageOptions.FontSize, FontFamily = new FontFamily(options.MessageOptions.FontFamily), Foreground = options.MessageOptions.Foreground.ToBrush() }; #endif Children.Add(messageLabel); SetRow(messageLabel, 0); SetColumn(messageLabel, 0); for (var i = 0; i < options.Actions.Count(); i++) { ColumnDefinitions.Add(new ColumnDefinition() { Width = GridLength.Auto }); var action = options.Actions.ToArray()[i]; var button = new Button { Content = action.Text, Foreground = action.ForegroundColor.ToBrush(), Background = action.BackgroundColor.ToBrush(), FontSize = action.FontSize, FontFamily = new FontFamily(action.FontFamily), Command = new Forms.Command(async() => { OnSnackBarActionExecuted?.Invoke(); await action.Action(); }) }; Children.Add(button); SetRow(button, 0); SetColumn(button, i + 1); } }
public SnackBarLayout(SnackBarOptions options) { RowDefinitions.Add(new RowDefinition()); ColumnDefinitions.Add(new ColumnDefinition()); if (options.BackgroundColor != Forms.Color.Default) { Background = options.BackgroundColor.ToBrush(); } #if UWP var messageLabel = new TextBlock { Text = options.MessageOptions.Message }; #else var messageLabel = new Label { Content = options.MessageOptions.Message }; #endif messageLabel.Padding = new Thickness(options.MessageOptions.Padding.Left, options.MessageOptions.Padding.Top, options.MessageOptions.Padding.Right, options.MessageOptions.Padding.Bottom); if (options.MessageOptions.Font != Forms.Font.Default) { if (options.MessageOptions.Font.FontSize > 0) { messageLabel.FontSize = options.MessageOptions.Font.FontSize; } if (options.MessageOptions.Font.FontFamily != null) { messageLabel.FontFamily = new FontFamily(options.MessageOptions.Font.FontFamily); } } if (options.MessageOptions.Foreground != Forms.Color.Default) { messageLabel.Foreground = options.MessageOptions.Foreground.ToBrush(); } Children.Add(messageLabel); SetRow(messageLabel, 0); SetColumn(messageLabel, 0); for (var i = 0; i < options.Actions.Count(); i++) { ColumnDefinitions.Add(new ColumnDefinition() { Width = GridLength.Auto }); var action = options.Actions.ToArray()[i]; var button = new Button { Content = action.Text, Command = new Forms.Command(async() => { OnSnackBarActionExecuted?.Invoke(); if (action.Action != null) { await action.Action(); } }), Padding = new Thickness(action.Padding.Left, action.Padding.Top, action.Padding.Right, action.Padding.Bottom) }; if (action.Font != Forms.Font.Default) { button.FontSize = action.Font.FontSize; button.FontFamily = new FontFamily(action.Font.FontFamily); } if (action.BackgroundColor != Forms.Color.Default) { button.Background = action.BackgroundColor.ToBrush(); } if (action.ForegroundColor != Forms.Color.Default) { button.Foreground = action.ForegroundColor.ToBrush(); } Children.Add(button); SetRow(button, 0); SetColumn(button, i + 1); } }