diff --git a/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/BusyIndicator/BusyIndicator.cs b/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/BusyIndicator/BusyIndicator.cs index d7f5f116..6a73cd8f 100644 --- a/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/BusyIndicator/BusyIndicator.cs +++ b/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/BusyIndicator/BusyIndicator.cs @@ -9,7 +9,6 @@ namespace Microsoft.Windows.Controls /// /// A control to provide a visual indicator when an application is busy. /// - /// Preview [TemplateVisualState(Name = VisualStates.StateIdle, GroupName = VisualStates.GroupBusyStatus)] [TemplateVisualState(Name = VisualStates.StateBusy, GroupName = VisualStates.GroupBusyStatus)] [TemplateVisualState(Name = VisualStates.StateVisible, GroupName = VisualStates.GroupVisibility)] diff --git a/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/MessageBox/Icons/Error48.png b/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/MessageBox/Icons/Error48.png new file mode 100644 index 00000000..4304d43b Binary files /dev/null and b/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/MessageBox/Icons/Error48.png differ diff --git a/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/MessageBox/Icons/Information48.png b/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/MessageBox/Icons/Information48.png new file mode 100644 index 00000000..35075187 Binary files /dev/null and b/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/MessageBox/Icons/Information48.png differ diff --git a/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/MessageBox/Icons/Question48.png b/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/MessageBox/Icons/Question48.png new file mode 100644 index 00000000..dad7dd09 Binary files /dev/null and b/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/MessageBox/Icons/Question48.png differ diff --git a/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/MessageBox/Icons/Warning48.png b/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/MessageBox/Icons/Warning48.png new file mode 100644 index 00000000..ecb7fe86 Binary files /dev/null and b/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/MessageBox/Icons/Warning48.png differ diff --git a/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/MessageBox/MessageBox.cs b/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/MessageBox/MessageBox.cs new file mode 100644 index 00000000..fe9a00bb --- /dev/null +++ b/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/MessageBox/MessageBox.cs @@ -0,0 +1,396 @@ +using System; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Media; +using System.Windows.Controls.Primitives; + +namespace Microsoft.Windows.Controls +{ + [TemplateVisualState(Name = VisualStates.OK, GroupName = VisualStates.MessageBoxButtonsGroup)] + [TemplateVisualState(Name = VisualStates.OKCancel, GroupName = VisualStates.MessageBoxButtonsGroup)] + [TemplateVisualState(Name = VisualStates.YesNo, GroupName = VisualStates.MessageBoxButtonsGroup)] + [TemplateVisualState(Name = VisualStates.YesNoCancel, GroupName = VisualStates.MessageBoxButtonsGroup)] + public class MessageBox : Control + { + #region Private Members + + /// + /// Tracks the MessageBoxButon value passed into the InitializeContainer method + /// + private MessageBoxButton _button = MessageBoxButton.OK; + + #endregion //Private Members + + #region Constructors + + static MessageBox() + { + DefaultStyleKeyProperty.OverrideMetadata(typeof(MessageBox), new FrameworkPropertyMetadata(typeof(MessageBox))); + } + + internal MessageBox() + { /*user cannot create instance */ } + + #endregion //Constructors + + #region Properties + + #region Protected Properties + + /// + /// A System.Windows.MessageBoxResult value that specifies which message box button was clicked by the user. + /// + protected MessageBoxResult MessageBoxResult = MessageBoxResult.None; + + protected Window Container { get; private set; } + protected Thumb DragWidget { get; private set; } + protected Button CloseButton { get; private set; } + + protected Button OkButton { get; private set; } + protected Button CancelButton { get; private set; } + protected Button YesButton { get; private set; } + protected Button NoButton { get; private set; } + + protected Button OkButton1 { get; private set; } + protected Button CancelButton1 { get; private set; } + protected Button YesButton1 { get; private set; } + protected Button NoButton1 { get; private set; } + + #endregion //Protected Properties + + #region Dependency Properties + + public static readonly DependencyProperty CaptionProperty = DependencyProperty.Register("Caption", typeof(string), typeof(MessageBox), new UIPropertyMetadata(String.Empty)); + /// + /// Gets or sets the caption. + /// + /// The caption. + public string Caption + { + get { return (string)GetValue(CaptionProperty); } + set { SetValue(CaptionProperty, value); } + } + + public static readonly DependencyProperty ImageSourceProperty = DependencyProperty.Register("ImageSource", typeof(ImageSource), typeof(MessageBox), new UIPropertyMetadata(default(ImageSource))); + /// + /// Gets or sets the message image source. + /// + /// The message image source. + public ImageSource ImageSource + { + get { return (ImageSource)GetValue(ImageSourceProperty); } + set { SetValue(ImageSourceProperty, value); } + } + + public static readonly DependencyProperty TextProperty = DependencyProperty.Register("Text", typeof(string), typeof(MessageBox), new UIPropertyMetadata(String.Empty)); + /// + /// Gets or sets the message text. + /// + /// The message text. + public string Text + { + get { return (string)GetValue(TextProperty); } + set { SetValue(TextProperty, value); } + } + + #endregion //Dependency Properties + + #endregion //Properties + + #region Base Class Overrides + + /// + /// Overrides the OnApplyTemplate method. + /// + public override void OnApplyTemplate() + { + base.OnApplyTemplate(); + + DragWidget = (Thumb)GetTemplateChild("PART_DragWidget"); + if (DragWidget != null) + DragWidget.DragDelta += (o, e) => ProcessMove(e); + + CloseButton = (Button)GetTemplateChild("PART_CloseButton"); + if (CloseButton != null) + CloseButton.Click += (o, e) => Close(); + + NoButton = (Button)GetTemplateChild("PART_NoButton"); + if (NoButton != null) + NoButton.Click += (o, e) => Button_Click(o, e); + + NoButton1 = (Button)GetTemplateChild("PART_NoButton1"); + if (NoButton1 != null) + NoButton1.Click += (o, e) => Button_Click(o, e); + + YesButton = (Button)GetTemplateChild("PART_YesButton"); + if (YesButton != null) + YesButton.Click += (o, e) => Button_Click(o, e); + + YesButton1 = (Button)GetTemplateChild("PART_YesButton1"); + if (YesButton1 != null) + YesButton1.Click += (o, e) => Button_Click(o, e); + + CancelButton = (Button)GetTemplateChild("PART_CancelButton"); + if (CancelButton != null) + CancelButton.Click += (o, e) => Button_Click(o, e); + + CancelButton1 = (Button)GetTemplateChild("PART_CancelButton1"); + if (CancelButton1 != null) + CancelButton1.Click += (o, e) => Button_Click(o, e); + + OkButton = (Button)GetTemplateChild("PART_OkButton"); + if (OkButton != null) + OkButton.Click += (o, e) => Button_Click(o, e); + + OkButton1 = (Button)GetTemplateChild("PART_OkButton1"); + if (OkButton1 != null) + OkButton1.Click += (o, e) => Button_Click(o, e); + + ChangeVisualState(_button.ToString(), true); + } + + #endregion //Base Class Overrides + + #region Methods + + #region Public Static + + /// + /// Displays a message box that has a message and that returns a result. + /// + /// A System.String that specifies the text to display. + /// A System.Windows.MessageBoxResult value that specifies which message box button is clicked by the user. + public static MessageBoxResult Show(string messageText) + { + return Show(messageText, string.Empty, MessageBoxButton.OK); + } + + /// + /// Displays a message box that has a message and title bar caption; and that returns a result. + /// + /// A System.String that specifies the text to display. + /// A System.String that specifies the title bar caption to display. + /// A System.Windows.MessageBoxResult value that specifies which message box button is clicked by the user. + public static MessageBoxResult Show(string messageText, string caption) + { + return Show(messageText, caption, MessageBoxButton.OK); + } + + /// + /// Displays a message box that has a message and that returns a result. + /// + /// A System.String that specifies the text to display. + /// A System.String that specifies the title bar caption to display. + /// A System.Windows.MessageBoxButton value that specifies which button or buttons to display. + /// A System.Windows.MessageBoxResult value that specifies which message box button is clicked by the user. + public static MessageBoxResult Show(string messageText, string caption, MessageBoxButton button) + { + return ShowCore(messageText, caption, button, MessageBoxImage.None); + } + + /// + /// Displays a message box that has a message and that returns a result. + /// + /// A System.String that specifies the text to display. + /// A System.String that specifies the title bar caption to display. + /// A System.Windows.MessageBoxButton value that specifies which button or buttons to display. + /// A System.Windows.MessageBoxImage value that specifies the icon to display. + /// A System.Windows.MessageBoxResult value that specifies which message box button is clicked by the user. + public static MessageBoxResult Show(string messageText, string caption, MessageBoxButton button, MessageBoxImage icon) + { + return ShowCore(messageText, caption, button, icon); + } + + #endregion //Public Static + + #region Private Static + + private static MessageBoxResult ShowCore(string messageText, string caption, MessageBoxButton button, MessageBoxImage icon) + { + MessageBox msgBox = new MessageBox(); + msgBox.InitializeMessageBox(messageText, caption, button, icon); + msgBox.Show(); + return msgBox.MessageBoxResult; + } + + /// + /// Resolves the owner Window of the MessageBox. + /// + /// + private static FrameworkElement ResolveOwner() + { + FrameworkElement owner = null; + if (Application.Current != null) + { + foreach (Window w in Application.Current.Windows) + { + if (w.IsActive) + { + owner = w; + break; + } + } + } + return owner; + } + + #endregion //Private Static + + #region Protected + + /// + /// Shows the MessageBox + /// + protected void Show() + { + Container.ShowDialog(); + } + + /// + /// Initializes the MessageBox. + /// + /// The text. + /// The caption. + /// The button. + /// The image. + protected void InitializeMessageBox(string text, string caption, MessageBoxButton button, MessageBoxImage image) + { + Text = text; + Caption = caption; + _button = button; + SetImageSource(image); + Container = CreateContainer(); + } + + /// + /// Changes the control's visual state(s). + /// + /// name of the state + /// True if state transitions should be used. + protected void ChangeVisualState(string name, bool useTransitions) + { + VisualStateManager.GoToState(this, name, useTransitions); + } + + #endregion //Protected + + #region Private + + /// + /// Sets the message image source. + /// + /// The image to show. + private void SetImageSource(MessageBoxImage image) + { + String iconName = String.Empty; + + switch (image) + { + case MessageBoxImage.Error: + { + iconName = "Error48.png"; + break; + } + case MessageBoxImage.Information: + { + iconName = "Information48.png"; + break; + } + case MessageBoxImage.Question: + { + iconName = "Question48.png"; + break; + } + case MessageBoxImage.Warning: + { + iconName = "Warning48.png"; + break; + } + case MessageBoxImage.None: + default: + { + return; + } + } + + ImageSource = (ImageSource)new ImageSourceConverter().ConvertFromString(String.Format("pack://application:,,,/WPFToolkit.Extended;component/MessageBox/Icons/{0}", iconName)); + } + + /// + /// Creates the container which will host the MessageBox control. + /// + /// + private Window CreateContainer() + { + return new Window() + { + AllowsTransparency = true, + Background = Brushes.Transparent, + Content = this, + Owner = Window.GetWindow(ResolveOwner()), + ShowInTaskbar = false, + SizeToContent = System.Windows.SizeToContent.WidthAndHeight, + ResizeMode = System.Windows.ResizeMode.NoResize, + WindowStartupLocation = System.Windows.WindowStartupLocation.CenterOwner, + WindowStyle = System.Windows.WindowStyle.None + }; + } + + #endregion //Private + + #endregion //Methods + + #region Event Handlers + + /// + /// Processes the move of a drag operation on the header. + /// + /// The instance containing the event data. + private void ProcessMove(DragDeltaEventArgs e) + { + Container.Left = Container.Left + e.HorizontalChange; + Container.Top = Container.Top + e.VerticalChange; + } + + /// + /// Sets the MessageBoxResult according to the button pressed and then closes the MessageBox. + /// + /// The source of the event. + /// The instance containing the event data. + private void Button_Click(object sender, RoutedEventArgs e) + { + Button button = e.Source as Button; + switch (button.Name) + { + case "PART_NoButton": + case "PART_NoButton1": + MessageBoxResult = MessageBoxResult.No; + break; + case "PART_YesButton": + case "PART_YesButton1": + MessageBoxResult = MessageBoxResult.Yes; + break; + case "PART_CancelButton": + case "PART_CancelButton1": + MessageBoxResult = MessageBoxResult.Cancel; + break; + case "PART_OkButton": + case "PART_OkButton1": + MessageBoxResult = MessageBoxResult.OK; + break; + } + + Close(); + } + + /// + /// Closes the MessageBox. + /// + private void Close() + { + Container.Close(); + } + + #endregion //Event Handlers + } +} diff --git a/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/MessageBox/MessageBox.xaml b/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/MessageBox/MessageBox.xaml new file mode 100644 index 00000000..a2cedd9a --- /dev/null +++ b/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/MessageBox/MessageBox.xaml @@ -0,0 +1,300 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/MessageBox/VisualStates.MessageBox.cs b/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/MessageBox/VisualStates.MessageBox.cs new file mode 100644 index 00000000..d47fcb08 --- /dev/null +++ b/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/MessageBox/VisualStates.MessageBox.cs @@ -0,0 +1,17 @@ +using System; + +namespace Microsoft.Windows.Controls +{ + internal static partial class VisualStates + { + public const string MessageBoxButtonsGroup = "MessageBoxButtonsGroup"; + + public const string OK = "OK"; + + public const string OKCancel = "OKCancel"; + + public const string YesNo = "YesNo"; + + public const string YesNoCancel = "YesNoCancel"; + } +} diff --git a/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/Properties/AssemblyInfo.cs b/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/Properties/AssemblyInfo.cs index aa6bc73c..4826befc 100644 --- a/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/Properties/AssemblyInfo.cs +++ b/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/Properties/AssemblyInfo.cs @@ -51,5 +51,5 @@ using System.Windows; // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0803.0")] -[assembly: AssemblyFileVersion("1.0.0803.0")] +[assembly: AssemblyVersion("1.1.0.0")] +[assembly: AssemblyFileVersion("1.1.0.0")] diff --git a/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/Themes/Generic.xaml b/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/Themes/Generic.xaml index b22e5043..35d1ebe8 100644 --- a/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/Themes/Generic.xaml +++ b/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/Themes/Generic.xaml @@ -1,4 +1,4 @@ - @@ -138,5 +138,300 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/WPFToolkit.Extended.csproj b/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/WPFToolkit.Extended.csproj index de00c6d1..16b46b7b 100644 --- a/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/WPFToolkit.Extended.csproj +++ b/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/WPFToolkit.Extended.csproj @@ -57,6 +57,10 @@ Designer MSBuild:Compile + + Designer + MSBuild:Compile + MSBuild:Compile Designer @@ -64,6 +68,7 @@ + Code @@ -79,6 +84,7 @@ + ResXFileCodeGenerator Resources.Designer.cs @@ -89,6 +95,12 @@ + + + + + +