├── .gitattributes
├── .gitignore
├── DotNetProjects.WPF.Converters
├── DotNetProjects.WPF.Converters.sln
└── DotNetProjects.WPF.Converters
│ ├── Behaviors
│ ├── CopyPaste
│ │ ├── ClipboardSecurityExceptionEventArgs.cs
│ │ ├── Commands
│ │ │ ├── ClipboardCommandBase.cs
│ │ │ ├── CommandBase.cs
│ │ │ ├── CopyCommand.cs
│ │ │ ├── CutCommand.cs
│ │ │ ├── DeleteCommand.cs
│ │ │ ├── PasteCommand.cs
│ │ │ ├── SelectAllCommand.cs
│ │ │ └── UndoCommand.cs
│ │ ├── ControlStdCommandsBehavior.cs
│ │ ├── IClipboardSecurityExceptionNotify.cs
│ │ ├── Images
│ │ │ ├── CopyHS.png
│ │ │ ├── CutHS.png
│ │ │ ├── DeleteHS.png
│ │ │ ├── Edit_UndoHS.png
│ │ │ └── PasteHS.png
│ │ └── StdCommandActionType.cs
│ ├── DragDropBehavior.cs
│ ├── ExposeFirstVisibleItemBehavior.cs
│ ├── ICloneableBehavior.cs
│ ├── InputBindingsManager.cs
│ ├── NumericTextBoxBehavior.cs
│ ├── StylizedBehaviors.cs
│ └── TabContent.cs
│ ├── BitmapConversion.cs
│ ├── Collections
│ └── ObservableDictionary.cs
│ ├── Converters
│ ├── AlternationEqualityConverter.cs
│ ├── BoolToValueConverter.cs
│ ├── ByteArrayToImageConverter.cs
│ ├── ByteIntArrayConverter.cs
│ ├── ByteToIntConverter.cs
│ ├── CenterConverter.cs
│ ├── CommaPositionConverter.cs
│ ├── DatabindingDebugConverter.cs
│ ├── DateTimeToLongTimeStringConverter.cs
│ ├── DateTimeToShortDateStringConverter.cs
│ ├── DiagnosisMessageBackGroundConverter.cs
│ ├── DoubleMultiplicationConverter.cs
│ ├── DoubleRangeConverter.cs
│ ├── DoubleToLog10Converter.cs
│ ├── EnumConverter.cs
│ ├── EnumEqualToVisibilityConverter.cs
│ ├── EnumFlagsConverter.cs
│ ├── EnumToIntConverter.cs
│ ├── EnumToTranslateStringConverter.cs
│ ├── EqualityToBooleanConverter.cs
│ ├── GuidEmptyToCollapsedConverter.cs
│ ├── GuidEmptyToNullConverter.cs
│ ├── I18NPlaceHoldersConverter.cs
│ ├── IEnumerableConverter.cs
│ ├── IEnumerableToCountConverter.cs
│ ├── IntIndexToBrushConverter.cs
│ ├── IntLessOrEqualToVisibilityConverter.cs
│ ├── IntMultiplicationConverter.cs
│ ├── IntRangeConverter.cs
│ ├── IntToBoolConverter.cs
│ ├── IntToBrushConverter.cs
│ ├── IntToDoubleConverter.cs
│ ├── IntToHiddenConverter.cs
│ ├── IntToVisibilityConverter.cs
│ ├── InvertConverter.cs
│ ├── ItemLineNumbersConverter.cs
│ ├── ListIntToVisibilityConverter.cs
│ ├── ListStringConverter.cs
│ ├── LongToDateTimeConverter.cs
│ ├── MonorailInfoDisplayAngleConverter.cs
│ ├── MultiBoolToVisibilityConverter.cs
│ ├── NotNullOrEmptyToVisible.cs
│ ├── NullOrEmptyToCollapsed.cs
│ ├── NullOrEmptyToVisible.cs
│ ├── NullToBrushConverter.cs
│ ├── NullToCollapsedConverter.cs
│ ├── NullToFalseConverter.cs
│ ├── NullToTrueConverter.cs
│ ├── NullToVisibleConverter.cs
│ ├── NullableBoolToValueConverter.cs
│ ├── NullableDecimalToPercentageConverter.cs
│ ├── NullableTimeSpanToMillisecondsConverter.cs
│ ├── ObjectToStringConverter.cs
│ ├── ResourcePointStateToBrushConverter.cs
│ ├── StringEmptyOrEqualVisibillityConverter.cs
│ ├── StringLastPartConverter.cs
│ ├── StringNullConverter.cs
│ ├── StringStripCharsConverter.cs
│ ├── StringStripFillCharConverter.cs
│ ├── StringToBoolConverter.cs
│ ├── ToEnumConverter.cs
│ ├── TreeViewLineConverter.cs
│ ├── TrueToFalseConverter.cs
│ ├── TypeToObjectArrayConverter.cs
│ ├── UtcToLocalTimeConverter.cs
│ ├── ValueConverter.cs
│ ├── VisibilityToBoolConverter.cs
│ ├── WidthConverter.cs
│ └── WithAndHeightToRectangleGeometryConverter.cs
│ ├── DotNetProjects.WPF.Converters.csproj
│ ├── ExtensionMethods
│ ├── ListBoxExtension.cs
│ └── TreeViewExtensions.cs
│ ├── GhostCursor.cs
│ ├── Panels
│ ├── AnimatedWrapPanel.cs
│ ├── CirclePanel.cs
│ ├── ColumnedPanel.cs
│ ├── FanPanel.cs
│ ├── FishEyePanel.cs
│ ├── LoopPanel.cs
│ ├── RadialPanel.cs
│ ├── SliderPanel.cs
│ ├── VirtualizingTilePanel.cs
│ └── VirtualizingWrapPanel.cs
│ ├── Properties
│ ├── AssemblyInfo.cs
│ ├── Resources.Designer.cs
│ ├── Resources.resx
│ ├── Settings.Designer.cs
│ └── Settings.settings
│ ├── ResolveElementName.cs
│ ├── UIHelpers.cs
│ └── WinFormsImage.cs
├── LICENSE
├── appveyor.yml
└── nuget
├── Package.nuspec
└── pack.ps1
/.gitattributes:
--------------------------------------------------------------------------------
1 | ###############################################################################
2 | # Set default behavior to automatically normalize line endings.
3 | ###############################################################################
4 | * text=auto
5 |
6 | ###############################################################################
7 | # Set default behavior for command prompt diff.
8 | #
9 | # This is need for earlier builds of msysgit that does not have it on by
10 | # default for csharp files.
11 | # Note: This is only used by command line
12 | ###############################################################################
13 | #*.cs diff=csharp
14 |
15 | ###############################################################################
16 | # Set the merge driver for project and solution files
17 | #
18 | # Merging from the command prompt will add diff markers to the files if there
19 | # are conflicts (Merging from VS is not affected by the settings below, in VS
20 | # the diff markers are never inserted). Diff markers may cause the following
21 | # file extensions to fail to load in VS. An alternative would be to treat
22 | # these files as binary and thus will always conflict and require user
23 | # intervention with every merge. To do so, just uncomment the entries below
24 | ###############################################################################
25 | #*.sln merge=binary
26 | #*.csproj merge=binary
27 | #*.vbproj merge=binary
28 | #*.vcxproj merge=binary
29 | #*.vcproj merge=binary
30 | #*.dbproj merge=binary
31 | #*.fsproj merge=binary
32 | #*.lsproj merge=binary
33 | #*.wixproj merge=binary
34 | #*.modelproj merge=binary
35 | #*.sqlproj merge=binary
36 | #*.wwaproj merge=binary
37 |
38 | ###############################################################################
39 | # behavior for image files
40 | #
41 | # image files are treated as binary by default.
42 | ###############################################################################
43 | #*.jpg binary
44 | #*.png binary
45 | #*.gif binary
46 |
47 | ###############################################################################
48 | # diff behavior for common document formats
49 | #
50 | # Convert binary document formats to text before diffing them. This feature
51 | # is only available from the command line. Turn it on by uncommenting the
52 | # entries below.
53 | ###############################################################################
54 | #*.doc diff=astextplain
55 | #*.DOC diff=astextplain
56 | #*.docx diff=astextplain
57 | #*.DOCX diff=astextplain
58 | #*.dot diff=astextplain
59 | #*.DOT diff=astextplain
60 | #*.pdf diff=astextplain
61 | #*.PDF diff=astextplain
62 | #*.rtf diff=astextplain
63 | #*.RTF diff=astextplain
64 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 |
4 | # User-specific files
5 | *.suo
6 | *.user
7 | *.userosscache
8 | *.sln.docstates
9 |
10 | # User-specific files (MonoDevelop/Xamarin Studio)
11 | *.userprefs
12 |
13 | # Build results
14 | [Dd]ebug/
15 | [Dd]ebugPublic/
16 | [Rr]elease/
17 | [Rr]eleases/
18 | x64/
19 | x86/
20 | bld/
21 | [Bb]in/
22 | [Oo]bj/
23 | [Ll]og/
24 |
25 | # Visual Studio 2015 cache/options directory
26 | .vs/
27 | # Uncomment if you have tasks that create the project's static files in wwwroot
28 | #wwwroot/
29 |
30 | # MSTest test Results
31 | [Tt]est[Rr]esult*/
32 | [Bb]uild[Ll]og.*
33 |
34 | # NUNIT
35 | *.VisualState.xml
36 | TestResult.xml
37 |
38 | # Build Results of an ATL Project
39 | [Dd]ebugPS/
40 | [Rr]eleasePS/
41 | dlldata.c
42 |
43 | # DNX
44 | project.lock.json
45 | artifacts/
46 |
47 | *_i.c
48 | *_p.c
49 | *_i.h
50 | *.ilk
51 | *.meta
52 | *.obj
53 | *.pch
54 | *.pdb
55 | *.pgc
56 | *.pgd
57 | *.rsp
58 | *.sbr
59 | *.tlb
60 | *.tli
61 | *.tlh
62 | *.tmp
63 | *.tmp_proj
64 | *.log
65 | *.vspscc
66 | *.vssscc
67 | .builds
68 | *.pidb
69 | *.svclog
70 | *.scc
71 |
72 | # Chutzpah Test files
73 | _Chutzpah*
74 |
75 | # Visual C++ cache files
76 | ipch/
77 | *.aps
78 | *.ncb
79 | *.opendb
80 | *.opensdf
81 | *.sdf
82 | *.cachefile
83 | *.VC.db
84 | *.VC.VC.opendb
85 |
86 | # Visual Studio profiler
87 | *.psess
88 | *.vsp
89 | *.vspx
90 | *.sap
91 |
92 | # TFS 2012 Local Workspace
93 | $tf/
94 |
95 | # Guidance Automation Toolkit
96 | *.gpState
97 |
98 | # ReSharper is a .NET coding add-in
99 | _ReSharper*/
100 | *.[Rr]e[Ss]harper
101 | *.DotSettings.user
102 |
103 | # JustCode is a .NET coding add-in
104 | .JustCode
105 |
106 | # TeamCity is a build add-in
107 | _TeamCity*
108 |
109 | # DotCover is a Code Coverage Tool
110 | *.dotCover
111 |
112 | # NCrunch
113 | _NCrunch_*
114 | .*crunch*.local.xml
115 | nCrunchTemp_*
116 |
117 | # MightyMoose
118 | *.mm.*
119 | AutoTest.Net/
120 |
121 | # Web workbench (sass)
122 | .sass-cache/
123 |
124 | # Installshield output folder
125 | [Ee]xpress/
126 |
127 | # DocProject is a documentation generator add-in
128 | DocProject/buildhelp/
129 | DocProject/Help/*.HxT
130 | DocProject/Help/*.HxC
131 | DocProject/Help/*.hhc
132 | DocProject/Help/*.hhk
133 | DocProject/Help/*.hhp
134 | DocProject/Help/Html2
135 | DocProject/Help/html
136 |
137 | # Click-Once directory
138 | publish/
139 |
140 | # Publish Web Output
141 | *.[Pp]ublish.xml
142 | *.azurePubxml
143 | # TODO: Comment the next line if you want to checkin your web deploy settings
144 | # but database connection strings (with potential passwords) will be unencrypted
145 | *.pubxml
146 | *.publishproj
147 |
148 | # Microsoft Azure Web App publish settings. Comment the next line if you want to
149 | # checkin your Azure Web App publish settings, but sensitive information contained
150 | # in these scripts will be unencrypted
151 | PublishScripts/
152 |
153 | # NuGet Packages
154 | *.nupkg
155 | # The packages folder can be ignored because of Package Restore
156 | **/packages/*
157 | # except build/, which is used as an MSBuild target.
158 | !**/packages/build/
159 | # Uncomment if necessary however generally it will be regenerated when needed
160 | #!**/packages/repositories.config
161 | # NuGet v3's project.json files produces more ignoreable files
162 | *.nuget.props
163 | *.nuget.targets
164 |
165 | # Microsoft Azure Build Output
166 | csx/
167 | *.build.csdef
168 |
169 | # Microsoft Azure Emulator
170 | ecf/
171 | rcf/
172 |
173 | # Windows Store app package directories and files
174 | AppPackages/
175 | BundleArtifacts/
176 | Package.StoreAssociation.xml
177 | _pkginfo.txt
178 |
179 | # Visual Studio cache files
180 | # files ending in .cache can be ignored
181 | *.[Cc]ache
182 | # but keep track of directories ending in .cache
183 | !*.[Cc]ache/
184 |
185 | # Others
186 | ClientBin/
187 | ~$*
188 | *~
189 | *.dbmdl
190 | *.dbproj.schemaview
191 | *.pfx
192 | *.publishsettings
193 | node_modules/
194 | orleans.codegen.cs
195 |
196 | # Since there are multiple workflows, uncomment next line to ignore bower_components
197 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
198 | #bower_components/
199 |
200 | # RIA/Silverlight projects
201 | Generated_Code/
202 |
203 | # Backup & report files from converting an old project file
204 | # to a newer Visual Studio version. Backup files are not needed,
205 | # because we have git ;-)
206 | _UpgradeReport_Files/
207 | Backup*/
208 | UpgradeLog*.XML
209 | UpgradeLog*.htm
210 |
211 | # SQL Server files
212 | *.mdf
213 | *.ldf
214 |
215 | # Business Intelligence projects
216 | *.rdl.data
217 | *.bim.layout
218 | *.bim_*.settings
219 |
220 | # Microsoft Fakes
221 | FakesAssemblies/
222 |
223 | # GhostDoc plugin setting file
224 | *.GhostDoc.xml
225 |
226 | # Node.js Tools for Visual Studio
227 | .ntvs_analysis.dat
228 |
229 | # Visual Studio 6 build log
230 | *.plg
231 |
232 | # Visual Studio 6 workspace options file
233 | *.opt
234 |
235 | # Visual Studio LightSwitch build output
236 | **/*.HTMLClient/GeneratedArtifacts
237 | **/*.DesktopClient/GeneratedArtifacts
238 | **/*.DesktopClient/ModelManifest.xml
239 | **/*.Server/GeneratedArtifacts
240 | **/*.Server/ModelManifest.xml
241 | _Pvt_Extensions
242 |
243 | # Paket dependency manager
244 | .paket/paket.exe
245 | paket-files/
246 |
247 | # FAKE - F# Make
248 | .fake/
249 |
250 | # JetBrains Rider
251 | .idea/
252 | *.sln.iml
253 |
--------------------------------------------------------------------------------
/DotNetProjects.WPF.Converters/DotNetProjects.WPF.Converters.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 14
4 | VisualStudioVersion = 14.0.25420.1
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DotNetProjects.WPF.Converters", "DotNetProjects.WPF.Converters\DotNetProjects.WPF.Converters.csproj", "{70DFB62D-4FBB-4EE7-92C8-C92E49243D5C}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|Any CPU = Debug|Any CPU
11 | Release|Any CPU = Release|Any CPU
12 | EndGlobalSection
13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
14 | {70DFB62D-4FBB-4EE7-92C8-C92E49243D5C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15 | {70DFB62D-4FBB-4EE7-92C8-C92E49243D5C}.Debug|Any CPU.Build.0 = Debug|Any CPU
16 | {70DFB62D-4FBB-4EE7-92C8-C92E49243D5C}.Release|Any CPU.ActiveCfg = Release|Any CPU
17 | {70DFB62D-4FBB-4EE7-92C8-C92E49243D5C}.Release|Any CPU.Build.0 = Release|Any CPU
18 | EndGlobalSection
19 | GlobalSection(SolutionProperties) = preSolution
20 | HideSolutionNode = FALSE
21 | EndGlobalSection
22 | EndGlobal
23 |
--------------------------------------------------------------------------------
/DotNetProjects.WPF.Converters/DotNetProjects.WPF.Converters/Behaviors/CopyPaste/ClipboardSecurityExceptionEventArgs.cs:
--------------------------------------------------------------------------------
1 | using System.Security;
2 | using System.Windows;
3 |
4 | namespace DotNetProjects.WPF.Converters.Behaviors.CopyPaste
5 | {
6 | public class ClipboardSecurityExceptionEventArgs : RoutedEventArgs
7 | {
8 | ///
9 | /// Exception thrown by system when application tried to get access to clipboard.
10 | ///
11 | public SecurityException Exception { get; private set; }
12 |
13 | ///
14 | /// Action type on which exception was thrown.
15 | ///
16 | public StdCommandActionType StdCommandActionType { get; private set; }
17 |
18 | public ClipboardSecurityExceptionEventArgs(SecurityException exception,
19 | StdCommandActionType stdCommandActionType)
20 | {
21 | this.Exception = exception;
22 | this.StdCommandActionType = stdCommandActionType;
23 | }
24 | }
25 | }
--------------------------------------------------------------------------------
/DotNetProjects.WPF.Converters/DotNetProjects.WPF.Converters/Behaviors/CopyPaste/Commands/ClipboardCommandBase.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Security;
3 | using System.Windows;
4 |
5 | namespace DotNetProjects.WPF.Converters.Behaviors.CopyPaste.Commands
6 | {
7 | ///
8 | /// Abstract class with base code for all textbox's standard commands, which uses clipboard.
9 | ///
10 | internal abstract class ClipboardCommandBase : CommandBase
11 | {
12 | private IClipboardSecurityExceptionNotify _clipboardSecurityExceptionNotify;
13 |
14 | protected ClipboardCommandBase(UIElement UIElement, IClipboardSecurityExceptionNotify clipboardSecurityExceptionNotify)
15 | : base(UIElement)
16 | {
17 | if (clipboardSecurityExceptionNotify == null)
18 | throw new ArgumentNullException("clipboardSecurityExceptionNotify");
19 |
20 | this._clipboardSecurityExceptionNotify = clipboardSecurityExceptionNotify;
21 | }
22 |
23 | ///
24 | /// Method for handle SecurityException with clipboard.
25 | ///
26 | ///
27 | ///
28 | protected void OnClipboardSecurityException(SecurityException exception, StdCommandActionType actionType)
29 | {
30 | this._clipboardSecurityExceptionNotify.OnClipboardSecurityExceptionEvent(
31 | new ClipboardSecurityExceptionEventArgs(exception, actionType));
32 | }
33 |
34 | protected override void OnDisposing()
35 | {
36 | this._clipboardSecurityExceptionNotify = null;
37 | base.OnDisposing();
38 |
39 | }
40 | }
41 | }
--------------------------------------------------------------------------------
/DotNetProjects.WPF.Converters/DotNetProjects.WPF.Converters/Behaviors/CopyPaste/Commands/CommandBase.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Windows;
3 | using System.Windows.Controls;
4 | using System.Windows.Input;
5 |
6 | namespace DotNetProjects.WPF.Converters.Behaviors.CopyPaste.Commands
7 | {
8 | ///
9 | /// Abstract class with base code for all textbox's standard commands.
10 | ///
11 | internal abstract class CommandBase : ICommand, IDisposable
12 | {
13 | internal string getText()
14 | {
15 | if (this.UIElement is TextBox) return ((TextBox)this.UIElement).Text;
16 | if (this.UIElement is TextBlock) return ((TextBlock)this.UIElement).Text;
17 | if (this.UIElement is ContentControl)
18 | {
19 | var cnt = ((ContentControl)this.UIElement).Content;
20 | if (cnt != null && cnt is TextBlock)
21 | return ((TextBlock)cnt).Text.ToString();
22 | else if (cnt != null && cnt is TextBox)
23 | return ((TextBox)cnt).Text.ToString();
24 | return ((ContentControl)this.UIElement).Content.ToString();
25 | }
26 | return null;
27 | }
28 |
29 | private bool _isDisposed = false;
30 |
31 | ///
32 | /// Constructor
33 | ///
34 | /// Associated object. Cannot be null.
35 | protected CommandBase(UIElement UIElement)
36 | {
37 | if (UIElement == null)
38 | throw new ArgumentNullException("UIElement");
39 |
40 | this.UIElement = UIElement;
41 | }
42 |
43 | ~CommandBase()
44 | {
45 | this.Dispose(false);
46 | }
47 |
48 | ///
49 | /// Associated TextBox
50 | ///
51 | protected UIElement UIElement { get; private set; }
52 |
53 | ///
54 | /// Is current command can be executed
55 | ///
56 | /// Not used.
57 | ///
58 | bool ICommand.CanExecute(object parameter)
59 | {
60 | return this.CanExecute();
61 | }
62 |
63 | ///
64 | /// Execute current command.
65 | /// Check before execution that current command can be executed with method.
66 | ///
67 | /// Not used.
68 | void ICommand.Execute(object parameter)
69 | {
70 | if (this.CanExecute())
71 | this.Execute();
72 | }
73 |
74 | ///
75 | /// If current command can be executed.
76 | /// Default realization return true.
77 | ///
78 | ///
79 | public virtual bool CanExecute()
80 | {
81 | return true;
82 | }
83 |
84 | ///
85 | /// Abstract method to executed current command.
86 | ///
87 | public abstract void Execute();
88 |
89 | ///
90 | /// Subscribe to handle state change of CanExecute
91 | ///
92 | public event EventHandler CanExecuteChanged;
93 |
94 | public void RaiseCanExecuteChanged()
95 | {
96 | EventHandler handler = this.CanExecuteChanged;
97 | if (handler != null)
98 | handler(this, EventArgs.Empty);
99 | }
100 |
101 | public void Dispose()
102 | {
103 | this.Dispose(true);
104 | GC.SuppressFinalize(this);
105 | }
106 |
107 | private void Dispose(bool isDisposing)
108 | {
109 | if (!this._isDisposed)
110 | {
111 | if (isDisposing)
112 | {
113 | this.OnDisposing();
114 | this.CanExecuteChanged = null;
115 | this.UIElement = null;
116 | }
117 | this._isDisposed = true;
118 | }
119 | }
120 |
121 | protected virtual void OnDisposing()
122 | {
123 | }
124 | }
125 | }
--------------------------------------------------------------------------------
/DotNetProjects.WPF.Converters/DotNetProjects.WPF.Converters/Behaviors/CopyPaste/Commands/CopyCommand.cs:
--------------------------------------------------------------------------------
1 | using System.Security;
2 | using System.Windows;
3 | using System.Windows.Controls;
4 |
5 | namespace DotNetProjects.WPF.Converters.Behaviors.CopyPaste.Commands
6 | {
7 | ///
8 | /// Command for TextBox's Context Menu.
9 | /// Do copy of selected text.
10 | /// Can't be executed if not text is selected.
11 | ///
12 | internal class CopyCommand : ClipboardCommandBase
13 | {
14 | public CopyCommand(UIElement UIElement, IClipboardSecurityExceptionNotify clipboardSecurityExceptionNotify)
15 | : base(UIElement, clipboardSecurityExceptionNotify)
16 | {
17 | }
18 |
19 | public override void Execute()
20 | {
21 | try
22 | {
23 | if (this.UIElement is TextBox)
24 | {
25 | var textBox = this.UIElement as TextBox;
26 | if (textBox.SelectionLength == 0)
27 | Clipboard.SetText(textBox.Text);
28 | else
29 | Clipboard.SetText(textBox.SelectedText);
30 |
31 | textBox.Focus();
32 | }
33 | else
34 | {
35 | Clipboard.SetText(this.getText());
36 | }
37 | }
38 | catch (SecurityException ex)
39 | {
40 | this.OnClipboardSecurityException(ex, StdCommandActionType.Copy);
41 | }
42 |
43 | }
44 |
45 | public override bool CanExecute()
46 | {
47 | return !string.IsNullOrEmpty(this.getText());
48 | }
49 | }
50 | }
--------------------------------------------------------------------------------
/DotNetProjects.WPF.Converters/DotNetProjects.WPF.Converters/Behaviors/CopyPaste/Commands/CutCommand.cs:
--------------------------------------------------------------------------------
1 | using System.Security;
2 | using System.Windows;
3 | using System.Windows.Controls;
4 |
5 | namespace DotNetProjects.WPF.Converters.Behaviors.CopyPaste.Commands
6 | {
7 | ///
8 | /// Command for TextBox's Context Menu.
9 | /// Do cut of selected text.
10 | /// Can't be executed if not text is selected.
11 | ///
12 | internal class CutCommand : ClipboardCommandBase
13 | {
14 | private TextBox TextBox;
15 |
16 | public CutCommand(TextBox textBox, IClipboardSecurityExceptionNotify clipboardSecurityExceptionNotify)
17 | : base(textBox, clipboardSecurityExceptionNotify)
18 | {
19 | this.TextBox = textBox;
20 | }
21 |
22 | public override void Execute()
23 | {
24 | try
25 | {
26 | Clipboard.SetText(this.TextBox.SelectedText);
27 | }
28 | catch (SecurityException ex)
29 | {
30 | this.OnClipboardSecurityException(ex, StdCommandActionType.Cut);
31 | }
32 | this.TextBox.SelectedText = string.Empty;
33 | this.TextBox.Focus();
34 | }
35 |
36 | public override bool CanExecute()
37 | {
38 | return this.TextBox.IsEnabled && !this.TextBox.IsReadOnly && this.TextBox.SelectionLength > 0;
39 | }
40 | }
41 | }
--------------------------------------------------------------------------------
/DotNetProjects.WPF.Converters/DotNetProjects.WPF.Converters/Behaviors/CopyPaste/Commands/DeleteCommand.cs:
--------------------------------------------------------------------------------
1 | using System.Windows.Controls;
2 |
3 | namespace DotNetProjects.WPF.Converters.Behaviors.CopyPaste.Commands
4 | {
5 | ///
6 | /// Command for TextBox's Context Menu.
7 | /// Do delete of selected text.
8 | /// Can't be executed if not text is selected.
9 | ///
10 | internal class DeleteCommand : CommandBase
11 | {
12 | private TextBox TextBox;
13 |
14 | public DeleteCommand(TextBox textBox) : base(textBox)
15 | {
16 | this.TextBox = textBox;
17 | }
18 |
19 | public override void Execute()
20 | {
21 | this.TextBox.SelectedText = string.Empty;
22 | this.TextBox.Focus();
23 | }
24 |
25 | public override bool CanExecute()
26 | {
27 | return this.TextBox.IsEnabled && !this.TextBox.IsReadOnly && this.TextBox.SelectionLength > 0;
28 | }
29 | }
30 | }
--------------------------------------------------------------------------------
/DotNetProjects.WPF.Converters/DotNetProjects.WPF.Converters/Behaviors/CopyPaste/Commands/PasteCommand.cs:
--------------------------------------------------------------------------------
1 | using System.Security;
2 | using System.Windows;
3 | using System.Windows.Controls;
4 |
5 | namespace DotNetProjects.WPF.Converters.Behaviors.CopyPaste.Commands
6 | {
7 | ///
8 | /// Command for TextBox's Context Menu.
9 | /// Do paste text from clipboard to selected text.
10 | /// Can't be executed if clipboard doesn't contains any text.
11 | ///
12 | internal class PasteCommand : ClipboardCommandBase
13 | {
14 | private TextBox TextBox;
15 |
16 | public PasteCommand(TextBox textBox, IClipboardSecurityExceptionNotify clipboardSecurityExceptionNotify)
17 | : base(textBox, clipboardSecurityExceptionNotify)
18 | {
19 | this.TextBox = textBox;
20 | }
21 |
22 | public override void Execute()
23 | {
24 | try
25 | {
26 | this.TextBox.SelectedText = Clipboard.GetText();
27 | }
28 | catch (SecurityException ex)
29 | {
30 | this.OnClipboardSecurityException(ex, StdCommandActionType.Paste);
31 | }
32 | this.TextBox.Focus();
33 | }
34 |
35 | public override bool CanExecute()
36 | {
37 | return this.TextBox.IsEnabled && !this.TextBox.IsReadOnly && Clipboard.ContainsText();
38 | }
39 | }
40 | }
--------------------------------------------------------------------------------
/DotNetProjects.WPF.Converters/DotNetProjects.WPF.Converters/Behaviors/CopyPaste/Commands/SelectAllCommand.cs:
--------------------------------------------------------------------------------
1 | using System.Windows.Controls;
2 |
3 | namespace DotNetProjects.WPF.Converters.Behaviors.CopyPaste.Commands
4 | {
5 | ///
6 | /// Command for TextBox's Context Menu.
7 | /// Do select All Text in TextBox.
8 | /// Can't be executed if all text is already selected or text is empty.
9 | ///
10 | internal class SelectAllCommand : CommandBase
11 | {
12 | private TextBox TextBox;
13 |
14 | public SelectAllCommand(TextBox textBox) : base(textBox)
15 | {
16 | this.TextBox = textBox;
17 | }
18 |
19 | public override void Execute()
20 | {
21 | this.TextBox.SelectAll();
22 | this.TextBox.Focus();
23 | }
24 |
25 | public override bool CanExecute()
26 | {
27 | return !string.IsNullOrEmpty(this.TextBox.Text) &&
28 | this.TextBox.Text.Length != this.TextBox.SelectedText.Length;
29 | }
30 | }
31 | }
--------------------------------------------------------------------------------
/DotNetProjects.WPF.Converters/DotNetProjects.WPF.Converters/Behaviors/CopyPaste/Commands/UndoCommand.cs:
--------------------------------------------------------------------------------
1 | using System.Windows.Controls;
2 |
3 | namespace DotNetProjects.WPF.Converters.Behaviors.CopyPaste.Commands
4 | {
5 | ///
6 | /// Command for TextBox's Context Menu.
7 | /// Do undo of text last operation.
8 | /// Can't be executed if text didn't changed.
9 | ///
10 | internal class UndoCommand : CommandBase
11 | {
12 | private TextBox TextBox;
13 |
14 | private string _oldText;
15 | private string _currentText;
16 |
17 | public UndoCommand(TextBox textBox)
18 | :base(textBox)
19 | {
20 | this.TextBox = textBox;
21 | this.TextBox.TextChanged += this.TextBoxTextChanged;
22 | this._currentText = this.TextBox.Text;
23 | }
24 |
25 | private void TextBoxTextChanged(object sender, TextChangedEventArgs e)
26 | {
27 | this._oldText = this._currentText;
28 | this._currentText = this.TextBox.Text;
29 | }
30 |
31 | public override bool CanExecute()
32 | {
33 | // Null state - text is not changed.
34 | // If somebody change text to empty then it will be string.Empty, but not null.
35 | return this.TextBox.IsEnabled && !this.TextBox.IsReadOnly && this._oldText != null;
36 | }
37 |
38 | public override void Execute()
39 | {
40 | this.TextBox.Text = this._oldText;
41 | this.TextBox.Focus();
42 | }
43 |
44 | protected override void OnDisposing()
45 | {
46 | base.OnDisposing();
47 | this.TextBox.TextChanged -= this.TextBoxTextChanged;
48 | }
49 | }
50 | }
--------------------------------------------------------------------------------
/DotNetProjects.WPF.Converters/DotNetProjects.WPF.Converters/Behaviors/CopyPaste/IClipboardSecurityExceptionNotify.cs:
--------------------------------------------------------------------------------
1 | namespace DotNetProjects.WPF.Converters.Behaviors.CopyPaste
2 | {
3 | ///
4 | /// Interface for handle security exceptions with clipboard.
5 | ///
6 | internal interface IClipboardSecurityExceptionNotify
7 | {
8 | void OnClipboardSecurityExceptionEvent(ClipboardSecurityExceptionEventArgs args);
9 | }
10 | }
--------------------------------------------------------------------------------
/DotNetProjects.WPF.Converters/DotNetProjects.WPF.Converters/Behaviors/CopyPaste/Images/CopyHS.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dotnetprojects/WpfConverters/c19bea236217ed633cf8545e27eb434a1b297dc7/DotNetProjects.WPF.Converters/DotNetProjects.WPF.Converters/Behaviors/CopyPaste/Images/CopyHS.png
--------------------------------------------------------------------------------
/DotNetProjects.WPF.Converters/DotNetProjects.WPF.Converters/Behaviors/CopyPaste/Images/CutHS.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dotnetprojects/WpfConverters/c19bea236217ed633cf8545e27eb434a1b297dc7/DotNetProjects.WPF.Converters/DotNetProjects.WPF.Converters/Behaviors/CopyPaste/Images/CutHS.png
--------------------------------------------------------------------------------
/DotNetProjects.WPF.Converters/DotNetProjects.WPF.Converters/Behaviors/CopyPaste/Images/DeleteHS.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dotnetprojects/WpfConverters/c19bea236217ed633cf8545e27eb434a1b297dc7/DotNetProjects.WPF.Converters/DotNetProjects.WPF.Converters/Behaviors/CopyPaste/Images/DeleteHS.png
--------------------------------------------------------------------------------
/DotNetProjects.WPF.Converters/DotNetProjects.WPF.Converters/Behaviors/CopyPaste/Images/Edit_UndoHS.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dotnetprojects/WpfConverters/c19bea236217ed633cf8545e27eb434a1b297dc7/DotNetProjects.WPF.Converters/DotNetProjects.WPF.Converters/Behaviors/CopyPaste/Images/Edit_UndoHS.png
--------------------------------------------------------------------------------
/DotNetProjects.WPF.Converters/DotNetProjects.WPF.Converters/Behaviors/CopyPaste/Images/PasteHS.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dotnetprojects/WpfConverters/c19bea236217ed633cf8545e27eb434a1b297dc7/DotNetProjects.WPF.Converters/DotNetProjects.WPF.Converters/Behaviors/CopyPaste/Images/PasteHS.png
--------------------------------------------------------------------------------
/DotNetProjects.WPF.Converters/DotNetProjects.WPF.Converters/Behaviors/CopyPaste/StdCommandActionType.cs:
--------------------------------------------------------------------------------
1 | namespace DotNetProjects.WPF.Converters.Behaviors.CopyPaste
2 | {
3 | public enum StdCommandActionType
4 | {
5 | Undo,
6 | Copy,
7 | Cut,
8 | Paste,
9 | Delete,
10 | SelectAll
11 | }
12 | }
--------------------------------------------------------------------------------
/DotNetProjects.WPF.Converters/DotNetProjects.WPF.Converters/Behaviors/DragDropBehavior.cs:
--------------------------------------------------------------------------------
1 | /**************************************************************
2 | * Copyright (c) 2009 Charlie Robbins
3 | *
4 | * Permission is hereby granted, free of charge, to any person
5 | * obtaining a copy of this software and associated documentation
6 | * files (the "Software"), to deal in the Software without
7 | * restriction, including without limitation the rights to use,
8 | * copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | * copies of the Software, and to permit persons to whom the
10 | * Software is furnished to do so, subject to the following
11 | * conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be
14 | * included in all copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 | * OTHER DEALINGS IN THE SOFTWARE.
24 | **************************************************************/
25 |
26 | using System;
27 | using System.Windows;
28 | using System.Windows.Input;
29 | using System.Windows.Interactivity;
30 | using System.Windows.Media;
31 |
32 | namespace DotNetProjects.WPF.Converters.Behaviors
33 | {
34 | public class DragDropBehavior : Behavior, ICloneableBehavior
35 | {
36 | #region IsHost Property
37 |
38 | public static readonly DependencyProperty IsHostProperty = DependencyProperty.RegisterAttached(
39 | "IsHost",
40 | typeof(bool),
41 | typeof(DragDropBehavior),
42 | new PropertyMetadata(false));
43 |
44 | public delegate void MouseClickDelegate(object sender, EventArgs e);
45 | public event MouseClickDelegate MouseClick;
46 |
47 |
48 | public static bool GetIsHost(DependencyObject obj)
49 | {
50 | return (bool)obj.GetValue(IsHostProperty);
51 | }
52 |
53 | public static void SetIsHost(DependencyObject obj, bool value)
54 | {
55 | obj.SetValue(IsHostProperty, value);
56 | }
57 |
58 | #endregion
59 |
60 | #region X Property
61 |
62 | private double x = double.NaN;
63 | public double X
64 | {
65 | get
66 | {
67 | return this.x;
68 | }
69 |
70 | set
71 | {
72 | this.x = value;
73 | }
74 | }
75 |
76 | #endregion
77 |
78 | #region Y Property
79 |
80 | private double y = double.NaN;
81 | public double Y
82 | {
83 | get
84 | {
85 | return this.y;
86 | }
87 |
88 | set
89 | {
90 | this.y = value;
91 | }
92 | }
93 |
94 | #endregion
95 |
96 | protected override void OnAttached()
97 | {
98 | base.OnAttached();
99 | //this.AssociatedObject.MouseLeftButtonDown += DragStart;
100 | this.AssociatedObject.AddHandler(FrameworkElement.MouseLeftButtonDownEvent, new MouseButtonEventHandler(this.DragStart), true);
101 |
102 | }
103 |
104 | protected override void OnDetaching()
105 | {
106 | base.OnDetaching();
107 | this.AssociatedObject.RemoveHandler(FrameworkElement.MouseLeftButtonDownEvent, new MouseButtonEventHandler(this.DragStart));
108 | //this.AssociatedObject.MouseLeftButtonDown -= DragStart;
109 | }
110 |
111 | private bool ignoreMouseUp = false;
112 |
113 | private void DragStart(object sender, MouseButtonEventArgs args)
114 | {
115 | this.ignoreMouseUp = false;
116 |
117 | UIElement dragSource = sender as UIElement;
118 |
119 | // Create the TranslateTransform that will perform our drag operation
120 | TranslateTransform dragTransform = new TranslateTransform();
121 | dragTransform.X = 0;
122 | dragTransform.Y = 0;
123 |
124 | // Set the TranslateTransform if it is the first time DragDrop is being used
125 | dragSource.RenderTransform = (dragSource.RenderTransform is TranslateTransform) ? dragSource.RenderTransform : dragTransform;
126 |
127 | // Attach the event handlers for MouseMove and MouseLeftButtonUp for dragging and dropping respectively
128 | dragSource.MouseMove += this.DragDelta;
129 | //dragSource.MouseLeftButtonUp += DragComplete;
130 | this.AssociatedObject.AddHandler(FrameworkElement.MouseLeftButtonUpEvent, new MouseButtonEventHandler(this.DragComplete), true);
131 |
132 | //Capture the Mouse
133 | dragSource.CaptureMouse();
134 | }
135 |
136 | private void DragDelta(object sender, MouseEventArgs args)
137 | {
138 | FrameworkElement dragSource = sender as FrameworkElement;
139 |
140 | // Calculate the offset of the dragSource and update its TranslateTransform
141 | FrameworkElement dragDropHost = FindDragDropHost(dragSource);
142 | Point relativeLocationInHost = args.GetPosition(dragDropHost);
143 | Point relativeLocationInSource = args.GetPosition(dragSource);
144 |
145 | // Calculate the delta from the previous position
146 | double xChange = relativeLocationInHost.X - this.X;
147 | double yChange = relativeLocationInHost.Y - this.Y;
148 |
149 | // Update the position if this is not the first mouse move
150 | if (!double.IsNaN(this.X))
151 | {
152 | ((TranslateTransform)dragSource.RenderTransform).X += xChange;
153 | this.ignoreMouseUp = true;
154 | }
155 |
156 | if (!double.IsNaN(this.Y))
157 | {
158 | ((TranslateTransform)dragSource.RenderTransform).Y += yChange;
159 | this.ignoreMouseUp = true;
160 | }
161 |
162 | // Update our private attached properties for tracking drag location
163 | this.X = relativeLocationInHost.X;
164 | this.Y = relativeLocationInHost.Y;
165 | }
166 |
167 | private void DragComplete(object sender, MouseButtonEventArgs args)
168 | {
169 | UIElement dragSource = sender as UIElement;
170 |
171 | dragSource.MouseMove -= this.DragDelta;
172 | //dragSource.MouseLeftButtonUp -= DragComplete;
173 | this.AssociatedObject.RemoveHandler(FrameworkElement.MouseLeftButtonDownEvent, new MouseButtonEventHandler(this.DragComplete));
174 |
175 | // Set the X & Y Values so that they can be reset next MouseDown
176 | this.X = double.NaN;
177 | this.Y = double.NaN;
178 |
179 | // Release Mouse Capture
180 | dragSource.ReleaseMouseCapture();
181 |
182 | if (!this.ignoreMouseUp && this.MouseClick != null)
183 | {
184 | this.ignoreMouseUp = true;
185 | this.MouseClick(this, new EventArgs());
186 | }
187 | }
188 |
189 | public static FrameworkElement FindDragDropHost(UIElement element)
190 | {
191 | DependencyObject parent = VisualTreeHelper.GetParent(element);
192 | while (parent != null && !GetIsHost(parent))
193 | {
194 | parent = VisualTreeHelper.GetParent(parent);
195 | }
196 |
197 | return parent as FrameworkElement;
198 | }
199 |
200 | public object CloneBehavior()
201 | {
202 | return new DragDropBehavior();
203 | }
204 | }
205 | }
206 |
--------------------------------------------------------------------------------
/DotNetProjects.WPF.Converters/DotNetProjects.WPF.Converters/Behaviors/ExposeFirstVisibleItemBehavior.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Windows;
4 | using System.Windows.Controls;
5 | using DotNetProjects.WPF.Converters.ExtensionMethods;
6 |
7 | namespace DotNetProjects.WPF.Converters.Behaviors
8 | {
9 | ///
10 | /// Exposes a ListBox's first visible item for (two-way)
11 | /// binding to a view model.
12 | ///
13 | /// Author: Dominik Schmidt (www.dominikschmidt.net)
14 | ///
15 | public class ExposeFirstVisibleItemBehavior
16 | {
17 | #region fields
18 |
19 | // keeping track of list boxes not to add handler multiple times
20 | private static List _listBoxes = new List();
21 |
22 | #endregion
23 |
24 | #region attached behavior
25 |
26 | public static readonly DependencyProperty FirstVisibleItemProperty =
27 | DependencyProperty.RegisterAttached("FirstVisibleItem", typeof(object), typeof(ExposeFirstVisibleItemBehavior),
28 | new FrameworkPropertyMetadata() { PropertyChangedCallback = OnFirstVisibleItemChanged, BindsTwoWayByDefault = true });
29 |
30 | public static object GetFirstVisibleItem(DependencyObject d)
31 | {
32 | if (d == null) throw new ArgumentNullException();
33 | return d.GetValue(FirstVisibleItemProperty);
34 | }
35 |
36 | public static void SetFirstVisibleItem(DependencyObject d, object value)
37 | {
38 | if (d == null) throw new ArgumentNullException();
39 | d.SetValue(FirstVisibleItemProperty, value);
40 | }
41 |
42 | private static void OnFirstVisibleItemChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
43 | {
44 | ListBox listBox = d as ListBox;
45 |
46 | if (d == null)
47 | throw new InvalidOperationException("The FirstVisibleItem attached property can only be applied to ListBox controls.");
48 |
49 | // add scroll changed handler only if not yet added
50 | if (!_listBoxes.Contains(listBox))
51 | {
52 | _listBoxes.Add(listBox);
53 | listBox.AddHandler(ScrollViewer.ScrollChangedEvent, new ScrollChangedEventHandler(ScrollChanged));
54 | }
55 |
56 | if (e.OldValue != e.NewValue)
57 | listBox.SetFirstVisibleItem(e.NewValue);
58 | }
59 |
60 | #endregion
61 |
62 | #region scrolling
63 |
64 | // updates first visible item after scrolling
65 | private static void ScrollChanged(object sender, ScrollChangedEventArgs e)
66 | {
67 | ListBox listBox = (ListBox)sender;
68 | if (listBox.Items.Count > 0 && listBox.GetPanel() != null)
69 | SetFirstVisibleItem(listBox, listBox.GetFirstVisibleItem());
70 | }
71 |
72 | #endregion
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/DotNetProjects.WPF.Converters/DotNetProjects.WPF.Converters/Behaviors/ICloneableBehavior.cs:
--------------------------------------------------------------------------------
1 | namespace DotNetProjects.WPF.Converters.Behaviors
2 | {
3 | //Base Class, for a Behavior that is Cloneable
4 | public interface ICloneableBehavior
5 | {
6 | object CloneBehavior();
7 | }
8 |
9 | }
10 |
--------------------------------------------------------------------------------
/DotNetProjects.WPF.Converters/DotNetProjects.WPF.Converters/Behaviors/InputBindingsManager.cs:
--------------------------------------------------------------------------------
1 | using System.Windows;
2 | using System.Windows.Data;
3 | using System.Windows.Input;
4 |
5 | namespace DotNetProjects.WPF.Converters.Behaviors
6 | {
7 | ///
8 | /// This Class is for usage with a TextBox, so that the Press of Enter Updates the Binding Source!
9 | /// Code from: http://stackoverflow.com/questions/563195/wpf-textbox-databind-on-enterkey-press
10 | ///
11 | public static class InputBindingsManager
12 | {
13 | public static readonly DependencyProperty UpdatePropertySourceWhenEnterPressedProperty = DependencyProperty.RegisterAttached(
14 | "UpdatePropertySourceWhenEnterPressedProperty", typeof(DependencyProperty), typeof(InputBindingsManager), new PropertyMetadata(null, OnUpdatePropertySourceWhenEnterPressedPropertyChanged));
15 |
16 | static InputBindingsManager()
17 | {
18 |
19 | }
20 |
21 | public static void SetUpdatePropertySourceWhenEnterPressedProperty(DependencyObject dp, DependencyProperty value)
22 | {
23 | dp.SetValue(UpdatePropertySourceWhenEnterPressedProperty, value);
24 | }
25 |
26 | public static DependencyProperty GetUpdatePropertySourceWhenEnterPressedProperty(DependencyObject dp)
27 | {
28 | return (DependencyProperty)dp.GetValue(UpdatePropertySourceWhenEnterPressedProperty);
29 | }
30 |
31 | private static void OnUpdatePropertySourceWhenEnterPressedPropertyChanged(DependencyObject dp, DependencyPropertyChangedEventArgs e)
32 | {
33 | UIElement element = dp as UIElement;
34 |
35 | if (element == null)
36 | {
37 | return;
38 | }
39 |
40 | if (e.OldValue != null)
41 | {
42 | element.PreviewKeyDown -= HandlePreviewKeyDown;
43 | }
44 |
45 | if (e.NewValue != null)
46 | {
47 | element.PreviewKeyDown += new KeyEventHandler(HandlePreviewKeyDown);
48 | }
49 | }
50 |
51 | static void HandlePreviewKeyDown(object sender, KeyEventArgs e)
52 | {
53 | if (e.Key == Key.Enter)
54 | {
55 | DoUpdateSource(e.Source);
56 | }
57 | }
58 |
59 | static void DoUpdateSource(object source)
60 | {
61 | DependencyProperty property =
62 | GetUpdatePropertySourceWhenEnterPressedProperty(source as DependencyObject);
63 |
64 | if (property == null)
65 | {
66 | return;
67 | }
68 |
69 | UIElement elt = source as UIElement;
70 |
71 | if (elt == null)
72 | {
73 | return;
74 | }
75 |
76 | BindingExpression binding = BindingOperations.GetBindingExpression(elt, property);
77 |
78 | if (binding != null)
79 | {
80 | binding.UpdateSource();
81 | }
82 | }
83 | }
84 | }
85 |
--------------------------------------------------------------------------------
/DotNetProjects.WPF.Converters/DotNetProjects.WPF.Converters/Behaviors/NumericTextBoxBehavior.cs:
--------------------------------------------------------------------------------
1 | using System.Text.RegularExpressions;
2 | using System.Windows;
3 | using System.Windows.Controls;
4 | using System.Windows.Input;
5 | using System.Windows.Interactivity;
6 |
7 | namespace DotNetProjects.WPF.Converters.Behaviors
8 | {
9 | ///
10 | /// An attached behavior that allows forces all input to a TextBox to be numeric
11 | ///
12 | public class NumericTextBoxBehavior : Behavior, ICloneableBehavior
13 | {
14 |
15 | ///
16 | /// Called when attached to a TextBox.
17 | ///
18 | protected override void OnAttached()
19 | {
20 | this.AssociatedObject.PreviewTextInput += OnPreviewTextInput;
21 | DataObject.AddPastingHandler(this.AssociatedObject, OnClipboardPaste);
22 | }
23 |
24 | ///
25 | /// This method handles paste and drag/drop events onto the TextBox. It restricts the character
26 | /// set and ensures we have consistent behavior.
27 | ///
28 | /// TextBox sender
29 | /// EventArgs
30 | private void OnClipboardPaste(object sender, DataObjectPastingEventArgs e)
31 | {
32 | string text = e.SourceDataObject.GetData(e.FormatToApply) as string;
33 |
34 | if (!string.IsNullOrEmpty(text) && !Validate(text))
35 | e.CancelCommand();
36 | }
37 |
38 | ///
39 | /// This checks if the resulting string will match the regex expression
40 | ///
41 | private void OnPreviewTextInput(object sender, TextCompositionEventArgs e)
42 | {
43 | if (!Validate(e.Text))
44 | e.Handled = true;
45 | }
46 |
47 |
48 | private bool Validate(string newContent)
49 | {
50 | string testString = string.Empty;
51 |
52 | // replace selection with new text.
53 | if (!string.IsNullOrEmpty(this.AssociatedObject.SelectedText))
54 | {
55 | string pre = this.AssociatedObject.Text.Substring(0, this.AssociatedObject.SelectionStart);
56 | string after = this.AssociatedObject.Text.Substring(this.AssociatedObject.SelectionStart + this.AssociatedObject.SelectionLength, this.AssociatedObject.Text.Length - (this.AssociatedObject.SelectionStart + this.AssociatedObject.SelectionLength));
57 | testString = pre + newContent + after;
58 | }
59 | else
60 | {
61 | string pre = this.AssociatedObject.Text.Substring(0, this.AssociatedObject.CaretIndex);
62 | string after = this.AssociatedObject.Text.Substring(this.AssociatedObject.CaretIndex, this.AssociatedObject.Text.Length - this.AssociatedObject.CaretIndex);
63 | testString = pre + newContent + after;
64 | }
65 |
66 | Regex regExpr = new Regex(@"^([-+]?)(\d*)([,.]?)(\d*)$");
67 | if (regExpr.IsMatch(testString))
68 | return true;
69 |
70 | return false;
71 | }
72 |
73 | public object CloneBehavior()
74 | {
75 | return new NumericTextBoxBehavior();
76 | }
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/DotNetProjects.WPF.Converters/DotNetProjects.WPF.Converters/Behaviors/StylizedBehaviors.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.ObjectModel;
3 | using System.Windows;
4 | using System.Windows.Interactivity;
5 |
6 | namespace DotNetProjects.WPF.Converters.Behaviors
7 | {
8 |
9 | public class StylizedBehaviorCollection : Collection
10 | { }
11 |
12 | ///
13 | /// Helper Class to apply Behaviors via a Style.
14 | /// But the Behavior has to implement ICloneableBehavior!
15 | ///
16 | public class StylizedBehaviors
17 | {
18 | #region Fields (public)
19 | public static readonly DependencyProperty BehaviorsProperty = DependencyProperty.RegisterAttached(
20 | @"Behaviors",
21 | typeof(StylizedBehaviorCollection),
22 | typeof(StylizedBehaviors),
23 | new PropertyMetadata(null, OnPropertyChanged));
24 | #endregion
25 | #region Static Methods (public)
26 | public static StylizedBehaviorCollection GetBehaviors(DependencyObject uie)
27 | {
28 | return (StylizedBehaviorCollection)uie.GetValue(BehaviorsProperty);
29 | }
30 |
31 | public static void SetBehaviors(DependencyObject uie, StylizedBehaviorCollection value)
32 | {
33 | uie.SetValue(BehaviorsProperty, value);
34 | }
35 | #endregion
36 |
37 | #region Static Methods (private)
38 | private static void OnPropertyChanged(DependencyObject dpo, DependencyPropertyChangedEventArgs e)
39 | {
40 | var uie = dpo as UIElement;
41 |
42 | if (uie == null)
43 | {
44 | return;
45 | }
46 |
47 | BehaviorCollection itemBehaviors = Interaction.GetBehaviors(uie);
48 |
49 | var newBehaviors = e.NewValue as StylizedBehaviorCollection;
50 | var oldBehaviors = e.OldValue as StylizedBehaviorCollection;
51 |
52 | if (newBehaviors == oldBehaviors)
53 | {
54 | return;
55 | }
56 |
57 | if (oldBehaviors != null)
58 | {
59 | foreach (var behavior in oldBehaviors)
60 | {
61 | int index = itemBehaviors.IndexOf(behavior);
62 |
63 | if (index >= 0)
64 | {
65 | itemBehaviors.RemoveAt(index);
66 | }
67 | }
68 | }
69 |
70 | if (newBehaviors != null)
71 | {
72 | foreach (var behavior in newBehaviors)
73 | {
74 | int index = itemBehaviors.IndexOf(behavior);
75 |
76 | if (index < 0)
77 | {
78 | if (behavior is ICloneableBehavior)
79 | {
80 | itemBehaviors.Add((Behavior) ((ICloneableBehavior) behavior).CloneBehavior());
81 | }
82 | else
83 | {
84 | throw new NotImplementedException("Behavior does not implement ICloneableBehavior");
85 | }
86 | }
87 | }
88 | }
89 | }
90 | #endregion
91 | }
92 | }
93 |
--------------------------------------------------------------------------------
/DotNetProjects.WPF.Converters/DotNetProjects.WPF.Converters/BitmapConversion.cs:
--------------------------------------------------------------------------------
1 | using System.Drawing;
2 | using System.Drawing.Imaging;
3 | using System.IO;
4 | using System.Windows.Media.Imaging;
5 |
6 | namespace DotNetProjects.WPF.Converters
7 | {
8 | static class BitmapConversion
9 | {
10 | public static Bitmap ToWinFormsBitmap(this BitmapSource bitmapsource)
11 | {
12 | using (MemoryStream stream = new MemoryStream())
13 | {
14 | BitmapEncoder enc = new BmpBitmapEncoder();
15 | enc.Frames.Add(BitmapFrame.Create(bitmapsource));
16 | enc.Save(stream);
17 |
18 | using (var tempBitmap = new Bitmap(stream))
19 | {
20 |
21 | return new Bitmap(tempBitmap);
22 | }
23 | }
24 | }
25 |
26 | public static BitmapSource ToWpfBitmap(this Image bitmap)
27 | {
28 | using (MemoryStream stream = new MemoryStream())
29 | {
30 | bitmap.Save(stream, ImageFormat.Png);
31 |
32 | stream.Position = 0;
33 | BitmapImage result = new BitmapImage();
34 | result.BeginInit();
35 |
36 | result.CacheOption = BitmapCacheOption.OnLoad;
37 | result.StreamSource = stream;
38 | result.EndInit();
39 | result.Freeze();
40 | return result;
41 | }
42 | }
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/DotNetProjects.WPF.Converters/DotNetProjects.WPF.Converters/Converters/AlternationEqualityConverter.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Globalization;
3 | using System.Windows;
4 | using System.Windows.Data;
5 |
6 | namespace DotNetProjects.WPF.Converters.Converters
7 | {
8 | public class MultiBoolToVisibilityConverter : IMultiValueConverter
9 | {
10 | public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
11 | {
12 | foreach (var value in values)
13 | {
14 | if (!(bool)value) return Visibility.Hidden;
15 | }
16 | return Visibility.Visible;
17 | }
18 |
19 | public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
20 | {
21 | throw new NotSupportedException();
22 | }
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/DotNetProjects.WPF.Converters/DotNetProjects.WPF.Converters/Converters/BoolToValueConverter.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Windows;
3 | using System.Windows.Media;
4 |
5 | namespace DotNetProjects.WPF.Converters.Converters
6 | {
7 | public class BoolToValueConverter : ValueConverter
8 | {
9 | public T FalseValue { get; set; }
10 | public T TrueValue { get; set; }
11 |
12 | public override object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
13 | {
14 | if (value == null)
15 | return this.FalseValue;
16 | else
17 | return (bool)value ? this.TrueValue : this.FalseValue;
18 | }
19 |
20 | public override object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
21 | {
22 | return value != null ? value.Equals(this.TrueValue) : false;
23 | }
24 | }
25 |
26 | public class BoolToStringConverter : BoolToValueConverter { }
27 |
28 | public class BoolToBoolConverter : BoolToValueConverter
29 | {
30 | private static readonly Lazy _instance = new Lazy(() => new BoolToBoolConverter());
31 | public static ValueConverter Instance { get { return _instance.Value; } }
32 |
33 | public BoolToBoolConverter()
34 | {
35 | TrueValue = false;
36 | FalseValue = true;
37 | }
38 | }
39 |
40 | public class EqualsToBoolConverter : BoolToValueConverter
41 | {
42 | public string CompareValue { get; set; }
43 |
44 | public override object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
45 | {
46 | if (value == null)
47 | return this.FalseValue;
48 | else if (CompareValue != null)
49 | return value.ToString() == CompareValue ? this.TrueValue : this.FalseValue;
50 | return System.Convert.ToBoolean(value) ? this.TrueValue : this.FalseValue;
51 | }
52 | }
53 |
54 | public class EqualsToVisibilityConverter : BoolToValueConverter
55 | {
56 | public string CompareValue { get; set; }
57 |
58 | public override object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
59 | {
60 | if (value == null)
61 | return this.FalseValue;
62 | else if (CompareValue != null)
63 | return value.ToString() == CompareValue ? this.TrueValue : this.FalseValue;
64 | return System.Convert.ToBoolean(value) ? this.TrueValue : this.FalseValue;
65 | }
66 | }
67 |
68 | public class EqualsToBrushConverter : BoolToValueConverter
69 | {
70 | public string CompareValue { get; set; }
71 |
72 | public override object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
73 | {
74 | if (value == null)
75 | return this.FalseValue;
76 | else if (CompareValue != null)
77 | return String.Equals(value.ToString(), CompareValue, StringComparison.CurrentCultureIgnoreCase) ? this.TrueValue : this.FalseValue;
78 | return System.Convert.ToBoolean(value) ? this.TrueValue : this.FalseValue;
79 | }
80 | }
81 |
82 | public class BoolToBrushConverter : BoolToValueConverter { }
83 |
84 | public class BoolToColorConverter : BoolToValueConverter { }
85 |
86 | public class BoolToVisibilityConverter : BoolToValueConverter
87 | {
88 | private static readonly Lazy _trueIsVisibleConverter = new Lazy(() => new BoolToVisibilityConverter() {TrueValue = Visibility.Visible, FalseValue = Visibility.Collapsed});
89 | public static ValueConverter TrueIsVisibleConverter { get { return _trueIsVisibleConverter.Value; } }
90 | }
91 | public class BoolToObjectConverter : BoolToValueConverter