當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。