使用相同的ItemSsource区分ItemsControl

时间:2013-02-12 13:12:37

标签: c# wpf binding itemscontrol itemsource

我有一个ObservableCollection,它是3个不同ItemsControl的ItemSource: LeftItemControl,CenterItemControl和RightItemControl,我无法理解为什么唯一有效的ItemsControl是我在XAML文件中写的最后一个...

我尝试了一个ListCollectionView但它没有改变任何东西......它让我发疯,因为我认为它会像那样工作得很好......

看起来我不理解绑定的行为......

这是我使用两次的ItemsControl:

 <ItemsControl x:Name="HeadbandControl">
        <ItemsControl.ItemsPanel>
            <ItemsPanelTemplate>
                <DockPanel Width="100" />
            </ItemsPanelTemplate>
        </ItemsControl.ItemsPanel>
        <!-- To set the Dock property we need to use this tag and not in the SurfaceButton  -->
        <ItemsControl.ItemContainerStyle>
            <Style TargetType="ContentPresenter">
                <Setter Property="DockPanel.Dock" Value="Top"/>
            </Style>
        </ItemsControl.ItemContainerStyle>
        <ItemsControl.ItemTemplate>
            <!-- TEMPLATE -->
            <DataTemplate x:Name="HeadBandSketch"  DataType="{x:Type class:Sketch}">
                <Grid Margin="2">
                    <Border BorderThickness="1" BorderBrush="CornflowerBlue">
                    <s:SurfaceButton Panel.ZIndex="2" Opacity="1"  Width="100"  Height="75"
                                 s:TouchExtensions.HoldGesture="SketchButton_OnHold" PreviewTouchDown="HeadbandButton_PreviewTouchDown"
                                  Background="Transparent"
                                 />
                    </Border>
                    <test:PreviewSketchControl />

                </Grid>
            </DataTemplate>
        </ItemsControl.ItemTemplate>
    </ItemsControl>

这是PreviewSketchControl.Xaml

<UserControl x:Class="SurfaceSketching.Sketches.Control.PreviewSketchControl"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" IsEnabled="False" IsManipulationEnabled="False">

<Grid>
    <Grid.LayoutTransform>
        <ScaleTransform ScaleX="0.10" ScaleY="0.10" CenterX=".5" CenterY=".5" />
    </Grid.LayoutTransform>
    <ItemsControl ItemsSource="{Binding Shapes}">
        <ItemsControl.ItemsPanel>
            <ItemsPanelTemplate>
                <Canvas/>
            </ItemsPanelTemplate>
        </ItemsControl.ItemsPanel>
        <ItemsControl.ItemTemplate>
            <DataTemplate>
                <Grid>
                    <UserControl Content="{Binding }"/>
                </Grid>
            </DataTemplate>
        </ItemsControl.ItemTemplate>
    </ItemsControl>
</Grid>

最后,我如何设置ItemSource:

CenterContent.CenterContentScatterView.ItemsSource = Sketchs;
HeadbandLeft.HeadbandControl.ItemsSource = Sketchs;
HeadbandRight.HeadbandControl.ItemsSource = Sketchs;

Sketch是 public ObservableCollection<Sketch> Sketchs { get; set; }

0 个答案:

没有答案
相关问题