【问题标题】:C# - wp8: change textblock content by dynamically?C# - wp8:动态更改文本块内容?
【发布时间】:2013-08-28 09:24:43
【问题描述】:

我的应用中有几个 html 文件。我通过 webBrowser 显示它。我将当前显示页面的编号存储为string Page。我想在文本块中显示该页面名称。因此,我将这些文本存储为字符串。例如

string chapter1 = "Welcome page";
string chapter2 = "About us";
//...// 100 strings

如果在浏览器中显示欢迎页面,string page 将是 1。使用 string page string chapter1 应该是 fileName.Text 同样我想显示。但是,我不知道该怎么做。最好的答案将不胜感激。

C#代码;

TextBlock fileName = new TextBlock();
fileName.Margin = new Thickness(0);
fileName.FontSize = 30;
fileName.Foreground = new SolidColorBrush(Colors.White);
fileName.TextAlignment = TextAlignment.Center;
fileName.Text = "???";

【问题讨论】:

  • 如果你使用的是html,你怎么把它标记为c#?
  • 我通过 webBrowser 显示 html 内容

标签: c# xaml windows-phone-8


【解决方案1】:

如果您的 XAML 控件标记为 [具有 名称 标记],那么您可以像这样从 C# 调用它们:

XAML:

<TextBlock Name="fileName" Margin="0,0,10,0" FontSize="30" Foreground="White" TextAlignment="Center" />
<phone:WebBrowser x:Name="browser" IsScriptEnabled="True" /><br>


C#:[假设你有一个按钮]

btn_Click+=(s, args) => {
fileName.Text="NewText";
}

【讨论】:

    【解决方案2】:

    我使用switch 语句完成了它。总之谢谢大家

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-05-16
      • 1970-01-01
      • 2017-09-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-05
      相关资源
      最近更新 更多