tags:

views:

152

answers:

1

Is there a way to mark the entire DataGrid as one-way binding?

+1  A: 

You can create a new class such as OneWayExtension that inherits binding.

 public class OneWayExtension : Binding
{
    public OneWayExtension()
        : base()
    {
        Initialize();
    }

    public OneWayExtension(string path)
        : base(path)
    {
        Initialize();
    }

    private void Initialize()
    {
        this.Source = YourSourceOrMakeThisAParameter;
        this.Mode = BindingMode.OneWay;
    }
}

You can then call this by

{local:OneWay PathOfData}
Chris Ridenour
Interesting. It looks like I could do a lot of cool stuff using this.
Jonathan Allen
I find it a great way to set User and App Settings.One "issue" is XAML editor will complain it cannot find a constructor with one argument. This has been addressed by MS as Will Not Fix. You can "work around" it by moving the class to a separate project in the solution, which for Settings doesn't work but for your case it might. Or if you don't mind the warning (still compiles obviously), ignore it ;)
Chris Ridenour
That's the kind of patently obvious answer that I could worry over this problem for six months and never find.
Robert Rossney