C# XAML中的Windows phone 8数据模板未显示数据
我想在我的应用程序中的数据模板中显示一些信息,但当它运行时,列表框中不会显示任何信息 下面是类代码(称为notes的类)C# XAML中的Windows phone 8数据模板未显示数据,c#,xaml,windows-phone-8,listbox,datatemplate,C#,Xaml,Windows Phone 8,Listbox,Datatemplate,我想在我的应用程序中的数据模板中显示一些信息,但当它运行时,列表框中不会显示任何信息 下面是类代码(称为notes的类) 公共课堂笔记 { 公共字符串strnotame{get;set;} 公共字符串strCreated{get;set;} 公共字符串strModified{get;set;} 公共bool boolIsProtected{get;set;} 公共字符串strNoteImage{get;set;} 公共静态ObservableCollection GetnotesRecord()
公共课堂笔记
{
公共字符串strnotame{get;set;}
公共字符串strCreated{get;set;}
公共字符串strModified{get;set;}
公共bool boolIsProtected{get;set;}
公共字符串strNoteImage{get;set;}
公共静态ObservableCollection GetnotesRecord()
{
ObservableCollection notesRecord=新的ObservableCollection
{
新注释{strnotame=“Science”,strCreated=“17/07/2014”,strModified=“17/07/2014”,boolIsProtected=true,strNoteImage=”“},
新注释{strnotame=“Math”,strCreated=“12/02/2014”,strModified=“15/07/2014”,boolIsProtected=false,strNoteImage=”“},
新注释{strnotame=“HW”,strCreated=“05/06/2014”,strModified=“2/07/2014”,boolIsProtected=false,strNoteImage=”“},
新注释{strnotame=“Business”,strCreated=“23/04/2014”,strModified=“17/07/2014”,boolIsProtected=true,strNoteImage=”“},
};
回执记录;
}
公众可观察的集合票据;
公共可观测集合所有注释
{
得到
{
还票;;
}
设置
{
_注释=价值;
}
}
}
下面是XAML代码:
<ListBox Margin="0,10,0,88">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Grid Margin="0,5,0,0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="auto"></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
</Grid.ColumnDefinitions>
<Image Source="{Binding strNoteImage}" Height="80" Width="80" Grid.Column="0"></Image>
<StackPanel Grid.Column="1" Orientation="Vertical" Width="150" Height="100" >
<TextBlock Text="{Binding strNoteName}" Margin="5,1,0,1"></TextBlock>
<TextBlock Text="{Binding strCreated}" Margin="5,1,0,1"></TextBlock>
<StackPanel Orientation="Horizontal">
<TextBlock Text="Last modified: " Margin="5,1,0,1"></TextBlock>
<TextBlock Text="{Binding strModified}" Margin="3,1,0,1"></TextBlock>
</StackPanel>
<StackPanel Orientation="Horizontal">
<TextBlock Text="Is protected: " Margin="5,1,0,1"></TextBlock>
<TextBlock Text="{Binding boolIsProtected}" Margin="3,1,0,1"></TextBlock>
</StackPanel>
</StackPanel>
</Grid>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox >
提前感谢您的帮助:)您无法将ItemsSource设置到列表框 您可以在XAML中实现这一点,并在代码隐藏中设置DataContext,类似这样
<ListBox Margin="0,10,0,88" Name = "lstBox1" ItemsSource= "{Binding}" />
或
将列表框定义更改为
<ListBox Margin="0,10,0,88" ItemsSource="{Binding}">
首先,为什么要将boolIsProtected绑定到图像?对不起,我也意识到了这一点。这是更新后的代码@Sajeetharan,当添加
Name=“lstBox1”ItemSource={Binding}
时,在Binding语句周围出现一个错误,说“{不是有效的名称”ItemSource应该有“。Like ItemSource=“{Binding}”@KasunKV谢谢通知:)
This.DataContext = GetnotesRecord();
lstBox1.ItemsSource = GetnotesRecord();
<ListBox Margin="0,10,0,88" ItemsSource="{Binding}">
this.DataContext = Notes.GetnotesRecord();