What does “{x:Static}” mean in XAML?

后端 未结 3 2243
后悔当初
后悔当初 2020-11-30 06:16

What does {x:Static} mean in XAML?

Code sample:


3条回答
  •  被撕碎了的回忆
    2020-11-30 06:53

    It is a way to insert any static value into XAML. For example, if I have a class:

    namespace A 
    { 
        public class MyConstants 
        {
            public static readonly string SomeConstantString = "BAM!";
        }
    }
    

    I can place it into a WPF UI using XAML like this:

    
    

    Notice, you will have to import the namespace in which MyConstants is defined into your XAML. So in the or element do something like:

    xmlns:A="clr-namespace:A"
    

提交回复
热议问题