Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

WPF Labels not preserving spaces in contents

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

    WPF Labels not preserving spaces in contents

    Hello,
    I've created a "floating" Info Box (based on the DrawingToolTile Indicator) to display information about the current state of my strategy logic. Instead of a column of buttons, it's a column of labels.

    Everything about it works perfectly, EXCEPT, if I set the "Content" of the label to a string that has spaces in it, the spaces seem to be ignored, or are stripped out. For example, if I pass in "Valid Signal Detected", the label displays "ValidSignalDetected".

    Here's the code that's creating the labels initially (there are two labels for each piece of data I'm displaying, one for the key (aka "title"), and one for the value).

    Code:
    foreach (var key in _infoBoxKeys)
    {
        Label keyLabel = new Label
        {
            Content = key,
            Foreground = textColor,
            FontFamily = fontFamily,
            FontSize = 12,
            FontWeight = FontWeights.Bold,
            FontStyle = FontStyles.Normal,
            Margin = new Thickness(3, 3, 3, 0),
            Padding = new Thickness(3, 3, 3, 0),
            BorderBrush = borderBrush,
            BorderThickness = rowCount == 0 ? new Thickness(0) : new Thickness(0, 1, 0, 0),
        };
    
        Label valueLabel = new Label
        {
            Content = "--",
            Foreground = textColor,
            FontFamily = fontFamily,
            FontSize = 12,
            FontStyle = FontStyles.Normal,
            Margin = new Thickness(3),
            Padding = new Thickness(3),
        };
    
        _infoBoxValueLabels[key] = valueLabel;
    
        contentGrid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Auto) });
        contentGrid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Auto) });
    
        Grid.SetRow(keyLabel, rowCount);
        Grid.SetColumn(keyLabel, 0);
    
        Grid.SetRow(valueLabel, rowCount + 1);
        Grid.SetColumn(valueLabel, 0);
    
        contentGrid.Children.Add(keyLabel);
        contentGrid.Children.Add(valueLabel);
    
        rowCount += 2;
    };​​


    And when I want to change the contents of the valueLabel, I just do...
    Code:
    _infoBoxValueLabels[key].Content = value;
    Any ideas how I can get the label to preserve the spaces???

    Thanks!

    #2
    Hello GregX999,

    Thank you for your post.

    WPF labels are not a NinjaTrader-specific concept, so modifying them and trying to preserve spaces goes outside of the scope of support offered by our team. I suggest referring to outside resources, such as the following publicly available link, for more information about Labels:


    Thank you for using NinjaTrader.
    Emily C.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Haiasi, 04-25-2024, 06:53 PM
    2 responses
    16 views
    0 likes
    Last Post Massinisa  
    Started by Creamers, Today, 05:32 AM
    0 responses
    4 views
    0 likes
    Last Post Creamers  
    Started by Segwin, 05-07-2018, 02:15 PM
    12 responses
    1,786 views
    0 likes
    Last Post Leafcutter  
    Started by poplagelu, Today, 05:00 AM
    0 responses
    3 views
    0 likes
    Last Post poplagelu  
    Started by fx.practic, 10-15-2013, 12:53 AM
    5 responses
    5,407 views
    0 likes
    Last Post Bidder
    by Bidder
     
    Working...
    X