Announcement

Collapse
No announcement yet.

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.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by CarlTrading, 05-11-2026, 05:56 AM
    0 responses
    52 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 05-10-2026, 08:12 PM
    0 responses
    29 views
    0 likes
    Last Post CarlTrading  
    Started by Hwop38, 05-04-2026, 07:02 PM
    0 responses
    194 views
    0 likes
    Last Post Hwop38
    by Hwop38
     
    Started by CaptainJack, 04-24-2026, 11:07 PM
    0 responses
    355 views
    0 likes
    Last Post CaptainJack  
    Started by Mindset, 04-21-2026, 06:46 AM
    0 responses
    274 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Working...
    X