爲什麼我的ItemsControl不是爲每個項目創建一個ContentPresenter?我猜這是什麼讓我的項目不出現(當我使用Live Visual Tree進行檢查時,它們被設置爲可見和正確的位置)。我基本上重複使用不同的ItemsControl上面的代碼,並且在搜索Google/Stackoverflow時遇到了這個問題,我一直無法找到任何東西。我可以包含視圖模型代碼,但我不認爲它是相關的,因爲我在Live Property Explorer中看到了適當的值,並且可以看到每個WellContainer都在它的合適的網格單元格中。ItemsControl未創建ContentPresenter
XAML:
<ItemsControl
Grid.Row="1"
Grid.Column="1"
ItemsSource="{Binding Wells}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<Grid
x:Name="m_WellGrid"
Margin="5"
wpf:GridHelpers.RowCount="{Binding RowCount}"
wpf:GridHelpers.ColumnCount="{Binding ColumnCount}">
</Grid>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemContainerStyle>
<Style>
<Setter
Property="Grid.Row"
Value="{Binding Path=WellRow}"/>
<Setter
Property="Grid.Column"
Value="{Binding Path=WellCol}"/>
</Style>
</ItemsControl.ItemContainerStyle>
<ItemsControl.ItemTemplate>
<DataTemplate>
<TextBlock
Text="A"
Margin="4"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
實況視覺樹檢查:
WellContainer定義在哪裏?你是否明確定義了一個'ContentPresenter'? –
我的視圖模型有一個'WellContainer'的'ObservableCollection','WellContainer'只是繼承自'Control'的同一個項目中的一個類。不,我沒有明確定義'ContentPresenter'只是'DataTemplate',因爲這是我在另外兩個似乎在附近工作的情況下所做的。 – m4gik
如果你的內容存在並且像你說的那樣處於正確的位置,請檢查'Z-Index'並確保它不僅僅隱藏在 –