2015-07-28 43 views
0

我有ItemControlItemsControl的顯示僅收集

<ItemsControl ItemsSource="{Binding CanvasCollection}"> 
       <ItemsControl.ItemsPanel> 
        <ItemsPanelTemplate>      
         <Canvas Width="{Binding CanvasSize}" Height="{Binding CanvasSize}" Background="RoyalBlue" />      
       </ItemsPanelTemplate> 
      </ItemsControl.ItemsPanel> 
      <ItemsControl.ItemContainerStyle> 
       <Style TargetType="ContentPresenter"> 
        <Setter Property="Canvas.Left" Value="{Binding X}" /> 
        <Setter Property="Canvas.Top" Value="{Binding Y}" /> 
       </Style> 
      </ItemsControl.ItemContainerStyle> 
      <ItemsControl.ItemTemplate> 
       <DataTemplate DataType="{x:Type viewModels:VertexViewModel}"> 
        <Thumb Width="11" Height="11"> 
         <Thumb.Template> 
          <ControlTemplate> 
           <Ellipse Width="11" Height="11" Fill="{Binding Fill}" /> 
          </ControlTemplate> 
         </Thumb.Template> 
        </Thumb> 
       </DataTemplate> 
      </ItemsControl.ItemTemplate> 
</ItemsControl> 

和複合收集與當前一個ObservableCollection的第一個元素:

private ObservableCollection<VertexViewModel> Points { get; set; } 
public CompositeCollection CanvasCollection { get; set; } 

調試時,我看到集合包含兩個元素,如我接受,但只有第一個顯示在畫布上。當我在模型中調用Refresh()方法時,我看到綁定工作,但僅用於第一個元素。

添加指向CompositeCollection:

Points = new ObservableCollection<VertexViewModel>(); 
     CanvasCollection = new CompositeCollection() 
     { 
      Points 
     }; 
+1

如果你寫的'的ItemsSource = 「{綁定點}」'會發生什麼? – Clemens

+0

嗯,這種方式一切正常,但我不明白,CompositeCollection有什麼問題。 – Aminion

回答

0

我不得不使用容器collectoin:

CanvasCollection = new CompositeCollection 
     { 
      new CollectionContainer() {Collection = Points}, 
      Polygon, 
     };