![](/img/trans.png)
[英]WPF binding different UserControls in a DataTemplate of TabControl
[英]Binding With a TabControl DataTemplate
我正在嘗試使用TabControl
將一些ViewModel容納到視圖中。
<TabControl SelectedIndex="{Binding QuestionIdx, Mode=TwoWay,
UpdateSourceTrigger=PropertyChanged}" ItemsSource="{Binding ProblemsVM}">
<TabControl.ContentTemplateSelector>
<problemSlector:ProblemsViewSelector>
<problemSlector:ProblemsViewSelector.FreeResponseTemplate>
<DataTemplate>
<views:FreeResponseView />
</DataTemplate>
</problemSlector:ProblemsViewSelector.FreeResponseTemplate>
</problemSlector:ProblemsViewSelector>
</TabControl.ContentTemplateSelector>
</TabControl>
。 。 。 我deubgged和confrimed(OnDataContextChanged)認為在DataContext FreeResponseView
是FreeResponseViewModel
。 出現FreeResponseView
並且選項卡的標題正確。 但是,在FreeResponseView
我有以下幾行似乎不起作用。
<toolkit:RichTextBox Text="{Binding Question, Mode=OneWay}" />
它沒有綁定來自數據源的Question
。
終於想通了。 。 。 代碼沒有錯,問題出在RichTextbox
。 我正在使用Xceed Extended WPF RichTextbox
。 事實證明,您必須使綁定為“可讀可寫”,否則綁定將不起作用。
<toolkit:RichTextBox Text="{Binding Question}" IsReadOnly="True" />
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.