2012-03-23 34 views
2

我有与使用相同的技术XAML数据绑定,对象不匹配目标类型

这对于命名为新闻源

<!-- Collection of grouped items displayed by this page --> 
<CollectionViewSource x:Name="groupedItemsViewSource" Source="{Binding Groups}" IsSourceGrouped="true" 
    ItemsPath="Items" d:Source="{Binding ItemGroups, Source={d:DesignInstance Type=data:NewsFeedDataSource, IsDesignTimeCreatable=True}}"/> 
第一组页2的外观相似类2不同组页

到该组数据传递到该组页。

这对于命名为事件

<CollectionViewSource x:Name="groupedItemsViewSource" Source="{Binding Groups}" IsSourceGrouped="true" 
    ItemsPath="Items" d:Source="{Binding ItemGroups, Source={d:DesignInstance Type=data:EventDataSource, IsDesignTimeCreatable=True}}"/> 

和一些与该ViewSource上述

<GridView x:Name="itemGridView" AutomationProperties.AutomationId="ItemGridView" AutomationProperties.Name="Grouped Items" Margin="116,0,40,46" 
       ItemsSource="{Binding Source={StaticResource groupedItemsViewSource}}" ItemTemplate="{StaticResource Standard250x250ItemTemplate}" 
       SelectionMode="None" 
       IsItemClickEnabled="True" 
       ItemClick="ItemView_ItemClick"> 

         <GridView.ItemsPanel> 
          <ItemsPanelTemplate> 
           <VirtualizingStackPanel Orientation="Horizontal"/> 
          </ItemsPanelTemplate> 
         </GridView.ItemsPanel> 

         <GridView.GroupStyle> 
          <GroupStyle> 
           <GroupStyle.HeaderTemplate> 
            <DataTemplate> 
             <Grid Margin="1,0,0,6"> 
              <Button 
             AutomationProperties.Name="Group Title" 
             Content="{Binding Title}" 
             Click="Header_Click" 
             Style="{StaticResource TextButtonStyle}"/> 
             </Grid> 
            </DataTemplate> 
           </GroupStyle.HeaderTemplate> 

           <GroupStyle.Panel> 
            <ItemsPanelTemplate> 
             <VariableSizedWrapGrid Orientation="Vertical" Margin="0,0,80,0"/> 
            </ItemsPanelTemplate> 
           </GroupStyle.Panel> 
          </GroupStyle> 
         </GridView.GroupStyle> 
        </GridView> 

和静态资源绑定的代码示例第二组页其绑定到250x250模板代码将是

<DataTemplate x:Key="Standard250x250ItemTemplate"> 
    <Grid HorizontalAlignment="Left" Width="250" Height="250"> 
     <Border Background="{StaticResource ListViewItemPlaceholderRectBrush}"> 
      <Image Source="{Binding Image}" Stretch="UniformToFill"/> 
     </Border> 
     <StackPanel VerticalAlignment="Bottom" Background="{StaticResource ListViewItemOverlayBackgroundBrush}"> 
      <TextBlock Text="{Binding Title}" Foreground="{StaticResource ListViewItemOverlayTextBrush}" Style="{StaticResource TitleTextStyle}" Height="60" Margin="15,0,15,0"/> 
      <TextBlock Text="{Binding PublishDate}" Foreground="{StaticResource ListViewItemOverlaySecondaryTextBrush}" Style="{StaticResource CaptionTextStyle}" TextWrapping="NoWrap" Margin="15,0,15,10"/> 
     </StackPanel> 
    </Grid> 
</DataTemplate> 

即使是能够在整个应用程序运行良好。但是我发现上面有一个源代码的底部。蓝线显示对象与目标类型不匹配。

任何knw wat发生的代码? = D 对不起,如果我没有发布所有信息。有点大。如果需要更多信息,请询问。

+0

你能发布2件更多的事情。我想我有一个想法..你能不能给我们的XAML线,其中NewsFeedDataSource和EventDataSource是否已设置,并且您是否可以验证您是否正在(在常规代码中)设置DefaultViewModel集合(由DataSource使用的集合)中的适当值? – DevTheo 2012-03-23 18:46:21

+0

@DevTheo 您是否创建了窗口8 metro app b4?它与样本完全一样,而我只是复制相同的一组类并编辑其中的一些信息。无论如何,因为你的要求,我尝试把相关的代码,以及= D – 2012-03-25 17:32:08

+0

其实,这是我得到的..我遇到了这样的事情,我有一个样本。在我的情况下,我有几件事情是错误的..最值得注意的是,我的DefaultViewModel提到了不同的来源..(虽然我也有一些错误的项目) – DevTheo 2012-03-26 13:09:54

回答

3

经过几次更多的测试后,我发现这个问题是由于itemspath和d:Source的名称相同而引起的。 的代码应该至少像

<UserControl.Resources> 

     <CollectionViewSource x:Name="groupedItemsViewSource" Source="{Binding Groups}" IsSourceGrouped="true" 
      ItemsPath="EventItems" d:Source="{Binding EventItemGroups, Source={d:DesignInstance Type=data:EventDataSource, IsDesignTimeCreatable=True}}"/> 
    </UserControl.Resources> 

<UserControl.Resources> 

    <!-- Collection of grouped items displayed by this page --> 
    <CollectionViewSource x:Name="groupedItemsViewSource" Source="{Binding Groups}" IsSourceGrouped="true" 
     ItemsPath="Items" d:Source="{Binding ItemGroups, Source={d:DesignInstance Type=data:NewsFeedDataSource, IsDesignTimeCreatable=True}}"/> 
</UserControl.Resources> 
相关问题