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 kinfxhk, 07-14-2026, 09:39 AM
    0 responses
    7 views
    0 likes
    Last Post kinfxhk
    by kinfxhk
     
    Started by kinfxhk, 07-13-2026, 10:18 AM
    0 responses
    59 views
    0 likes
    Last Post kinfxhk
    by kinfxhk
     
    Started by kinfxhk, 07-13-2026, 09:50 AM
    0 responses
    41 views
    0 likes
    Last Post kinfxhk
    by kinfxhk
     
    Started by kinfxhk, 07-13-2026, 07:21 AM
    0 responses
    47 views
    0 likes
    Last Post kinfxhk
    by kinfxhk
     
    Started by kinfxhk, 07-11-2026, 02:11 AM
    0 responses
    38 views
    0 likes
    Last Post kinfxhk
    by kinfxhk
     
    Working...
    X