2012-12-27 39 views
0

我遇到了数据绑定的奇怪问题。在设计器中,所有内容都能正确显示,但在运行时,我的ListView只包含那些TextBlocks,其中包含一个空字符串。我为ViewModels使用MVVM光源。大部分代码是由VS2012通过为WindowsStore-Apps创建一个拆分页面生成的。ListView在运行时显示空的TextBlocks

这是我的XAML:(我已经去掉一些其他部分,如VisualStateManager,但没有效果,这样似乎并不成为一个问题。)

<common:LayoutAwarePage 
    x:Name="pageRoot" 
    x:Class="Kunden.OrderPage" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:local="using:Kunden" 
    xmlns:common="using:Kunden.Common" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    mc:Ignorable="d" 
    DataContext="{Binding SelectCustomersViewModel, Source={StaticResource Locator}}"> 

    <Page.Resources> 
     <CollectionViewSource 
      x:Name="itemsViewSource" 
      Source="{Binding Items}"/> 
    </Page.Resources> 

    <Grid Style="{StaticResource LayoutRootStyle}"> 
     <Grid.RowDefinitions> 
      <RowDefinition Height="140"/> 
      <RowDefinition Height="*"/> 
     </Grid.RowDefinitions> 
     <Grid.ColumnDefinitions> 
      <ColumnDefinition x:Name="primaryColumn" Width="610"/> 
      <ColumnDefinition Width="*"/> 
     </Grid.ColumnDefinitions> 

     <Grid x:Name="titlePanel"> 
      <Grid.ColumnDefinitions> 
       <ColumnDefinition Width="Auto"/> 
       <ColumnDefinition Width="*"/> 
      </Grid.ColumnDefinitions> 
      <Button 
       x:Name="backButton" 
       Click="GoBack" 
       IsEnabled="{Binding DefaultViewModel.CanGoBack, ElementName=pageRoot}" 
       Style="{StaticResource BackButtonStyle}"/> 
      <TextBlock x:Name="pageTitle" Grid.Column="1" Text="Werbeauswahl" Style="{StaticResource PageHeaderTextStyle}" Margin="0,0,-2,40"/> 
     </Grid> 

     <!-- Elementliste mit vertikalem Bildlauf --> 
     <ListView 
      x:Name="itemListView" 
      AutomationProperties.AutomationId="ItemsListView" 
      AutomationProperties.Name="Items" 
      TabIndex="1" 
      Grid.Row="1" 
      Margin="-10,-10,0,0" 
      Padding="120,0,0,60" 
      IsSwipeEnabled="False" 
      SelectionChanged="ItemListView_SelectionChanged" 
      ItemsSource="{Binding AvaiableCountries}"> 
      <ListView.ItemTemplate> 
       <DataTemplate> 
        <TextBlock Text="{Binding Name}"/> 
       </DataTemplate> 
      </ListView.ItemTemplate> 
     </ListView> 
... closing brackets etc. 

IEnumerable我要绑定:

private IEnumerable<Country> avaiableCountries; 

     public IEnumerable<Country> AvaiableCountries 
     { 
      get { return avaiableCountries; } 
      set { avaiableCountries = value; RaisePropertyChanged(() => AvaiableCountries); } 
     } 

的数据值对象Country我需要为我的LINQ查询:

public class Country 
    { 
     internal string Name { get; set; } 
    } 

回答

1

请尝试将名称属性的访问修饰符从internal更改为public,然后查看是否解决了您的问题?

如果不张贴代码工作在那里你填充AvaiableCountries数据

+0

太他妈的容易...它改变公众的伎俩。我已经这样做了,但似乎我没有尝试运行它与这个变化虽然... 奇怪的事情,它被显示在设计师,但... – Zhedar