Skip to content

Commit

Permalink
Changes from review
Browse files Browse the repository at this point in the history
  • Loading branch information
punker76 committed May 1, 2021
1 parent f3652ba commit 8c2ccf3
Show file tree
Hide file tree
Showing 13 changed files with 458 additions and 575 deletions.
Original file line number Diff line number Diff line change
@@ -1,34 +1,28 @@
<!--
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.
-->

<UserControl x:Class="MetroDemo.ExampleViews.MultiSelectionComboBoxExample"
<UserControl x:Class="MetroDemo.ExampleViews.MultiSelectionComboBoxExample"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:MetroDemo"
xmlns:local1="clr-namespace:MetroDemo.ExampleViews"
xmlns:mah="http://metro.mahapps.com/winfx/xaml/controls"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:system="clr-namespace:System;assembly=mscorlib"
d:DataContext="{d:DesignInstance local:MainWindowViewModel}"
d:DesignHeight="450"
d:DesignWidth="800"
mc:Ignorable="d">

<UserControl.Resources>
<Style BasedOn="{StaticResource MahApps.Styles.MetroHeader.Horizontal}" TargetType="mah:MetroHeader" />
<Style BasedOn="{StaticResource MahApps.Styles.GroupBox}" TargetType="GroupBox">
<Setter Property="Margin" Value="5,5,5,0" />
<Setter Property="Margin" Value="5 5 5 0" />
</Style>

<!-- Selection Order -->
<ObjectDataProvider x:Key="Demo.Enums.OrderSelectedItemsBy"
<ObjectDataProvider x:Key="Demo.Enums.SelectedItemsOrderType"
MethodName="GetValues"
ObjectType="{x:Type system:Enum}">
ObjectType="{x:Type mah:SelectedItemsOrderType}">
<ObjectDataProvider.MethodParameters>
<x:Type TypeName="mah:OrderSelectedItemsBy" />
<x:Type TypeName="mah:SelectedItemsOrderType" />
</ObjectDataProvider.MethodParameters>
</ObjectDataProvider>

Expand Down Expand Up @@ -146,7 +140,7 @@
<ComboBox ItemsSource="{Binding Source={StaticResource Demo.Enums.SelectionMode}}" SelectedItem="{Binding ElementName=mscb_Example, Path=SelectionMode}" />
</mah:MetroHeader>
<mah:MetroHeader Header="OrderSelectedItemsBy">
<ComboBox ItemsSource="{Binding Source={StaticResource Demo.Enums.OrderSelectedItemsBy}}" SelectedItem="{Binding ElementName=mscb_Example, Path=OrderSelectedItemsBy}" />
<ComboBox ItemsSource="{Binding Source={StaticResource Demo.Enums.SelectedItemsOrderType}}" SelectedItem="{Binding ElementName=mscb_Example, Path=OrderSelectedItemsBy}" />
</mah:MetroHeader>
<mah:MetroHeader Header="ObjectToStringComparer">
<ComboBox SelectedValue="{Binding ElementName=mscb_Example, Path=ObjectToStringComparer}" SelectedValuePath="Tag">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,19 +239,8 @@ public void Dispose()

public int SelectedIndex { get; set; }


public ICollection<Album> Albums { get; set; }


private Album _MultiSelectionComboBoxSelectedAlbum;
[Display(Prompt = "Select an Album")]
public Album MultiSelectionComboBoxSelectedAlbum
{
get { return _MultiSelectionComboBoxSelectedAlbum; }
set { _MultiSelectionComboBoxSelectedAlbum = value; OnPropertyChanged(nameof(MultiSelectionComboBoxSelectedAlbum)); }
}


public List<Artist> Artists { get; set; }

private ObservableCollection<Artist> _selectedArtists = new ObservableCollection<Artist>();
Expand Down Expand Up @@ -682,8 +671,14 @@ private void ToggleIconScaling(object obj)
"Zebra"
};

[Display(Prompt = "Select your favoite animal(s)")]
public string MyFavoriteAnimal { get; set; }
private object myFavoriteAnimal;

[Display(Prompt = "Select your favorite animal(s)")]
public object MyFavoriteAnimal
{
get => this.myFavoriteAnimal;
set => this.Set(ref this.myFavoriteAnimal, value);
}

public ObjectParser MyObjectParser {get;}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Globalization;
using System.Linq;
using MetroDemo.Core;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,7 @@

using MahApps.Metro.Controls;
using MahApps.Metro.Controls.Dialogs;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace MetroDemo.Models
{
Expand Down Expand Up @@ -39,7 +33,7 @@ public object CreateObjectFromString(string input, CultureInfo culture, string s
DefaultButtonFocus = MessageDialogResult.Affirmative
};

if (_dialogCoordinator.ShowModalMessageExternal(_mainWindowViewModel, "Add Animal", $"Do you want to add \"{input}\" to the animals list?", MessageDialogStyle.AffirmativeAndNegative, dialogSettings) == 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)
{
return input.Trim();
}
Expand Down
56 changes: 28 additions & 28 deletions src/MahApps.Metro/Controls/Helper/BindingHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,20 @@ public static class BindingHelper
/// <summary>
/// A dummy property to initialize the binding to evaluate
/// </summary>
private static readonly DependencyProperty DummyProperty = DependencyProperty.RegisterAttached(
"Dummy",
typeof(object),
typeof(BindingHelper),
new UIPropertyMetadata(null));
private static readonly DependencyProperty DummyProperty
= DependencyProperty.RegisterAttached("Dummy",
typeof(object),
typeof(BindingHelper),
new UIPropertyMetadata(null));

/// <summary>
/// A dummy property to initialize the binding to evaluate. This property supports also string format.
/// </summary>
private static readonly DependencyProperty DummyTextProperty = DependencyProperty.RegisterAttached(
"DummyText",
typeof(string),
typeof(BindingHelper),
new UIPropertyMetadata(null));
private static readonly DependencyProperty DummyTextProperty
= DependencyProperty.RegisterAttached("DummyText",
typeof(string),
typeof(BindingHelper),
new UIPropertyMetadata(null));

/// <summary>
/// Evaluates a defined <see cref="Binding"/>-path on the given object
Expand All @@ -48,7 +48,7 @@ public static object Eval(object source, string expression)
/// </summary>
/// <param name="source">the object to evaluate</param>
/// <param name="expression">the binding expression to evaluate</param>
/// <param name="format">the stringformat to use</param>
/// <param name="format">the string format to use</param>
/// <returns>the result of the <see cref="Binding"/></returns>
public static object Eval(object source, string expression, string format)
{
Expand All @@ -70,29 +70,29 @@ public static object Eval(Binding binding, object source)
}

Binding newBinding = new Binding
{
Source = source,
AsyncState = binding.AsyncState,
BindingGroupName = binding.BindingGroupName,
BindsDirectlyToSource = binding.BindsDirectlyToSource,
Path = binding.Path,
Converter = binding.Converter,
ConverterCulture = binding.ConverterCulture,
ConverterParameter = binding.ConverterParameter,
FallbackValue = binding.FallbackValue,
IsAsync = binding.IsAsync,
Mode = BindingMode.OneWay,
StringFormat = binding.StringFormat,
TargetNullValue = binding.TargetNullValue
};
{
Source = source,
AsyncState = binding.AsyncState,
BindingGroupName = binding.BindingGroupName,
BindsDirectlyToSource = binding.BindsDirectlyToSource,
Path = binding.Path,
Converter = binding.Converter,
ConverterCulture = binding.ConverterCulture,
ConverterParameter = binding.ConverterParameter,
FallbackValue = binding.FallbackValue,
IsAsync = binding.IsAsync,
Mode = BindingMode.OneWay,
StringFormat = binding.StringFormat,
TargetNullValue = binding.TargetNullValue
};
return Eval(newBinding);
}

/// <summary>
/// Evaluates a defined <see cref="Binding"/> on the given <see cref="DependencyObject"/>
/// </summary>
/// <param name="binding">The <see cref="Binding"/> to evaluate</param>
/// <param name="dependencyObject">optional: The <see cref="DependencyObject"/> to evalutate</param>
/// <param name="dependencyObject">optional: The <see cref="DependencyObject"/> to evaluate</param>
/// <returns>The resulting object</returns>
public static object Eval(Binding binding, DependencyObject dependencyObject)
{
Expand Down Expand Up @@ -120,4 +120,4 @@ public static object Eval(Binding binding)
return Eval(binding, null);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,14 @@ public interface ICompareObjectToString
/// <param name="input">The string to compare</param>
/// <param name="objectToCompare">The object to compare</param>
/// <param name="stringComparison">The <see cref="StringComparison"/> used to check if the string matches</param>
/// <param name="stringFormat">The string format to applay</param>
/// <returns>true if the string represents the object, otherwise fase.</returns>
/// <param name="stringFormat">The string format to apply</param>
/// <returns>true if the string represents the object, otherwise false.</returns>
public bool CheckIfStringMatchesObject(string input, object objectToCompare, StringComparison stringComparison, string stringFormat);
}


[MarkupExtensionReturnType(typeof(DefaultObjectToStringComparer))]
public class DefaultObjectToStringComparer : MarkupExtension, ICompareObjectToString
{
private static DefaultObjectToStringComparer _Instance;

/// <inheritdoc/>
public bool CheckIfStringMatchesObject(string input, object objectToCompare, StringComparison stringComparison, string stringFormat)
{
Expand Down Expand Up @@ -63,7 +60,7 @@ public bool CheckIfStringMatchesObject(string input, object objectToCompare, Str
/// <inheritdoc/>
public override object ProvideValue(IServiceProvider serviceProvider)
{
return _Instance ??= new DefaultObjectToStringComparer();
return this;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ public interface IParseStringToObject
/// </summary>
/// <param name="input">The input string to parse</param>
/// <param name="culture">The culture which should be used to parse</param>
/// <param name="stringFormat">The string format to applay</param>
/// <param name="stringFormat">The string format to apply</param>
/// <returns>The object if successful, otherwise null</returns>
object CreateObjectFromString(string input, CultureInfo culture, string stringFormat);
}
}
}
Loading

0 comments on commit 8c2ccf3

Please sign in to comment.