数据绑定不起作用
|
我正在开发Windows Phone应用。
我有以下C#代码:
private void Default_Loaded(object sender, RoutedEventArgs e)
{
long gameId;
short gameType;
loadedData = XDocument.Load(\"SampleData/GamesDesc.xml\");
if (NavigationContext.QueryString.Count == 2)
{
if (long.TryParse(NavigationContext.QueryString.Values.First(), out gameId))
{
if (short.TryParse(NavigationContext.QueryString.Values.Last(), out gameType))
{
var filteredData = from c in loadedData.Descendants(\"gameDescription\")
where c.Attribute(\"game_id\").Value == gameId.ToString() &&
c.Attribute(\"gameType\").Value == gameType.ToString() &&
c.Attribute(\"language\").Value.Equals(CultureInfo.CurrentCulture.TwoLetterISOLanguageName)
select new SampleData.GameDesc()
{
Id = uint.Parse(c.Attribute(\"game_id\").Value),
Name = c.Attribute(\"name\").Value,
Language = c.Attribute(\"language\").Value,
GameType = uint.Parse(c.Attribute(\"gameType\").Value),
ShortDescription = c.Attribute(\"shortDescription\").Value,
LongDescription = c.Attribute(\"longDescription\").Value
};
LayoutRoot.DataContext = filteredData;
}
}
}
}
以及以下XAML代码:
<!--LayoutRoot is the root grid where all page content is placed-->
<Grid x:Name=\"LayoutRoot\" Background=\"Transparent\">
<Grid.RowDefinitions>
<RowDefinition Height=\"Auto\"/>
<RowDefinition Height=\"*\"/>
</Grid.RowDefinitions>
<!--TitlePanel contains the name of the application and page title-->
<StackPanel x:Name=\"TitlePanel\" Grid.Row=\"0\" Margin=\"12,17,0,28\">
<TextBlock x:Name=\"ApplicationTitle\" Text=\"MY APPLICATION\" Style=\"{StaticResource PhoneTextNormalStyle}\"/>
<TextBlock x:Name=\"PageTitle\" Text=\"page name\" Margin=\"9,-7,0,0\" Style=\"{StaticResource PhoneTextTitle1Style}\"/>
</StackPanel>
<!--ContentPanel - place additional content here-->
<Grid x:Name=\"ContentPanel\" Grid.Row=\"1\" Margin=\"12,0,12,0\">
<Grid x:Name=\"LongDescPanel\" Margin=\"0\">
<Grid.RowDefinitions>
<RowDefinition Height=\"0.45*\"/>
<RowDefinition Height=\"0.55*\"/>
</Grid.RowDefinitions>
<TextBlock x:Name=\"LongDescription\" Margin=\"8,8,8,13\" TextWrapping=\"Wrap\" Text=\"{Binding LongDescription}\"/>
<Button x:Name=\"PlayButton\" Content=\"{Binding Path=AppResources.Play, Source={StaticResource LocalizedStrings}}\" VerticalAlignment=\"Top\" Margin=\"165,36,165,0\" d:LayoutOverrides=\"Width\" Grid.Row=\"1\" Click=\"PlayButton_Click\" />
</Grid>
</Grid>
</Grid>
为什么LongDescription
TextBlock不显示任何内容?
没有找到相关结果
已邀请:
1 个回复
凸晴
如果要显示所有项目而不是仅显示第一个项目,请使用ItemsControl。