A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/dotnet/csharplang/issues/1419 below:

Make the NotifyChanged event part of each object · Issue #1419 · dotnet/csharplang · GitHub

In my view, C#/WPF is the magic combo promoted by Microsoft. These are designed to work hand in hand and should support each-other optimally in a MVVM world. And I must say I'm pretty convinced by this association.
Now, whereas the learning in C# is a snap for an experienced programmer, I feel that learning WPF is quite a long way interrupted with road-blocks and paved with frustration. The main reason: The Binding can be done only on class properties that implement INotifyPropertyChanged interface. I think the experienced WPF developers are smiling now thinking: "Of course ! This is an easy one !"
But I think every newcomer in WPF has faced this problem, where he was trying to bind a non-observable property, or not even a property, or binding an ObservableCollection wishfully thinking that the changes on items on the collection would be detected... But also admit it, how much time did you spend to solve, implement or work-around this limitation or draw fancy dependency graphs to bind your properties correctly ?

This could have been avoided by having the change event implemented differently. Instead of having it patched over to the .NET library with the quick Implementation of the INotifyPropertyChanged interface, it could be handled by the compiler.

Think of an NotifyChanged event on the object base class, that would be handled directly by the C# Compiler... All the restriction to bind objects only if these are properties from an instance of object implementing an INotifyPropertyChanged would disappear, your Model could become your ViewModel, the binding would become simpler... and the performance would be way better: Less code size, faster response !

If this is too complicated for the compiler to figure out where the NotifyChanged should be added to the IL, we may consider to add a compiler attribute like [Observable]

Think of this as a new ViewModel:

[Observable]
public class Person
{
    [Observable]
    public string Name;
 
    [Observable]
    public Person[] Friends; 
}

That you can simply bind with:

<Border DataContext={Binding MainPersonInstance} >
    <TextBox Text={Binding} />
    <ItemsControl ItemsSource={Binding Friends}>
        <ItemsControl.ItemTemplate>
            <DataTemplate>
                <TextBox Text={Binding}/>
            </DataTemplate>
        </ItemsControl.ItemTemplate>
    /<ItemsControl>
</Border>

Wouldn't that make your day ?

svick, jnm2, Joe4evr, casperOne, yaakov-h and 8 moretpetrina, ufcpp and binki


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4