-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Refactor PasswordBoxAssist.Password to use behaviors (issue 2930) #2932
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
e9388bf
Rewrite current UI test and add new UI test to test failing scenario
nicolaihenriksen 4d9c233
Refactor PasswordBoxAssist to use behavior
nicolaihenriksen 90471ba
Refactor PasswordBox reveal style TextBox focus- and text selection code
nicolaihenriksen 0a9f4f8
Undo wrong change in TestBase
nicolaihenriksen bc349fa
Whitespace commit to force re-run
nicolaihenriksen bd746b4
Increase delay in test
nicolaihenriksen b282e6c
Rollback of increased test delay
nicolaihenriksen dda88f8
Update MaterialDesignThemes.Wpf/Behaviors/PasswordBoxRevealTextBoxBeh…
nicolaihenriksen 7d32386
Update MaterialDesignThemes.Wpf/Behaviors/PasswordBoxRevealTextBoxBeh…
nicolaihenriksen e1ddcf8
Extract PasswordBoxBehavior into its own class
nicolaihenriksen 847d6ab
Cache PropertyInfos and MethodInfos in PasswordBoxRevealTextBoxBehavior
nicolaihenriksen 417c69c
Selecting minimum required version of dependency and updating nuspec
nicolaihenriksen 4b78de6
Convert Password binding to opt-in feature
nicolaihenriksen 3fdb918
File scoped namespace
nicolaihenriksen e89ce21
Behavior classes renames and change from internal to public
nicolaihenriksen 21d7373
Use latest version of Xaml.Behaviors and update nuspec file
nicolaihenriksen da46c37
Attempting fix of pipeline
Keboo 8124883
Adding screenshots for debugging
Keboo fac1639
Attempt at fixing failing UI test
nicolaihenriksen b52a9ce
Adding more screenshots for debugging
nicolaihenriksen 100bad6
Activate test window on loaded event
nicolaihenriksen bfbd3d5
Yet another attempt at getting test window shown
nicolaihenriksen afbc730
Removing debugging screenshots
nicolaihenriksen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Refactor PasswordBoxAssist to use behavior
- Loading branch information
commit 4d9c23389bd16582276a68b65b4d2629e7107d57
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| using Microsoft.Xaml.Behaviors; | ||
nicolaihenriksen marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| namespace MaterialDesignThemes.Wpf; | ||
|
|
||
| public class StylizedBehaviorCollection : FreezableCollection<Behavior> | ||
nicolaihenriksen marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| { | ||
| protected override Freezable CreateInstanceCore() => new StylizedBehaviorCollection(); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,122 @@ | ||
| using Microsoft.Xaml.Behaviors; | ||
nicolaihenriksen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| namespace MaterialDesignThemes.Wpf; | ||
|
|
||
| internal class StylizedBehaviors | ||
nicolaihenriksen marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| { | ||
| private static readonly DependencyProperty OriginalBehaviorProperty = DependencyProperty.RegisterAttached( | ||
| "OriginalBehavior", typeof(Behavior), typeof(StylizedBehaviors), new UIPropertyMetadata(null)); | ||
| private static void SetOriginalBehavior(DependencyObject obj, Behavior? value) => obj.SetValue(OriginalBehaviorProperty, value); | ||
| private static Behavior? GetOriginalBehavior(DependencyObject obj) => (Behavior?)obj.GetValue(OriginalBehaviorProperty); | ||
|
|
||
| internal static readonly DependencyProperty BehaviorsProperty = DependencyProperty.RegisterAttached( | ||
| "Behaviors", typeof(StylizedBehaviorCollection), typeof(StylizedBehaviors), new FrameworkPropertyMetadata(null, OnPropertyChanged)); | ||
| internal static void SetBehaviors(DependencyObject uie, StylizedBehaviorCollection? value) => uie.SetValue(BehaviorsProperty, value); | ||
| internal static StylizedBehaviorCollection? GetBehaviors(DependencyObject uie) => (StylizedBehaviorCollection?)uie.GetValue(BehaviorsProperty); | ||
|
|
||
| private static void OnPropertyChanged(DependencyObject dpo, DependencyPropertyChangedEventArgs e) | ||
| { | ||
| if (dpo is not FrameworkElement frameworkElement) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| var newBehaviors = e.NewValue as StylizedBehaviorCollection; | ||
| var oldBehaviors = e.OldValue as StylizedBehaviorCollection; | ||
| if (newBehaviors == oldBehaviors) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| var itemBehaviors = Interaction.GetBehaviors(frameworkElement); | ||
| frameworkElement.Unloaded -= FrameworkElementUnloaded; | ||
| if (oldBehaviors != null) | ||
| { | ||
| foreach (var behavior in oldBehaviors) | ||
| { | ||
| int index = GetIndexOf(itemBehaviors, behavior); | ||
| if (index >= 0) | ||
| { | ||
| itemBehaviors.RemoveAt(index); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| if (newBehaviors != null) | ||
| { | ||
| foreach (var behavior in newBehaviors) | ||
| { | ||
| int index = GetIndexOf(itemBehaviors, behavior); | ||
| if (index < 0) | ||
| { | ||
| var clone = (Behavior)behavior.Clone(); | ||
| SetOriginalBehavior(clone, behavior); | ||
| itemBehaviors.Add(clone); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| if (itemBehaviors.Count > 0) | ||
| { | ||
| frameworkElement.Unloaded += FrameworkElementUnloaded; | ||
| } | ||
| } | ||
|
|
||
| private static void FrameworkElementUnloaded(object sender, RoutedEventArgs e) | ||
| { | ||
| // BehaviorCollection doesn't call Detach, so we do this | ||
| if (sender is not FrameworkElement frameworkElement) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| var itemBehaviors = Interaction.GetBehaviors(frameworkElement); | ||
| foreach (var behavior in itemBehaviors) | ||
| { | ||
| behavior.Detach(); | ||
| } | ||
|
|
||
| frameworkElement.Loaded += FrameworkElementLoaded; | ||
| } | ||
|
|
||
| private static void FrameworkElementLoaded(object sender, RoutedEventArgs e) | ||
| { | ||
| if (sender is not FrameworkElement frameworkElement) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| frameworkElement.Loaded -= FrameworkElementLoaded; | ||
| var itemBehaviors = Interaction.GetBehaviors(frameworkElement); | ||
| foreach (var behavior in itemBehaviors) | ||
| { | ||
| behavior.Attach(frameworkElement); | ||
| } | ||
| } | ||
|
|
||
| private static int GetIndexOf(BehaviorCollection itemBehaviors, Behavior behavior) | ||
| { | ||
| int index = -1; | ||
|
|
||
| var originalBehavior = GetOriginalBehavior(behavior); | ||
|
|
||
| for (int i = 0; i < itemBehaviors.Count; i++) | ||
| { | ||
| var currentBehavior = itemBehaviors[i]; | ||
| if (currentBehavior == behavior || currentBehavior == originalBehavior) | ||
| { | ||
| index = i; | ||
| break; | ||
| } | ||
|
|
||
| var currentOriginalBehavior = GetOriginalBehavior(currentBehavior); | ||
| if (currentOriginalBehavior == behavior || currentOriginalBehavior == originalBehavior) | ||
| { | ||
| index = i; | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| return index; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.