Boolean CommandParameter in XAML

后端 未结 6 1079
忘掉有多难
忘掉有多难 2020-12-05 09:35

I have this code (which works just right):


             


        
6条回答
  •  佛祖请我去吃肉
    2020-12-05 09:40

    I just found an even more generic solution with this markup extension:

    public class SystemTypeExtension : MarkupExtension
    {
        private object parameter;
    
        public int Int{set { parameter = value; }}
        public double Double { set { parameter = value; } }
        public float Float { set { parameter = value; } }
        public bool Bool { set { parameter = value; } }
        // add more as needed here
    
        public override object ProvideValue(IServiceProvider serviceProvider)
        {
            return parameter;
        }
    }
    

    Usage ("wpf:" is the namespace where the extension lives in):

    
    

    You even get the options True and False after typing Bool= and type safety!

提交回复
热议问题