mirror of
https://github.com/ckaczor/Common.Wpf.git
synced 2026-01-13 17:22:47 -05:00
Reorganize files
This commit is contained in:
@@ -154,7 +154,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="CheckedListItem.cs" />
|
<Compile Include="CheckedListItem.cs" />
|
||||||
<Compile Include="EnumToResourceConverter.cs" />
|
<Compile Include="Resource\EnumToResourceConverter.cs" />
|
||||||
<Compile Include="ExtendedListBoxControl\ExtendedListBox.cs" />
|
<Compile Include="ExtendedListBoxControl\ExtendedListBox.cs" />
|
||||||
<Compile Include="ExtendedListBoxControl\ExtendedListBoxItem.cs" />
|
<Compile Include="ExtendedListBoxControl\ExtendedListBoxItem.cs" />
|
||||||
<Compile Include="Extensions\ApplicationExtensions.cs" />
|
<Compile Include="Extensions\ApplicationExtensions.cs" />
|
||||||
@@ -181,7 +181,7 @@
|
|||||||
<Compile Include="HtmlLabelControl\TextFragmentStyle.cs" />
|
<Compile Include="HtmlLabelControl\TextFragmentStyle.cs" />
|
||||||
<Compile Include="HtmlLabelControl\TextParser.cs" />
|
<Compile Include="HtmlLabelControl\TextParser.cs" />
|
||||||
<AppDesigner Include="Properties\" />
|
<AppDesigner Include="Properties\" />
|
||||||
<Compile Include="RepositionPopupBehavior.cs" />
|
<Compile Include="Validation\RepositionPopupBehavior.cs" />
|
||||||
<Compile Include="TextListControl\TextList.xaml.cs">
|
<Compile Include="TextListControl\TextList.xaml.cs">
|
||||||
<DependentUpon>TextList.xaml</DependentUpon>
|
<DependentUpon>TextList.xaml</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
@@ -190,6 +190,7 @@
|
|||||||
<DependentUpon>ImageButton.xaml</DependentUpon>
|
<DependentUpon>ImageButton.xaml</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="Toolbar\SplitButton\SplitButton.cs" />
|
<Compile Include="Toolbar\SplitButton\SplitButton.cs" />
|
||||||
|
<Compile Include="Validation\ValidationModelBase.cs" />
|
||||||
<Compile Include="Windows\ControlBox.cs" />
|
<Compile Include="Windows\ControlBox.cs" />
|
||||||
<Compile Include="Windows\SnappingWindow.cs" />
|
<Compile Include="Windows\SnappingWindow.cs" />
|
||||||
<Compile Include="Windows\WindowInformation.cs" />
|
<Compile Include="Windows\WindowInformation.cs" />
|
||||||
@@ -221,7 +222,7 @@
|
|||||||
<Generator>MSBuild:Compile</Generator>
|
<Generator>MSBuild:Compile</Generator>
|
||||||
<SubType>Designer</SubType>
|
<SubType>Designer</SubType>
|
||||||
</Page>
|
</Page>
|
||||||
<Page Include="ValidationResources.xaml">
|
<Page Include="Validation\ValidationResources.xaml">
|
||||||
<SubType>Designer</SubType>
|
<SubType>Designer</SubType>
|
||||||
<Generator>MSBuild:Compile</Generator>
|
<Generator>MSBuild:Compile</Generator>
|
||||||
</Page>
|
</Page>
|
||||||
|
|||||||
@@ -102,7 +102,7 @@ namespace Common.Wpf.Extensions
|
|||||||
public static void ClearAllValidationErrors(this DependencyObject window, IEnumerable<BindingExpressionInfo> bindingExpressions)
|
public static void ClearAllValidationErrors(this DependencyObject window, IEnumerable<BindingExpressionInfo> bindingExpressions)
|
||||||
{
|
{
|
||||||
foreach (var expression in bindingExpressions)
|
foreach (var expression in bindingExpressions)
|
||||||
Validation.ClearInvalid(expression.BindingExpression);
|
System.Windows.Controls.Validation.ClearInvalid(expression.BindingExpression);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool Validate(this Window window)
|
public static bool Validate(this Window window)
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ using System.Globalization;
|
|||||||
using System.Resources;
|
using System.Resources;
|
||||||
using System.Windows.Data;
|
using System.Windows.Data;
|
||||||
|
|
||||||
namespace Common.Wpf
|
namespace Common.Wpf.Resource
|
||||||
{
|
{
|
||||||
public class EnumToResourceConverter : IValueConverter
|
public class EnumToResourceConverter : IValueConverter
|
||||||
{
|
{
|
||||||
@@ -3,7 +3,7 @@ using System.Windows;
|
|||||||
using System.Windows.Controls.Primitives;
|
using System.Windows.Controls.Primitives;
|
||||||
using System.Windows.Interactivity;
|
using System.Windows.Interactivity;
|
||||||
|
|
||||||
namespace Common.Wpf
|
namespace Common.Wpf.Validation
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Defines the reposition behavior of a <see cref="Popup"/> control when the window to which it is attached is moved or resized.
|
/// Defines the reposition behavior of a <see cref="Popup"/> control when the window to which it is attached is moved or resized.
|
||||||
86
Validation/ValidationModelBase.cs
Normal file
86
Validation/ValidationModelBase.cs
Normal 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
|
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">
|
<ControlTemplate x:Key="ValidationTemplate">
|
||||||
<StackPanel Orientation="Horizontal">
|
<StackPanel Orientation="Horizontal">
|
||||||
<!-- Defines TextBox outline border and the ToolTipCorner -->
|
<!-- Defines TextBox outline border and the ToolTipCorner -->
|
||||||
@@ -39,7 +39,7 @@
|
|||||||
PlacementRectangle="10,-1,0,0">
|
PlacementRectangle="10,-1,0,0">
|
||||||
<!-- Used to reposition Popup when dialog moves or resizes -->
|
<!-- Used to reposition Popup when dialog moves or resizes -->
|
||||||
<i:Interaction.Behaviors>
|
<i:Interaction.Behaviors>
|
||||||
<wpf:RepositionPopupBehavior />
|
<validation:RepositionPopupBehavior />
|
||||||
</i:Interaction.Behaviors>
|
</i:Interaction.Behaviors>
|
||||||
<Popup.Style>
|
<Popup.Style>
|
||||||
<Style TargetType="{x:Type Popup}">
|
<Style TargetType="{x:Type Popup}">
|
||||||
Reference in New Issue
Block a user