Constants in xaml

后端 未结 2 2102
情深已故
情深已故 2021-02-18 19:03

Let\'s say I have a class defined something like the below:

namespace MyProject.MyConstants
{
    public class Constants
    {
        public class Group1Constan         


        
相关标签:
2条回答
  • 2021-02-18 19:22

    Try this one:

    <MenuItem Header="{x:Static constants:Constants+Group1Constants.DoIt}">
    

    I used "+" instead of "." to reference the nested class. Not sure if you'll run into problems doing this though.

    0 讨论(0)
  • 2021-02-18 19:28

    For textbox label text field constants in XAML I use:

    Text="{x:Static local:[myConstantNamesClass].[name of constant string in your constant class]}" 
    

    and then need to build the solution to make it accessible.

    (Note that the local: XAML namespace would be set to reference the CLR namespace of the Constants class at the very top of the XAML file.)

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