当前位置: 首页>>代码示例>>C#>>正文


C# TextBlock.ClearValue方法代码示例

本文整理汇总了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 "";
        }
开发者ID:TheHalcyonSavant,项目名称:VocabularyGame,代码行数:33,代码来源:Auxiliary.cs

示例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");
		}
开发者ID:kangaroo,项目名称:moon,代码行数:38,代码来源:TextBlockTest.cs


注:本文中的System.Windows.Controls.TextBlock.ClearValue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。