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

    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:
      [COLOR=#c0392b][XmlIgnore][/COLOR]
      [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:
      [COLOR=#c0392b][NinjaScriptProperty][/COLOR]
      [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.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Mindset, 04-21-2026, 06:46 AM
        0 responses
        44 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by M4ndoo, 04-20-2026, 05:21 PM
        0 responses
        56 views
        0 likes
        Last Post M4ndoo
        by M4ndoo
         
        Started by M4ndoo, 04-19-2026, 05:54 PM
        0 responses
        35 views
        0 likes
        Last Post M4ndoo
        by M4ndoo
         
        Started by cmoran13, 04-16-2026, 01:02 PM
        0 responses
        95 views
        0 likes
        Last Post cmoran13  
        Started by PaulMohn, 04-10-2026, 11:11 AM
        0 responses
        57 views
        0 likes
        Last Post PaulMohn  
        Working...
        X