Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Using SimpleFont as UserInput not saving in profiles?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Using SimpleFont as UserInput not saving in profiles?

    howdy.

    So I've created a simplefont object, as a variable, and turned it into a user input. It works fine, but for some reason, it won't save under a template. So when reopening a template, it reverts back to its default value.

    I am wondering if I am doing something wrong here.

    At the class level, I declare a variable like this:

    Code:
    private SimpleFont                         myTextFont                     = new NinjaTrader.Gui.Tools.SimpleFont("Impact", 20);

    In my onRender() block, I create a text format via:
    Code:
    SharpDX.DirectWrite.TextFormat textFormat = myTextFont.ToDirectWriteTextFormat();


    In my properties section, I capture that user input via:
    Code:
    [XmlIgnore]
    [Display(ResourceType = typeof(Custom.Resource), Name = "Text Type", Description = "", GroupName = "Parameters", Order = 0)]
    public SimpleFont MyTextFont
    {
    get {return myTextFont;}
    set {myTextFont = value;}
    }

    Is there something obvious I'm missing here? Is it due to me only manipulating this text layout in onRender(), that it just never gets stored anywhere? Does this somehow need to be initialized, or created in the state.configure block?

    #2
    Hello forrestang, thanks for your post.

    This SimpleFont public property works fine in my test script:

    Code:
    NinjaTrader.Gui.Tools.SimpleFont largeFont;
    
    [NinjaScriptProperty]
    [Display(Name="Large Font", Description="Font Size", Order=1, GroupName="Font")]
    public SimpleFont LargeFont
    {
        get{return largeFont;}
        set{largeFont = value;}
    }
    I attached my test script. Could you load this up and compare the differences between your custom script?

    Please let me know if I can assist any further.
    Attached Files
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_ChrisL View Post

      I attached my test script. Could you load this up and compare the differences between your custom script?

      Please let me know if I can assist any further.
      Thank you for the help. It looks like my issue was this bit of code...

      What I originally had was this:
      Code:
      [XmlIgnore]
      [Display(ResourceType = typeof(Custom.Resource), Name = "Text Type", Description = "", GroupName = "Parameters", Order = 0)]
      public SimpleFont MyTextFont
      {
      get {return myTextFont;}
      set {myTextFont = value;}
      }

      What you have, and what I changed it to was this:
      Code:
      [NinjaScriptProperty]
      [Display(ResourceType = typeof(Custom.Resource), Name = "Text Type", Description = "", GroupName = "Parameters", Order = 0)]
      public SimpleFont MyTextFont
      {
      get {return myTextFont;}
      set {myTextFont = value;}
      }

      I don't really understand what those two pieces do(the xmlignore vs ninjascriptproperty)... but that seems to be what was stopping the property from being saved in templates or workspaces?

      Also... I didn't set anything in state==state.setdefaults the way you did... but I changed that to match yours... but again, that didn't seem to be what was stopping it from being saved.

      Comment


        #4
        Hello forrestang, thanks for the follow up.

        It was the [XmlIgnore] property decorator that was causing the template to not save this property, sorry for not catching that in the first post. [XmlIgnore] means it will not save to workspace and template XML files.

        I initialized the font object in State.SetDefaults so the object gets initialized and is displayed in the property grid.

        Please let me know if I can assist any further.
        Chris L.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by varsha, Today, 06:33 PM
        0 responses
        2 views
        0 likes
        Last Post varsha
        by varsha
         
        Started by NtFan, Today, 04:12 PM
        1 response
        8 views
        0 likes
        Last Post NtFan
        by NtFan
         
        Started by futurenow, Today, 01:44 PM
        2 responses
        37 views
        0 likes
        Last Post voltation  
        Started by Gerik, Today, 12:44 PM
        1 response
        14 views
        0 likes
        Last Post NinjaTrader_Jim  
        Started by autogenix, Today, 01:01 PM
        3 responses
        20 views
        0 likes
        Last Post NinjaTrader_Emily  
        Working...
        X