c#标签未显示正确的内容

时间:2017-01-21 12:08:31

标签: c# wpf xaml

我有label.content ...

的问题

内容是" my_text_formated"但他表示" mytext_formated"

为什么这样做? :/

(我使用C#wpf编程,我使用的是VisualStudio 15专业版)

重现代码(如果尝试,您只需要点击按钮);

XAML

        <Button x:Name="btnFormat" Content="formatText" HorizontalAlignment="Left" Margin="50,118,0,0" VerticalAlignment="Top" Width="75" Click="btnFormat_Click"/>
        <Label x:Name="lblResult" Content="defaultResult" HorizontalAlignment="Left" Margin="160,112,0,0" VerticalAlignment="Top"/>
        <TextBox x:Name="txtBoxText" HorizontalAlignment="Left" Height="23" Margin="50,75,0,0" TextWrapping="Wrap" Text="my text formated" VerticalAlignment="Top" Width="120"/>

XAML.CS

private void btnFormat_Click(object sender, RoutedEventArgs e)
    {
        lblResult.Content = toFormatString(txtBoxText.Text);
        Console.WriteLine("AFTER_SET_CONTENT =>" + lblResult.Content);
    }

    public string toFormatString(string text)
    {
        List<String> FormatList = text.Split(' ').ToList();
        String result = "";
        foreach (String s in FormatList)
        {
            if (!String.IsNullOrEmpty(result))
                result += "_";
            result += s;
        }
        Console.WriteLine("IN_FORMAT_METHOD =>" + result);
        return result;
    }

输出结果:

控制台:

IN_FORMAT_METHOD =&gt; my_text_formated

AFTER_SET_CONTENT =&gt; my_text_formated

Windows: mytext_formated

0 个答案:

没有答案