如何在Silverlight中将TextBlock的文本设置为粗体?

发布于 2024-10-18 06:35:56 字数 434 浏览 2 评论 0原文

我正在用 C# 开发 Windows Phone 7 应用程序。我是 Windows Phone 7 应用程序的新手。我也是银光新手。我想动态生成Texblock的粗体文本。我只想为文本的某些部分生成粗体文本。我正在使用以下代码,

IncometextBlock.Text = "Income entries on " + selectedDate.ToShortDateString() + "        Page - "+SelectedButtonName+"";

我希望输出为

21/01/2011 页面上的收入条目 - A

我想要上述输出。如何将上述要求的文字加粗?您能否提供任何代码或链接来解决上述问题。如果我做错了什么,请指导我。

I am developing window phone 7 application in C#. I am new to the window phone 7 application. I am also new to the silverlight. I want to generate the bold text of Texblock dynamically. I want to generate the bold text only for some part of the text. I am using the following code

IncometextBlock.Text = "Income entries on " + selectedDate.ToShortDateString() + "        Page - "+SelectedButtonName+"";

I want the output as

"Income entries on 21/01/2011 Page - A"

I want the above output. How to make the bold text for above requirement ? Can you please provide me any code or link through which I can resolve the above issue. If I am doing anything wrong then please guide me.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

回首观望 2024-10-25 06:35:56

我会这样做。

IncometextBlock.Inlines.Clear();
IncometextBlock.Inlines.Add(new Run() {Text = "Income entries", FontWeight = FontWeights.Bold});
IncometextBlock.Inlines.Add(new Run() {Text = " on " }); 
IncometextBlock.Inlines.Add(new Run() {Text = selectedDate.ToShortDateString(), FontWeight = FontWeights.Bold});
IncometextBlock.Inlines.Add(new Run() {Text = "     Page - "}); 
IncometextBlock.Inlines.Add(new Run() {Text = SelectedButtonName, FontWeight = FontWeights.Bold});

I'd do it like this.

IncometextBlock.Inlines.Clear();
IncometextBlock.Inlines.Add(new Run() {Text = "Income entries", FontWeight = FontWeights.Bold});
IncometextBlock.Inlines.Add(new Run() {Text = " on " }); 
IncometextBlock.Inlines.Add(new Run() {Text = selectedDate.ToShortDateString(), FontWeight = FontWeights.Bold});
IncometextBlock.Inlines.Add(new Run() {Text = "     Page - "}); 
IncometextBlock.Inlines.Add(new Run() {Text = SelectedButtonName, FontWeight = FontWeights.Bold});
盗心人 2024-10-25 06:35:56

如果您使用 WrapPanel(来自工具包),您可以执行以下操作:(

<Grid>
    <toolkit:WrapPanel>
        <TextBlock Text="Income entries" FontWeight="Bold"/>
        <TextBlock Text=" on "/>
        <TextBlock Text="21/01/2011" FontWeight="Bold"/>
        <TextBlock Text=" Page - "/>
        <TextBlock Text="A" FontWeight="Bold"/>
    </toolkit:WrapPanel>
</Grid>

以上是仅在网格中启用代码突出显示,并且不需要使效果起作用。)

If you use the WrapPanel (from the Toolkit) you can do this:

<Grid>
    <toolkit:WrapPanel>
        <TextBlock Text="Income entries" FontWeight="Bold"/>
        <TextBlock Text=" on "/>
        <TextBlock Text="21/01/2011" FontWeight="Bold"/>
        <TextBlock Text=" Page - "/>
        <TextBlock Text="A" FontWeight="Bold"/>
    </toolkit:WrapPanel>
</Grid>

(The above is only in a grid to enable code highlighting here in SO and does not need to be for the effect to work.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文