2014-01-22 56 views
0

我有一個用於textblock的擴展,以允許分配格式化的「Inlines」。我遵循@max提供的方法來創建此擴展。現在如何以編程方式設置TextBlock擴展屬性

Format part of the text of TextBlock using iValueConverter

,我需要做的是能夠以編程方式設置此FormattedText屬性的UI元素,這是被動態創建TextBlock的父母。

<TextBlock FontSize="14" FontFamily="Calibri" local:TextBlockEx.FormattedText="{Binding Converter={StaticResource LabelFormatConerter}}" /> 

回答

1

您是否嘗試過使用在鏈接問題的答案中明確聲明的方法,或者您是否複製而不看?也許這樣的事情?:

TextBlockEx textBlockEx = new TextBlockEx(); 
textBlockEx.SetFormattedText(textBlockEx, new Run() { Text = "Hello World" }); 

UPDATE >>>

真的應該問的每一件事情一次,而不是要求額外的問題,一旦你的問題得到了解答。我可以「T甚至可以提供一個完整的答案你問題,如你移除了BindingBinding.PathSource。在代碼中創建您Binding

Binding binding = new Binding("PropertyOfYourDataSourceObject"); 
binding.Source = YourDataSourceObject; 
binding.Converter = new SomeConverter(); 
textBlockEx.SetBinding(TextBlockEx.FormattedTextProperty, binding); 

請參閱How to: Create a Binding in Code頁面上MSDN以獲得更多幫助。

+0

感謝您的回覆。正如你在答覆中所建議的那樣,我認爲我確實達到了這一點。但是,我注意到我實際上並沒有包含我需要幫助的代碼行。我正在尋找將這個XAML轉換爲C#代碼,我可以從代碼隱藏中做到這一點。 – user1869870

+0
相關問題