-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4006 from timunie/feature/MultiSelectionComboBox
Implement a MultiSelectionComboBox
- Loading branch information
Showing
30 changed files
with
4,401 additions
and
7 deletions.
There are no files selected for viewing
305 changes: 305 additions & 0 deletions
305
src/MahApps.Metro.Samples/MahApps.Metro.Demo/ExampleViews/MultiSelectionComboBoxExample.xaml
Large diffs are not rendered by default.
Oops, something went wrong.
52 changes: 52 additions & 0 deletions
52
...hApps.Metro.Samples/MahApps.Metro.Demo/ExampleViews/MultiSelectionComboBoxExample.xaml.cs
This file contains 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,52 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using MahApps.Metro.Controls; | ||
using MahApps.Metro.Controls.Dialogs; | ||
using System.Diagnostics; | ||
using System.Windows.Controls; | ||
|
||
namespace MetroDemo.ExampleViews | ||
{ | ||
/// <summary> | ||
/// Interaction logic for MultiSelectionComboBoxExample.xaml | ||
/// </summary> | ||
public partial class MultiSelectionComboBoxExample : UserControl | ||
{ | ||
public MultiSelectionComboBoxExample() | ||
{ | ||
this.InitializeComponent(); | ||
} | ||
|
||
private void Mscb_Example_AddingItem(object? sender, AddingItemEventArgs args) | ||
{ | ||
// We don't want to get double entries so let`s check if we already have one. | ||
args.Accepted = args.TargetList is not null && !args.TargetList.Contains(args.ParsedObject); | ||
} | ||
|
||
private async void Mscb_Example_AddedItem(object? sender, AddedItemEventArgs args) | ||
{ | ||
var window = this.TryFindParent<MetroWindow>(); | ||
if (window is null) | ||
{ | ||
return; | ||
} | ||
|
||
await window.ShowMessageAsync("Added Item", $"Successfully added \"{args.AddedItem}\" to your Items-Collection"); | ||
} | ||
|
||
private void mscb_Example_SelectionChanged(object sender, SelectionChangedEventArgs e) | ||
{ | ||
foreach (var item in e.AddedItems) | ||
{ | ||
Debug.WriteLine($"MultiSelectionComboBox-Example: Selected item \"{item}\""); | ||
} | ||
|
||
foreach (var item in e.RemovedItems) | ||
{ | ||
Debug.WriteLine($"MultiSelectionComboBox-Example: Unselected item \"{item}\""); | ||
} | ||
} | ||
} | ||
} |
This file contains 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 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 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 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 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
55 changes: 55 additions & 0 deletions
55
src/MahApps.Metro.Samples/MahApps.Metro.Demo/Models/ObjectParser.cs
This file contains 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,55 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using MahApps.Metro.Controls; | ||
using MahApps.Metro.Controls.Dialogs; | ||
using System; | ||
using System.Globalization; | ||
|
||
namespace MetroDemo.Models | ||
{ | ||
public class ObjectParser : IParseStringToObject | ||
{ | ||
private readonly MainWindowViewModel _mainWindowViewModel; | ||
private readonly IDialogCoordinator _dialogCoordinator; | ||
|
||
public ObjectParser(MainWindowViewModel mainWindowViewModel, IDialogCoordinator dialogCoordinator) | ||
{ | ||
this._mainWindowViewModel = mainWindowViewModel; | ||
this._dialogCoordinator = dialogCoordinator; | ||
} | ||
|
||
/// <inheritdoc /> | ||
public bool TryCreateObjectFromString(string? input, | ||
out object? result, | ||
CultureInfo? culture = null, | ||
string? stringFormat = null, | ||
Type? elementType = null) | ||
{ | ||
if (string.IsNullOrWhiteSpace(input)) | ||
{ | ||
result = null; | ||
return false; | ||
} | ||
|
||
MetroDialogSettings dialogSettings = new MetroDialogSettings | ||
{ | ||
AffirmativeButtonText = "Yes", | ||
NegativeButtonText = "No", | ||
DefaultButtonFocus = MessageDialogResult.Affirmative | ||
}; | ||
|
||
if (this._dialogCoordinator.ShowModalMessageExternal(this._mainWindowViewModel, "Add Animal", $"Do you want to add \"{input}\" to the animals list?", MessageDialogStyle.AffirmativeAndNegative, dialogSettings) == MessageDialogResult.Affirmative) | ||
{ | ||
result = input!.Trim(); | ||
return true; | ||
} | ||
else | ||
{ | ||
result = null; | ||
return false; | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.