initial oogynize check in _ this actually used to work!
This commit is contained in:
106
GUILib/WPFHelper.cs
Normal file
106
GUILib/WPFHelper.cs
Normal file
@@ -0,0 +1,106 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Media;
|
||||
using System.Windows;
|
||||
|
||||
namespace Foo.GUILib
|
||||
{
|
||||
static public class WPFHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// Useful to create a simple wrapping tooltip for a wpf control
|
||||
/// </summary>
|
||||
/// <param name="strToolTipContent"></param>
|
||||
/// <param name="height">Set to 0 to leave default, else set to 0> to define max height</param>
|
||||
/// <param name="width">Set to 0 to leave default, else set to 0> to define max width</param>
|
||||
/// <returns>a ToolTip Object to assign to a control</returns>
|
||||
public static ToolTip CreateNewStringToolTip(string strToolTipContent, int height, int width)
|
||||
{
|
||||
// Create the TextBlock
|
||||
TextBlock tx = new TextBlock();
|
||||
if(height > 0)
|
||||
tx.Height = height;
|
||||
if(width > 0)
|
||||
tx.Width = width;
|
||||
tx.TextWrapping = TextWrapping.Wrap;
|
||||
tx.Text = strToolTipContent;
|
||||
|
||||
// Create the ToolTip with the TextBlock inside
|
||||
ToolTip tt = new ToolTip();
|
||||
tt.Content = strToolTipContent;
|
||||
return tt;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Useful if you want to know if the Mouse cursor is over the specified Wpf Window
|
||||
/// (Uses windowsforms to do the calculations)
|
||||
/// </summary>
|
||||
/// <returns>true if the mouse cursor is over the specified form window, false otherwise</returns>
|
||||
public static bool IsMouseCursorOverWPFormWindow(Window wpfWindow)
|
||||
{
|
||||
if (wpfWindow != null)
|
||||
{
|
||||
// Get the Point location of the mouse cursor
|
||||
System.Drawing.Point point = System.Windows.Forms.Cursor.Position;
|
||||
|
||||
// Get the rect for the Navigation Form
|
||||
Point wpfFormLeftTopPoint = new Point(wpfWindow.Left, wpfWindow.Top);
|
||||
Size wpfFormSize = new Size(wpfWindow.Width, wpfWindow.Height);
|
||||
Rect rect = new Rect(wpfFormLeftTopPoint, wpfFormSize);
|
||||
|
||||
// Return if the Mouse is over the Navigation Form
|
||||
return (rect.Contains((double)point.X, (double)point.Y));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// For Dynamically Creating Text ComboBox Items
|
||||
/// </summary>
|
||||
/// <param name="strContent">Text Content to Display</param>
|
||||
/// <param name="tag">object to tag to the menu item</param>
|
||||
/// <returns></returns>
|
||||
public static ComboBoxItem CreateAComboBoxItem(string strContent, object tag)
|
||||
{
|
||||
if (!String.IsNullOrEmpty(strContent) && (tag != null))
|
||||
{
|
||||
ComboBoxItem item = new ComboBoxItem();
|
||||
item.Content = strContent;
|
||||
item.Tag = tag;
|
||||
return item;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// For dynamically creating Image sources, this function helps you to create an image out of
|
||||
/// a Resource Uri. You can then assign this image to a 'Source' property on an image wpf object
|
||||
/// </summary>
|
||||
/// <param name="strRelativeResourceUri">a valid relative Resource Uri String to an image</param>
|
||||
/// <param name="ImageHeight">the output image's desired height</param>
|
||||
/// <param name="ImageWidth">the output image's desired width</param>
|
||||
/// <returns></returns>
|
||||
public static Image CreateWPFImageFromRelativeResourceUri(string strRelativeResourceUri, int ImageHeight, int ImageWidth)
|
||||
{
|
||||
if (!String.IsNullOrEmpty(strRelativeResourceUri))
|
||||
{
|
||||
Image myImage = new Image();
|
||||
BitmapImage image = new BitmapImage();
|
||||
image.BeginInit();
|
||||
image.UriSource = new Uri(strRelativeResourceUri, UriKind.Relative);
|
||||
image.EndInit();
|
||||
myImage.Stretch = Stretch.Fill;
|
||||
myImage.Height = ImageHeight;
|
||||
myImage.Width = ImageWidth;
|
||||
myImage.Source = image;
|
||||
return myImage;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user