This project is read-only.

Common.Route improvement.

Dec 19, 2012 at 12:56 PM

Actually, "Common.RoutePropertyChanged" returns if "GetIsInDesignMode" is true. Can it check if a property exists o not?

 

Dec 24, 2012 at 9:53 AM

 

Hi angabanga!

 

The best thing will be that this will be statically checked by the xaml compiler but of course we can not do that.

 

I suppose that this could be done for some cases but not in general (routes over routes, delayed routes, datatemplates).

 

If you come up with a working implementation we'll be glad to include it. We don't use the designer too much. it's getting better?

 

Thanks for the idea!

Jan 15, 2013 at 2:04 AM

hi Olmo

here are my attempts to solve the question:

First, I wish the DesignTime controls the "Common.TypeContext" property. Looking deep into the "PropertyRouteConverter" class, it seems that the "ConvertFrom" does no work in design time. So so I bypassed by creating my own "Attached" property of type "Type":

public static readonly DependencyProperty ContextTypeProperty =
	DependencyProperty.RegisterAttached("ContextType", typeof (Type), typeof (Common),
	new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.Inherits,
	new PropertyChangedCallback(ContextTypePropertyChanged)));

 

and with the new "ContextTypePropertyChanged", I keep the TypeContextProperty in sync:

public static void ContextTypePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
	if (e.NewValue != null) SetTypeContext(d, PropertyRoute.Root((Type) e.NewValue));
}


By this time, I get an error in XAML, if I digit an invalid class name.

 

Now it's time to work with RouteProperty. I changed the method:

 

public static void RoutePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
.
.
.
if (DesignerProperties.GetIsInDesignMode(fe))
{
	DependencyProperty labelText =
	.
	.
	.

	PropertyRoute parentType = GetTypeContext(fe);

	if ((parentType != null) && (parentType.RootType.GetProperty((string) e.NewValue))== null)
		throw new InvalidOperationException(
			"ContextType does not contains Route attached property : '{0}'".Formato(e.NewValue));

	return;
}


It seemed that  all was ok,


but the designer does not allow me to know the value of an inherited attached property, so I got my partial success by putting everything on the same line:

 

<m:ValueLine m:Common.ContextType="d:PersonDN" m:Common.Route="Name" />


Jan 18, 2013 at 12:03 PM
Edited Jan 18, 2013 at 12:04 PM

Hi angabanga!

I really liked the Common.ContextType idea! Initially TypeContext was of type Type, and there was better tooling and compile time checking. 

When we evolved it to be of type PropertyRoute, I tried to create a Type -> PropertyRoute converter but it didn't work, so I made a string -> PropertyRoute converter. 

With your idea in mind, I think I will make three attached properties:

Type TypeContext. (temporal)
string Route. (temporal)
PropertyRoute PropertyRoute. (the only real one)

Many code will have to change but can be solved with a regex, and then we'll have compile time checking back again :). 

About the Route part, it's more complicated, we don't use the Designer very much and I don't think is worth having to write another property (ContextType) just for it. It also won't work with embeddeds. 

Tell me if you find a a way to get the inherited attached property. 

Thanks a lot!