Skip to content
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

HamburgerMenu with own ViewModel collection produces System.Windows.Data Warning and Error #3859

Closed
punker76 opened this issue Jun 17, 2020 · 0 comments · Fixed by #3860
Closed
Assignees
Labels
Milestone

Comments

@punker76
Copy link
Member

punker76 commented Jun 17, 2020

Describe the bug

Using a collection with own ViewModels different to HamburgerMenuItem and HamburgerMenuItemCollection produces following output warning and errors:

System.Windows.Data Warning: 40 : BindingExpression path error: 'IsVisible' property not found on 'object' ''ServerSettingsViewModel' (HashCode=5659087)'. BindingExpression:Path=IsVisible; DataItem='ServerSettingsViewModel' (HashCode=5659087); target element is 'ListBoxItem' (Name=''); target property is 'Visibility' (type 'Visibility')
System.Windows.Data Error: 11 : Fallback value 'True' (type 'String') cannot be converted for use in 'Visibility' (type 'Visibility'). BindingExpression:Path=IsVisible; DataItem='ServerSettingsViewModel' (HashCode=5659087); target element is 'ListBoxItem' (Name=''); target property is 'Visibility' (type 'Visibility') FormatException:'System.FormatException: True is not a valid value for Visibility.
 ---> System.ArgumentException: Requested value 'True' was not found.
   at System.Enum.TryParseByName(RuntimeType enumType, String originalValueString, ReadOnlySpan`1 value, Boolean ignoreCase, Boolean throwOnFailure, UInt64& result)
   at System.Enum.TryParseUInt32Enum(RuntimeType enumType, String originalValueString, ReadOnlySpan`1 value, UInt32 maxInclusive, Boolean ignoreCase, Boolean throwOnFailure, TypeCode type, UInt32& result)
   at System.Enum.TryParse(Type enumType, String value, Boolean ignoreCase, Boolean throwOnFailure, Object& result)
   at System.Enum.Parse(Type enumType, String value, Boolean ignoreCase)
   at System.ComponentModel.EnumConverter.ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, Object value)
   --- End of inner exception stack trace ---
   at System.ComponentModel.EnumConverter.ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, Object value)
   at System.Windows.Data.BindingExpressionBase.ConvertValue(Object value, DependencyProperty dp, Exception& e)'

Steps to reproduce

  1. Create an ObservableCollection with ViewModels
  2. Create DataTemplate for ItemTemplate and OptionsItemTemplate to use own ViewModel
  3. Create DataTemplate for the ViewModels
  4. Bind HamburgerMenu ItemsSource to the collections

Now if the app starts, the above warnings and errors occurs.

Expected behavior

HamburgerMenu should also work with own collections and ViewModels like other ItemsControls.

Environment

MahApps.Metro version: v2.0.1
Windows build number: Win10 1909 [Version 10.0.18363.836]
Visual Studio: 2019 16.6.0
Target Framework: .Net Core 3.1 (v4.5.2, v4.7.2)
@punker76 punker76 added the Bug label Jun 17, 2020
@punker76 punker76 added this to the 2.1.0 milestone Jun 17, 2020
@punker76 punker76 self-assigned this Jun 17, 2020
punker76 added a commit that referenced this issue Jun 17, 2020
Introduce HamburgerMenuListBox class which handles the IsVisible (IHamburgerMenuItemBase) and IsEnabled (IHamburgerMenuItem) properties and bind them to the properties of the ListBoxItem.

This makes it easier to use own ViewModel collections which are mostly not implement these properties. But now it can be done with the interfaces.
punker76 added a commit that referenced this issue Jun 17, 2020
…ewModelCollection

(GH-3859) Allow own ViewModel collection for HamburgerMenu ItemsSource
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging a pull request may close this issue.

1 participant