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 NullPointStrategies, Today, 05:17 AM
    0 responses
    50 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    126 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    69 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    42 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    46 views
    0 likes
    Last Post TheRealMorford  
    Working...
    X