Using a Generic IValueConverter from XAML

前端 未结 1 1506
滥情空心
滥情空心 2021-02-06 05:26

I have a generic class implementing IValueConverter. Something like:

class MyValueConverter : IValueConverter

With XAML 2

相关标签:
1条回答
  • 2021-02-06 05:50

    You could probably do this with a custom MarkupExtension(archive)(v4). Something like:

    public class MyMarkupExtension : MarkupExtension {
    
        public MyMarkupExtension() {
            this.Type = /* some default type */;
        }
    
        public MyMarkupExtension(Type type) {
            this.Type = type;
        }
    
        public Type Type { get; private set; }
    
        public override object ProvideValue(IServiceProvider serviceProvider) {
            Type type = typeof(MyValueConverter<>).MakeGenericType(this.Type);
            return Activator.CreateInstance(type);
        }
    }
    

    Then you'd use it like {Binding ... Converter={local:MyMarkup {x:Type BounceEase}}}

    0 讨论(0)
提交回复
热议问题