Blastobi

Hi,
I'm working on a very specific aspect of DSL with WPF. Indeed, I get back Visual Studio XML files generated at model time (myfile.myExt and myfile.myExt.diagram) to load them in my own repository.
I haven't problem to load them and manipulate them. But I have some difficulties to bind object properties with my WPF graphic controls. I have a "Property" concept which has 3 properties : "Name", "Type" and "Value". I would like to display the Value property and update display automatically when value is modified.
To use Dependency property of WPF controls, I implement INotifyPropertyChanged on my Property concept.

Code Snippet

partial class Property : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
public void NotifyPropertyChanged(PropertyChangedEventArgs args)
{
if(PropertyChanged != null)
PropertyChanged(this, args);
}
}


As I can't modify the setter of Value property, I create a ChangedRule to notify the observers when a modification begins.
Code Snippet

[RuleOn(typeof(Property))]
public sealed class ValueOfPropertyRule : ChangeRule
{
public override void ElementPropertyChanged(ElementPropertyChangedEventArgs e)
{
Property property = e.ModelElement as Property;
if (e.DomainProperty.Id == Property.ValueDomainPropertyId)
{
property.NotifyPropertyChanged(new PropertyChangedEventArgs(property.Name));
}

}
}


I tested this code with a binding to a winform control and it received notifications without problem. But a WPF control is not modified by this same binding. :/
For now, I incorporate my business concept "Property" in a WPFProperty, which implements INotifyPropertyChanged interface too. I'm binding my wpf control to it and it works! But if someone knows why it doesn't work directly, I listen him! (Maybe cause of Transaction )


Re: Visual Studio Extensibility property notification and WPF

SteveCook

I suggest you look at the thread http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=202700&SiteID=1 that discusses responding to property change events. Although I don't know why your code doesn't work, in general it is incorrect to use rules to notify changes outside the model, because undo behaviour will be incorrect.

-- Steve





Re: Visual Studio Extensibility property notification and WPF

Blastobi

Thanks.
I have already read this thread but I don't succeed to develop a notification working with WPF controls.
I'm looking for a solution... If I find (and I will find ^^), I will acquaint you about my solution.

Best regards

Heinzer David




Re: Visual Studio Extensibility property notification and WPF

GarethJ - MSFT

I'm afraid we dont have WPF expertise on the DSL team right now, so you might find more help on the WPF forum.

As Steve says, rules are not appropriate here.

You could either use events, or more likely override the Set method in the property handler nested class that is generated.