tags:

views:

625

answers:

1

I am working on a Custom MarkupExtension within a WPF application. Every documented example I have seen uses string parameters from XAML to construct the new object. Is it possible to use a non-string parameter?

In other words, how can I do something like this?

[MarkupExtensionReturnType(typeof(Uri))]
public class RefPackUriExtension : MarkupExtension
{
    object _assembly = null;

        public RefPackUriExtension() { }
        public RefPackUriExtension(object assembly)
        {
          this._assembly = assembly;
        }

        public override object ProvideValue(IServiceProvider serviceProvider)
        {
          //return an object by using the "_assembly" member somehow
        }
}
A: 

Any parameters to your MarkupExtension are subject to the same parsing behavior as properties on CLR objects. You can use a TypeConverter to allow the user to provide a string that is converted to the target type, or you can use another MarkupExtension.

As an example of the former, see the ColorConverter class. As an example of the latter, see the RelativeSource class (which is used within the Binding MarkupExtension).

HTH, Kent

Kent Boogaart
Are you sure this works? Before I posted the question I tried using the Binding MarkupExtension and received a compile-time error.
YeahStu
What would be helpful is an example of the XAML used in such cases
YeahStu