0
我有一個簡單的WP7程序,我想在列表框和Diagramm中顯示我的模型對象。在DataTemplate中使用ListBox控件
我想使用數據模板和選擇器類,它返回正確的模板。 的選擇發生在視圖模型的布爾屬性,並返回ListBoxTemplate或DiagrammTemplate
我的頁面資源看起來是這樣的:
<local:NewTemplateSelector x:Key="NewTemplateSelector">
<local:NewTemplateSelector.ListBoxTemplate>
<DataTemplate>
<StackPanel>
<ListBox
x:Name="MainListBox" Margin="6,205,35,136" ItemsSource="{Binding Acts}"
ItemTemplate="{Binding ElementName=Page, Path=Orientation,
Converter={StaticResource OrientationToListItemTemplate}}" />
</StackPanel>
</DataTemplate>
</local:NewTemplateSelector.ListBoxTemplate>
<local:NewTemplateSelector.DiagrammTemplate>
<DataTemplate>
<TextBlock Text="Diagramm"/>
</DataTemplate>
</local:NewTemplateSelector.DiagrammTemplate>
</local:NewTemplateSelector>
我的內容面板只有1個元素:
<ContentControl ContentTemplate="{Binding IsDiagramm,
Converter={StaticResource NewTemplateSelector}}" HorizontalAlignment="Left" HorizontalContentAlignment="Left" />
我當我運行這個時,總是得到一個空白屏幕。 我的選擇器類返回正確的模板,我可以在調試器中看到它。 當我用簡單的文本塊替換模板中的列表框時,將顯示文本塊,因此我懷疑數據綁定存在問題。
但是當模板中的列表框沒有任何數據模板插入到我的內容面板時,它可以正常工作。
我任何提示?
如何以及何時將數據放入內容控制中? – thomasmartinsen 2011-01-23 22:59:03