本文整理汇总了C#中System.Windows.Controls.TextBlock.ClearValue方法的典型用法代码示例。如果您正苦于以下问题:C# TextBlock.ClearValue方法的具体用法?C# TextBlock.ClearValue怎么用?C# TextBlock.ClearValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Controls.TextBlock
的用法示例。
在下文中一共展示了TextBlock.ClearValue方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: getRandomTranslation
public string getRandomTranslation(TextBlock tb, bool[] answerTypes)
{
List<string> subL;
Random rnd = new Random();
int[] options = Enumerable.Range(0, 3).OrderBy(x => rnd.Next()).ToArray();
tb.ClearValue(TextBlock.FontStyleProperty);
tb.ClearValue(TextBlock.FontWeightProperty);
tb.Tag = this;
for (int i = 0; i < options.Length; i++)
{
switch (options[i])
{
case 0:
if (!answerTypes[0] || llLexicon.Count == 0) continue;
tb.FontStyle = FontStyles.Italic;
tb.Text = llLexicon[rnd.Next(llLexicon.Count)];
return tb.Text;
case 1:
if (!answerTypes[1] || llSynonyms.Count == 0) continue;
subL = llSynonyms[rnd.Next(llSynonyms.Count)];
tb.FontWeight = FontWeights.Bold;
tb.Text = subL[rnd.Next(subL.Count)];
return tb.Text;
case 2:
if (!answerTypes[2] || llMacedonian.Count == 0) continue;
subL = llMacedonian[rnd.Next(llMacedonian.Count)];
tb.Text = subL[rnd.Next(subL.Count)];
return tb.Text;
}
}
return "";
}
示例2: SettingTextNeverCreatesMoreThanOneRun
public void SettingTextNeverCreatesMoreThanOneRun ()
{
TextBlock tb = new TextBlock ();
string text;
Run run;
tb.Text = "this is line 1\rthis is line 2";
run = (Run) tb.Inlines[0];
Assert.AreEqual (1, tb.Inlines.Count, "1. Setting Text property should never create more than 1 Run");
Assert.AreEqual ("this is line 1\rthis is line 2", run.Text, "1. The Run's Text should remain unchanged");
tb.Text = "this is line 1\nthis is line 2";
run = (Run) tb.Inlines[0];
Assert.AreEqual (1, tb.Inlines.Count, "2. Setting Text property should never create more than 1 Run");
Assert.AreEqual ("this is line 1\nthis is line 2", run.Text, "2. The Run's Text should remain unchanged");
tb.Text = "this is line 1\r\nthis is line 2";
run = (Run) tb.Inlines[0];
Assert.AreEqual (1, tb.Inlines.Count, "3. Setting Text property should never create more than 1 Run");
Assert.AreEqual ("this is line 1\r\nthis is line 2", run.Text, "3. The Run's Text should remain unchanged");
// now try using the exact same line separator that LineBreak maps to
tb.Inlines.Clear ();
run.Text = "this is line 1";
tb.Inlines.Add (run);
tb.Inlines.Add (new LineBreak ());
run = new Run ();
run.Text = "this is line 2";
tb.Inlines.Add (run);
text = tb.Text;
tb.ClearValue (TextBlock.TextProperty);
tb.Text = text;
run = (Run) tb.Inlines[0];
Assert.AreEqual (1, tb.Inlines.Count, "4. Setting Text property should never create more than 1 Run");
Assert.AreEqual (text, run.Text, "4. The Run's Text should remain unchanged");
}