mvvmlight icon indicating copy to clipboard operation
mvvmlight copied to clipboard

Proposal: Include essential, but missing, WPF/XAML functionality

Open daiplusplus opened this issue 8 years ago • 1 comments

I have my own little WPF utility library that provides some essential functionality that isn't included in WPF-proper (or other XAML frameworks, I assume) or MvvmLight. I'll be happy to share my implementation if you like. I think if they were included in the MvvmLight.Extras then they'd benefit more people.

  • class BindingProxy : System.Windows.Freezable - pretty much from here: https://www.thomaslevesque.com/2011/03/21/wpf-how-to-bind-to-data-when-the-datacontext-is-not-inherited/
  • CultureAwareBinding - As described here: https://stackoverflow.com/questions/5831455/use-real-cultureinfo-currentculture-in-wpf-binding-not-cultureinfo-from-ietfl
  • A whole slew of IValueConverter for XAML-frustrations like:
    • BooleanToVisibilityConverter (that accepts an enum parameter to specify if false means Collapsed, Hidden or Visible and so on).
    • EnumToBooleanConverter
    • NullToVisibilityConverter
    • TextTransformConverter (parameterised by an enum specifying ToUppercase, ToLowercase, ToTitleCase

I also have plans to build a Markup-Extension or Binding Converter that allows for C#-like expressions to be used in bindings, to eliminate the need for most Converters or hacks in ViewModels. Already there's the MathConverter available here: https://rachel53461.wordpress.com/2011/08/20/the-math-converter/ - but that's restricted to numeric arithmetic - but my proposal would use something like DLR/Dynamic-Linq or the built-in C# expression parser so we could do something like this:

I'm also looking at possibly avoiding common converters in Binding expressions by using better-typed Attached Properties, e.g.:

<Label mvvm:Vis.Visible="{Binding SomeBooleanProperty}"  />`

...where Vis.Visible is a Boolean property that proxies UIElement.Visibility, instead of:

<Resources>
    <BooleanToVisibilityConverter x:Key="boolToVis" />
</Resources>

<Label Visibility="{Binding SomeBooleanProperty, Converter={StaticResource boolToVis}}" />

daiplusplus avatar Nov 03 '17 04:11 daiplusplus

Interesting propositions and thanks so much for sharing the ideas. I am quite conservative in adding new features but I took notes of these ideas.

lbugnion avatar Nov 25 '17 16:11 lbugnion