Reorganize files

This commit is contained in:
2014-06-21 10:16:23 -04:00
parent c5de3f70f3
commit 6651a5772e
6 changed files with 95 additions and 8 deletions

View File

@@ -154,7 +154,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="CheckedListItem.cs" />
<Compile Include="EnumToResourceConverter.cs" />
<Compile Include="Resource\EnumToResourceConverter.cs" />
<Compile Include="ExtendedListBoxControl\ExtendedListBox.cs" />
<Compile Include="ExtendedListBoxControl\ExtendedListBoxItem.cs" />
<Compile Include="Extensions\ApplicationExtensions.cs" />
@@ -181,7 +181,7 @@
<Compile Include="HtmlLabelControl\TextFragmentStyle.cs" />
<Compile Include="HtmlLabelControl\TextParser.cs" />
<AppDesigner Include="Properties\" />
<Compile Include="RepositionPopupBehavior.cs" />
<Compile Include="Validation\RepositionPopupBehavior.cs" />
<Compile Include="TextListControl\TextList.xaml.cs">
<DependentUpon>TextList.xaml</DependentUpon>
</Compile>
@@ -190,6 +190,7 @@
<DependentUpon>ImageButton.xaml</DependentUpon>
</Compile>
<Compile Include="Toolbar\SplitButton\SplitButton.cs" />
<Compile Include="Validation\ValidationModelBase.cs" />
<Compile Include="Windows\ControlBox.cs" />
<Compile Include="Windows\SnappingWindow.cs" />
<Compile Include="Windows\WindowInformation.cs" />
@@ -221,7 +222,7 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="ValidationResources.xaml">
<Page Include="Validation\ValidationResources.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>

View File

@@ -102,7 +102,7 @@ namespace Common.Wpf.Extensions
public static void ClearAllValidationErrors(this DependencyObject window, IEnumerable<BindingExpressionInfo> bindingExpressions)
{
foreach (var expression in bindingExpressions)
Validation.ClearInvalid(expression.BindingExpression);
System.Windows.Controls.Validation.ClearInvalid(expression.BindingExpression);
}
public static bool Validate(this Window window)

View File

@@ -3,7 +3,7 @@ using System.Globalization;
using System.Resources;
using System.Windows.Data;
namespace Common.Wpf
namespace Common.Wpf.Resource
{
public class EnumToResourceConverter : IValueConverter
{

View File

@@ -3,7 +3,7 @@ using System.Windows;
using System.Windows.Controls.Primitives;
using System.Windows.Interactivity;
namespace Common.Wpf
namespace Common.Wpf.Validation
{
/// <summary>
/// Defines the reposition behavior of a <see cref="Popup"/> control when the window to which it is attached is moved or resized.

View File

@@ -0,0 +1,86 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Runtime.CompilerServices;
namespace Common.Wpf.Validation
{
public class ValidationModelBase : INotifyPropertyChanged, INotifyDataErrorInfo
{
#region Property changed
public event PropertyChangedEventHandler PropertyChanged = delegate { };
protected void NotifyPropertyChanged(string propertyName)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
#endregion
#region Notify data error
private readonly Dictionary<string, List<string>> _errors = new Dictionary<string, List<string>>();
public event EventHandler<DataErrorsChangedEventArgs> ErrorsChanged = delegate { };
// get errors by property
public IEnumerable GetErrors(string propertyName)
{
if (_errors.ContainsKey(propertyName))
return _errors[propertyName];
return null;
}
// has errors
public bool HasErrors
{
get { return (_errors.Count > 0); }
}
// object is valid
public bool IsValid
{
get { return !HasErrors; }
}
public void AddError(string error, [CallerMemberName] string propertyName = null)
{
if (propertyName == null)
return;
// Add error to list
_errors[propertyName] = new List<string> { error };
NotifyErrorsChanged(propertyName);
}
public void RemoveError([CallerMemberName] string propertyName = null)
{
if (propertyName == null)
return;
// remove error
if (_errors.ContainsKey(propertyName))
_errors.Remove(propertyName);
NotifyErrorsChanged(propertyName);
}
private void NotifyErrorsChanged(string propertyName)
{
ErrorsChanged(this, new DataErrorsChangedEventArgs(propertyName));
}
#endregion
protected void SetProperty<T>(ref T propertyValue, T newValue, [CallerMemberName] string propertyName = null)
{
if (Equals(propertyValue, newValue))
return;
propertyValue = newValue;
NotifyPropertyChanged(propertyName);
NotifyErrorsChanged(propertyName);
}
}
}

View File

@@ -1,7 +1,7 @@
<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">
xmlns:validation="clr-namespace:Common.Wpf.Validation">
<ControlTemplate x:Key="ValidationTemplate">
<StackPanel Orientation="Horizontal">
<!-- Defines TextBox outline border and the ToolTipCorner -->
@@ -39,7 +39,7 @@
PlacementRectangle="10,-1,0,0">
<!-- Used to reposition Popup when dialog moves or resizes -->
<i:Interaction.Behaviors>
<wpf:RepositionPopupBehavior />
<validation:RepositionPopupBehavior />
</i:Interaction.Behaviors>
<Popup.Style>
<Style TargetType="{x:Type Popup}">