Generic Behavior

帅比萌擦擦* 提交于 2019-12-22 17:53:36

问题


I would like create generic behavior. My problem is generic declaration in XAML.

    public class GenericBehavior<T> : Behavior<DataGrid>
        where T : class 
    {
    }

I can’t use x:TypeArguments because I don’t have loose XAML file.

In WPF and when targeting .NET Framework 4, you can use XAML 2009 features together with x:TypeArguments but only for loose XAML (XAML that is not markup-compiled). Markup-compiled XAML for WPF and the BAML form of XAML do not currently support the XAML 2009 keywords and features

I found some workaround with MarkupExtension but with Behaviors not work.

In my current solution I attach behavior in code.

Any idea?

来源:https://stackoverflow.com/questions/23313622/generic-behavior

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!