diff --git a/Common.Wpf.csproj b/Common.Wpf.csproj index c8637ef..09abecf 100644 --- a/Common.Wpf.csproj +++ b/Common.Wpf.csproj @@ -1,5 +1,5 @@  - + Debug AnyCPU @@ -10,7 +10,7 @@ Properties Common.Wpf Common.Wpf - v4.0 + v4.5.1 512 {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 4 @@ -35,7 +35,8 @@ false false true - Client + + SAK SAK SAK @@ -51,6 +52,7 @@ 4 AnyCPU AllRules.ruleset + false pdbonly @@ -60,6 +62,7 @@ prompt 4 AllRules.ruleset + false true @@ -76,6 +79,7 @@ true ;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop\\Rules true + false bin\x86\Release\ @@ -91,6 +95,7 @@ ;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\\Rule Sets ;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop\\Rules true + false true @@ -106,6 +111,7 @@ ;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\\Rule Sets ;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop\\Rules false + false bin\x64\Release\ @@ -122,6 +128,7 @@ true ;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop\\Rules true + false @@ -132,6 +139,7 @@ + @@ -146,6 +154,7 @@ + @@ -172,6 +181,7 @@ + TextList.xaml @@ -211,6 +221,10 @@ MSBuild:Compile Designer + + Designer + MSBuild:Compile + diff --git a/EnumToResourceConverter.cs b/EnumToResourceConverter.cs new file mode 100644 index 0000000..3104fd3 --- /dev/null +++ b/EnumToResourceConverter.cs @@ -0,0 +1,29 @@ +using System; +using System.Globalization; +using System.Resources; +using System.Windows.Data; + +namespace Common.Wpf +{ + public class EnumToResourceConverter : IValueConverter + { + public ResourceManager ResourceManager { get; set; } + + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + if (value == null) + return string.Empty; + + var resourceKey = value.GetType().Name + "_" + value; + + var resourceValue = ResourceManager.GetString(resourceKey); + + return resourceValue ?? string.Format("EnumToResourceConverter: {0} not found", resourceKey); + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } + } +} diff --git a/RepositionPopupBehavior.cs b/RepositionPopupBehavior.cs new file mode 100644 index 0000000..bf6352c --- /dev/null +++ b/RepositionPopupBehavior.cs @@ -0,0 +1,91 @@ +using System; +using System.Windows; +using System.Windows.Controls.Primitives; +using System.Windows.Interactivity; + +namespace Common.Wpf +{ + /// + /// Defines the reposition behavior of a control when the window to which it is attached is moved or resized. + /// + /// + /// This solution was influenced by the answers provided by NathanAW and + /// Jason to + /// this question. + /// + public class RepositionPopupBehavior : Behavior + { + #region Protected Methods + + /// + /// Called after the behavior is attached to an . + /// + protected override void OnAttached() + { + base.OnAttached(); + var window = Window.GetWindow(AssociatedObject.PlacementTarget); + if (window == null) { return; } + window.LocationChanged += OnLocationChanged; + window.SizeChanged += OnSizeChanged; + AssociatedObject.Loaded += AssociatedObject_Loaded; + } + + void AssociatedObject_Loaded(object sender, RoutedEventArgs e) + { + //AssociatedObject.HorizontalOffset = 7; + //AssociatedObject.VerticalOffset = -AssociatedObject.Height; + } + + /// + /// Called when the behavior is being detached from its , but before it has actually occurred. + /// + protected override void OnDetaching() + { + base.OnDetaching(); + var window = Window.GetWindow(AssociatedObject.PlacementTarget); + if (window == null) { return; } + window.LocationChanged -= OnLocationChanged; + window.SizeChanged -= OnSizeChanged; + AssociatedObject.Loaded -= AssociatedObject_Loaded; + } + + #endregion Protected Methods + + #region Private Methods + + /// + /// Handles the routed event which occurs when the window's location changes. + /// + /// + /// The source of the event. + /// + /// + /// An object that contains the event data. + /// + private void OnLocationChanged(object sender, EventArgs e) + { + var offset = AssociatedObject.HorizontalOffset; + AssociatedObject.HorizontalOffset = offset + 1; + AssociatedObject.HorizontalOffset = offset; + } + + /// + /// Handles the routed event which occurs when either then or the + /// properties change value. + /// + /// + /// The source of the event. + /// + /// + /// An object that contains the event data. + /// + private void OnSizeChanged(object sender, SizeChangedEventArgs e) + { + var offset = AssociatedObject.HorizontalOffset; + AssociatedObject.HorizontalOffset = offset + 1; + AssociatedObject.HorizontalOffset = offset; + } + + #endregion Private Methods + } +} \ No newline at end of file diff --git a/ValidationResources.xaml b/ValidationResources.xaml new file mode 100644 index 0000000..a726018 --- /dev/null +++ b/ValidationResources.xaml @@ -0,0 +1,91 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file