mirror of
https://github.com/ckaczor/Common.Wpf.git
synced 2026-01-14 01:25:37 -05:00
Upgrade .NET framework
Add enum to resource converter Add validation resources and logic
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
@@ -10,7 +10,7 @@
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>Common.Wpf</RootNamespace>
|
||||
<AssemblyName>Common.Wpf</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
|
||||
<TargetFrameworkVersion>v4.5.1</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
@@ -35,7 +35,8 @@
|
||||
<IsWebBootstrapper>false</IsWebBootstrapper>
|
||||
<UseApplicationTrust>false</UseApplicationTrust>
|
||||
<BootstrapperEnabled>true</BootstrapperEnabled>
|
||||
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
|
||||
<TargetFrameworkProfile>
|
||||
</TargetFrameworkProfile>
|
||||
<SccProjectName>SAK</SccProjectName>
|
||||
<SccLocalPath>SAK</SccLocalPath>
|
||||
<SccAuxPath>SAK</SccAuxPath>
|
||||
@@ -51,6 +52,7 @@
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
|
||||
<Prefer32Bit>false</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
@@ -60,6 +62,7 @@
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
|
||||
<Prefer32Bit>false</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
@@ -76,6 +79,7 @@
|
||||
<CodeAnalysisIgnoreBuiltInRuleSets>true</CodeAnalysisIgnoreBuiltInRuleSets>
|
||||
<CodeAnalysisRuleDirectories>;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop\\Rules</CodeAnalysisRuleDirectories>
|
||||
<CodeAnalysisIgnoreBuiltInRules>true</CodeAnalysisIgnoreBuiltInRules>
|
||||
<Prefer32Bit>false</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
|
||||
<OutputPath>bin\x86\Release\</OutputPath>
|
||||
@@ -91,6 +95,7 @@
|
||||
<CodeAnalysisRuleSetDirectories>;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\\Rule Sets</CodeAnalysisRuleSetDirectories>
|
||||
<CodeAnalysisRuleDirectories>;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop\\Rules</CodeAnalysisRuleDirectories>
|
||||
<CodeAnalysisIgnoreBuiltInRules>true</CodeAnalysisIgnoreBuiltInRules>
|
||||
<Prefer32Bit>false</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
@@ -106,6 +111,7 @@
|
||||
<CodeAnalysisRuleSetDirectories>;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\\Rule Sets</CodeAnalysisRuleSetDirectories>
|
||||
<CodeAnalysisRuleDirectories>;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop\\Rules</CodeAnalysisRuleDirectories>
|
||||
<CodeAnalysisIgnoreBuiltInRules>false</CodeAnalysisIgnoreBuiltInRules>
|
||||
<Prefer32Bit>false</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
|
||||
<OutputPath>bin\x64\Release\</OutputPath>
|
||||
@@ -122,6 +128,7 @@
|
||||
<CodeAnalysisIgnoreBuiltInRuleSets>true</CodeAnalysisIgnoreBuiltInRuleSets>
|
||||
<CodeAnalysisRuleDirectories>;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop\\Rules</CodeAnalysisRuleDirectories>
|
||||
<CodeAnalysisIgnoreBuiltInRules>true</CodeAnalysisIgnoreBuiltInRules>
|
||||
<Prefer32Bit>false</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="PresentationFramework.Luna" />
|
||||
@@ -132,6 +139,7 @@
|
||||
<Reference Include="System.Deployment" />
|
||||
<Reference Include="System.Drawing" />
|
||||
<Reference Include="System.Windows.Forms" />
|
||||
<Reference Include="System.Windows.Interactivity, Version=4.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
|
||||
<Reference Include="System.Xaml" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="WindowsBase">
|
||||
@@ -146,6 +154,7 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="CheckedListItem.cs" />
|
||||
<Compile Include="EnumToResourceConverter.cs" />
|
||||
<Compile Include="ExtendedListBoxControl\ExtendedListBox.cs" />
|
||||
<Compile Include="ExtendedListBoxControl\ExtendedListBoxItem.cs" />
|
||||
<Compile Include="Extensions\ApplicationExtensions.cs" />
|
||||
@@ -172,6 +181,7 @@
|
||||
<Compile Include="HtmlLabelControl\TextFragmentStyle.cs" />
|
||||
<Compile Include="HtmlLabelControl\TextParser.cs" />
|
||||
<AppDesigner Include="Properties\" />
|
||||
<Compile Include="RepositionPopupBehavior.cs" />
|
||||
<Compile Include="TextListControl\TextList.xaml.cs">
|
||||
<DependentUpon>TextList.xaml</DependentUpon>
|
||||
</Compile>
|
||||
@@ -211,6 +221,10 @@
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
<SubType>Designer</SubType>
|
||||
</Page>
|
||||
<Page Include="ValidationResources.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
|
||||
|
||||
29
EnumToResourceConverter.cs
Normal file
29
EnumToResourceConverter.cs
Normal file
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
91
RepositionPopupBehavior.cs
Normal file
91
RepositionPopupBehavior.cs
Normal file
@@ -0,0 +1,91 @@
|
||||
using System;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls.Primitives;
|
||||
using System.Windows.Interactivity;
|
||||
|
||||
namespace Common.Wpf
|
||||
{
|
||||
/// <summary>
|
||||
/// Defines the reposition behavior of a <see cref="Popup"/> control when the window to which it is attached is moved or resized.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This solution was influenced by the answers provided by <see href="http://stackoverflow.com/users/262204/nathanaw">NathanAW</see> and
|
||||
/// <see href="http://stackoverflow.com/users/718325/jason">Jason</see> to
|
||||
/// <see href="http://stackoverflow.com/questions/1600218/how-can-i-move-a-wpf-popup-when-its-anchor-element-moves">this</see> question.
|
||||
/// </remarks>
|
||||
public class RepositionPopupBehavior : Behavior<Popup>
|
||||
{
|
||||
#region Protected Methods
|
||||
|
||||
/// <summary>
|
||||
/// Called after the behavior is attached to an <see cref="Behavior.AssociatedObject"/>.
|
||||
/// </summary>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called when the behavior is being detached from its <see cref="Behavior.AssociatedObject"/>, but before it has actually occurred.
|
||||
/// </summary>
|
||||
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
|
||||
|
||||
/// <summary>
|
||||
/// Handles the <see cref="Window.LocationChanged"/> routed event which occurs when the window's location changes.
|
||||
/// </summary>
|
||||
/// <param name="sender">
|
||||
/// The source of the event.
|
||||
/// </param>
|
||||
/// <param name="e">
|
||||
/// An object that contains the event data.
|
||||
/// </param>
|
||||
private void OnLocationChanged(object sender, EventArgs e)
|
||||
{
|
||||
var offset = AssociatedObject.HorizontalOffset;
|
||||
AssociatedObject.HorizontalOffset = offset + 1;
|
||||
AssociatedObject.HorizontalOffset = offset;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles the <see cref="Window.SizeChanged"/> routed event which occurs when either then <see cref="Window.ActualHeight"/> or the
|
||||
/// <see cref="Window.ActualWidth"/> properties change value.
|
||||
/// </summary>
|
||||
/// <param name="sender">
|
||||
/// The source of the event.
|
||||
/// </param>
|
||||
/// <param name="e">
|
||||
/// An object that contains the event data.
|
||||
/// </param>
|
||||
private void OnSizeChanged(object sender, SizeChangedEventArgs e)
|
||||
{
|
||||
var offset = AssociatedObject.HorizontalOffset;
|
||||
AssociatedObject.HorizontalOffset = offset + 1;
|
||||
AssociatedObject.HorizontalOffset = offset;
|
||||
}
|
||||
|
||||
#endregion Private Methods
|
||||
}
|
||||
}
|
||||
91
ValidationResources.xaml
Normal file
91
ValidationResources.xaml
Normal file
@@ -0,0 +1,91 @@
|
||||
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
|
||||
xmlns:wpf="clr-namespace:Common.Wpf">
|
||||
<ControlTemplate x:Key="ValidationTemplate">
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<!-- Defines TextBox outline border and the ToolTipCorner -->
|
||||
<Border x:Name="border"
|
||||
BorderThickness="1.25"
|
||||
BorderBrush="#FFDC000C">
|
||||
<Grid>
|
||||
<Polygon x:Name="toolTipCorner"
|
||||
Grid.ZIndex="2"
|
||||
Margin="-1"
|
||||
Points="9,9 9,0 0,0"
|
||||
Fill="#FFDC000C"
|
||||
HorizontalAlignment="Right"
|
||||
VerticalAlignment="Top"
|
||||
IsHitTestVisible="True" />
|
||||
<Polyline Grid.ZIndex="3"
|
||||
Points="10,10 0,0"
|
||||
Margin="-1"
|
||||
HorizontalAlignment="Right"
|
||||
StrokeThickness="1.5"
|
||||
StrokeEndLineCap="Round"
|
||||
StrokeStartLineCap="Round"
|
||||
Stroke="White"
|
||||
VerticalAlignment="Top"
|
||||
IsHitTestVisible="True" />
|
||||
<AdornedElementPlaceholder x:Name="adorner" />
|
||||
</Grid>
|
||||
</Border>
|
||||
<!-- Defines the Popup -->
|
||||
<Popup x:Name="placard"
|
||||
AllowsTransparency="True"
|
||||
PopupAnimation="Fade"
|
||||
Placement="Top"
|
||||
PlacementTarget="{Binding ElementName=toolTipCorner}"
|
||||
PlacementRectangle="10,-1,0,0">
|
||||
<!-- Used to reposition Popup when dialog moves or resizes -->
|
||||
<i:Interaction.Behaviors>
|
||||
<wpf:RepositionPopupBehavior />
|
||||
</i:Interaction.Behaviors>
|
||||
<Popup.Style>
|
||||
<Style TargetType="{x:Type Popup}">
|
||||
<Style.Triggers>
|
||||
<!-- Shows Popup when TextBox has focus -->
|
||||
<DataTrigger Binding="{Binding ElementName=adorner, Path=AdornedElement.IsFocused}"
|
||||
Value="True">
|
||||
<Setter Property="IsOpen"
|
||||
Value="True" />
|
||||
</DataTrigger>
|
||||
<!-- Shows Popup when mouse hovers over ToolTipCorner -->
|
||||
<DataTrigger Binding="{Binding ElementName=toolTipCorner, Path=IsMouseOver}"
|
||||
Value="True">
|
||||
<Setter Property="IsOpen"
|
||||
Value="True" />
|
||||
</DataTrigger>
|
||||
<!-- Hides Popup when window is no longer active -->
|
||||
<DataTrigger Binding="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=IsActive}"
|
||||
Value="False">
|
||||
<Setter Property="IsOpen"
|
||||
Value="False" />
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</Popup.Style>
|
||||
<Border x:Name="errorBorder"
|
||||
Background="#FFDC000C"
|
||||
Margin="0,0,8,8"
|
||||
Opacity="1"
|
||||
CornerRadius="4"
|
||||
IsHitTestVisible="False"
|
||||
MinHeight="24"
|
||||
MaxWidth="267">
|
||||
<Border.Effect>
|
||||
<DropShadowEffect ShadowDepth="4"
|
||||
Color="Black"
|
||||
Opacity="0.6"
|
||||
Direction="315"
|
||||
BlurRadius="4" />
|
||||
</Border.Effect>
|
||||
<TextBlock Text="{Binding ElementName=adorner, Path=AdornedElement.(Validation.Errors).CurrentItem.ErrorContent}"
|
||||
Foreground="White"
|
||||
Margin="8,3,8,3"
|
||||
TextWrapping="Wrap" />
|
||||
</Border>
|
||||
</Popup>
|
||||
</StackPanel>
|
||||
</ControlTemplate>
|
||||
</ResourceDictionary>
|
||||
Reference in New Issue
Block a user