protected virtual ToggleButton CreateToggleButton(string name, string text, string toolTipText, string imgResName, RoutedEventHandler onClick, int imgWidth = 32, int imgHeight = 32, ImageTextType imageTextType = ImageTextType.ImageBeforeText) { var imgResUri = CreateUriToResource(imgResName); return(CreateToggleButton(name, text, toolTipText, imgResUri, onClick, imgWidth, imgHeight, imageTextType)); }
/// <summary> /// Create a new instance of ToggleButon class with the specified name that displays the specified text and image and that raises the Click event. /// </summary> /// <param name="name">The name of the ToggleButton.</param> /// <param name="text">The text to display on the ToggleButton.</param> /// <param name="toolTipText">Specify the text that appears as a ToolTip for a control.</param> /// <param name="imgResName">The image name in resources to display on the ToggleButton.</param> /// <param name="onClick">An event handler that raises the Click event.</param> /// <param name="imgWidth">Image width</param> /// <param name="imgHeight">Image height</param> /// <param name="imageTextType">Image and text layout</param> /// <returns>Newly created ToggleButton</returns> protected virtual ToggleButton CreateToggleButton(string name, string text, string toolTipText, string imgResName, RoutedEventHandler onClick, int imgWidth = 32, int imgHeight = 32, ImageTextType imageTextType = ImageTextType.ImageBeforeText) { ToggleButton btn = new ToggleButton(); btn.Name = name; btn.ToolTip = new ToolTip() { Content = toolTipText }; var btncontent = new StackPanel(); Image img = null; TextBlock txt = null; if (imgResName != null) img = new Image() { Source = new BitmapImage(new Uri("pack://application:,,,/Patagames.Pdf.Wpf;component/Resources/" + imgResName, UriKind.Absolute)), Stretch = System.Windows.Media.Stretch.Fill, Width = imgWidth, Height = imgHeight, }; if (text != null) txt = new TextBlock() { Text = text, TextAlignment = TextAlignment.Center }; btn.Content = btncontent; btn.Click += onClick; btn.Padding = new Thickness(7, 2, 7, 2); if (imageTextType == ImageTextType.ImageBeforeText || imageTextType == ImageTextType.ImageOnly) btncontent.Children.Add(img); if (imageTextType == ImageTextType.ImageBeforeText || imageTextType == ImageTextType.TextOnly) btncontent.Children.Add(txt); return btn; }
/// <summary> /// Create a new instance of Button class with the specified name that displays the specified text and image and that raises the Click event. /// </summary> /// <param name="name">The name of the Button.</param> /// <param name="text">The text to display on the Button.</param> /// <param name="toolTipText">Specify the text that appears as a ToolTip for a control.</param> /// <param name="imgRes">The image to display on the Button.</param> /// <param name="onClick">An event handler that raises the Click event.</param> /// <param name="imgWidth">Image width</param> /// <param name="imgHeight">Image height</param> /// <param name="imageTextType">Image and text layout</param> /// <returns>Newly created Button</returns> protected virtual Button CreateButton(string name, string text, string toolTipText, Uri imgRes, RoutedEventHandler onClick, int imgWidth=32, int imgHeight=32, ImageTextType imageTextType = ImageTextType.ImageBeforeText) { Button btn = new Button(); btn.Name = name; btn.ToolTip = new ToolTip() { Content = toolTipText }; var btncontent = new StackPanel(); Image img = null; TextBlock txt = null; if (imgRes != null) img = new Image() { Source = new BitmapImage(imgRes), Stretch = System.Windows.Media.Stretch.Fill, Width = imgWidth, Height = imgHeight, }; if (text != null) txt = new TextBlock() { Text = text, TextAlignment = TextAlignment.Center }; btn.Content = btncontent; btn.Click += onClick; btn.Padding = new Thickness(7, 2, 7, 2); if(imageTextType== ImageTextType.ImageBeforeText || imageTextType== ImageTextType.ImageOnly) btncontent.Children.Add(img); if (imageTextType == ImageTextType.ImageBeforeText || imageTextType == ImageTextType.TextOnly) btncontent.Children.Add(txt); return btn; }
/// <summary> /// Create a new instance of ToggleButon class with the specified name that displays the specified text and image and that raises the Click event. /// </summary> /// <param name="name">The name of the ToggleButton.</param> /// <param name="text">The text to display on the ToggleButton.</param> /// <param name="toolTipText">Specify the text that appears as a ToolTip for a control.</param> /// <param name="imgResName">The image name in resources to display on the ToggleButton.</param> /// <param name="onClick">An event handler that raises the Click event.</param> /// <param name="imgWidth">Image width</param> /// <param name="imgHeight">Image height</param> /// <param name="imageTextType">Image and text layout</param> /// <returns>Newly created ToggleButton</returns> protected virtual ToggleButton CreateToggleButton(string name, string text, string toolTipText, string imgResName, RoutedEventHandler onClick, int imgWidth = 32, int imgHeight = 32, ImageTextType imageTextType = ImageTextType.ImageBeforeText) { ToggleButton btn = new ToggleButton(); btn.Name = name; btn.ToolTip = new ToolTip() { Content = toolTipText }; var btncontent = new StackPanel(); Image img = null; TextBlock txt = null; if (imgResName != null) { img = new Image() { Source = new BitmapImage(new Uri("pack://application:,,,/Patagames.Pdf.Wpf;component/Resources/" + imgResName, UriKind.Absolute)), Stretch = System.Windows.Media.Stretch.Fill, Width = imgWidth, Height = imgHeight, } } ; if (text != null) { txt = new TextBlock() { Text = text, TextAlignment = TextAlignment.Center } } ; btn.Content = btncontent; btn.Click += onClick; btn.Padding = new Thickness(7, 2, 7, 2); if (imageTextType == ImageTextType.ImageBeforeText || imageTextType == ImageTextType.ImageOnly) { btncontent.Children.Add(img); } if (imageTextType == ImageTextType.ImageBeforeText || imageTextType == ImageTextType.TextOnly) { btncontent.Children.Add(txt); } return(btn); } #endregion } }
/// <summary> /// Create a new instance of Button class with the specified name that displays the specified text and image and that raises the Click event. /// </summary> /// <param name="name">The name of the Button.</param> /// <param name="text">The text to display on the Button.</param> /// <param name="toolTipText">Specify the text that appears as a ToolTip for a control.</param> /// <param name="imgRes">The image to display on the Button.</param> /// <param name="onClick">An event handler that raises the Click event.</param> /// <param name="imgWidth">Image width</param> /// <param name="imgHeight">Image height</param> /// <param name="imageTextType">Image and text layout</param> /// <returns>Newly created Button</returns> protected virtual Button CreateButton(string name, string text, string toolTipText, Uri imgRes, RoutedEventHandler onClick, int imgWidth = 32, int imgHeight = 32, ImageTextType imageTextType = ImageTextType.ImageBeforeText) { Button btn = new Button(); btn.Name = name; btn.ToolTip = new ToolTip() { Content = toolTipText }; var btncontent = new StackPanel(); Image img = null; TextBlock txt = null; if (imgRes != null) { img = new Image() { Source = new BitmapImage(imgRes), Stretch = System.Windows.Media.Stretch.Fill, Width = imgWidth, Height = imgHeight, } } ; if (text != null) { txt = new TextBlock() { Text = text, TextAlignment = TextAlignment.Center } } ; btn.Content = btncontent; btn.Click += onClick; btn.Padding = new Thickness(7, 2, 7, 2); if (imageTextType == ImageTextType.ImageBeforeText || imageTextType == ImageTextType.ImageOnly) { btncontent.Children.Add(img); } if (imageTextType == ImageTextType.ImageBeforeText || imageTextType == ImageTextType.TextOnly) { btncontent.Children.Add(txt); } return(btn); }