好吧,這是一個令人難以置信的簡單問題,但卻讓我發瘋。我正在學習DataTemplating,並試圖將非常簡單的ItemTemplate應用於ListBox。WPF - 非常基本的ListBox.ItemTemplate問題
但是,當我運行我的應用程序時,模板完全被忽略,我只是看到了標準的列表框,而實際上我希望看到與「測試」一起的複選框列表。
我試過這幾次,總是相同的結果。我已經在Google上檢查過幾個資源,並且它們都具有用於在ListBox上定義和ItemTemplate的相同類型的語法,所以我確實無法看到我要出錯的地方。
代碼...
<Grid x:Name="LayoutRoot">
<ListBox x:Name="TestList"
SelectionMode="Multiple">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel>
<CheckBox Content="Check this checkbox!"/>
<TextBlock>Test</TextBlock>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
<ListBox.Items>
<ListBoxItem>Bob</ListBoxItem>
<ListBoxItem>Jim</ListBoxItem>
<ListBoxItem>Dave</ListBoxItem>
<ListBoxItem>Larry</ListBoxItem>
<ListBoxItem>Tom</ListBoxItem>
</ListBox.Items>
</ListBox>
</Grid>
任何幫助極大的讚賞。對不起,這樣的啞似乎問題,但我真的在第一障礙這裏:(
AT