C# 如何在源为Windows Phone应用程序中的数据绑定的TextBlock中获取以下属性值
请看一下这张图片以了解我的场景 因此,在我的Windows Phone应用程序中,我有一个具有以下布局的列表框 我的列表框的XAMLC# 如何在源为Windows Phone应用程序中的数据绑定的TextBlock中获取以下属性值,c#,list,xaml,binding,nested,C#,List,Xaml,Binding,Nested,请看一下这张图片以了解我的场景 因此,在我的Windows Phone应用程序中,我有一个具有以下布局的列表框 我的列表框的XAML <ListBox x:Name="llsIceCreamBrands" Margin="0,54,0,0" CacheMode="BitmapCache"> <ListBox.ItemTemplate> <D
<ListBox x:Name="llsIceCreamBrands" Margin="0,54,0,0" CacheMode="BitmapCache">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Margin="0,0,0,40">
<StackPanel>
<Border BorderBrush="{StaticResource PhoneProgressBarBackgroundBrush}" BorderThickness="3">
<Image Width="200" Height="200" Source="{Binding IceCreamBrandImage }" Margin="3,0,0,0" Stretch="Fill"/>
</Border>
</StackPanel>
<StackPanel>
<Grid Margin="20,-5,0,0" Height="250" >
<StackPanel>
<TextBlock Text="{Binding IceCreamBrandName }" FontWeight="SemiBold" FontSize="34" FontFamily="Segoe WP" Margin="0" TextWrapping="Wrap" Width="184" VerticalAlignment="Top" HorizontalAlignment="Left" Opacity="1" LineStackingStrategy="BlockLineHeight" LineHeight="35" Height="Auto" />
<TextBlock Text="{Binding IceCreamBrandFlavour }" FontWeight="Normal" FontSize="15" FontFamily="Segoe WP" TextWrapping="Wrap" VerticalAlignment="Top" Width="200" Opacity="0.7" HorizontalAlignment="Left" IsHitTestVisible="False" Height="140"/>
</StackPanel>
</Grid>
</StackPanel>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
但这对Ben&Jerrys和Haagen Dazz来说都是相同的价值——这是两个品牌口味的融合
我怎样才能实现我想要的呢?我看不出您在GetIceCreamBrands中从何处定义变量“sourceFlavourList”,因此我假设您在代码的其他地方定义了这个变量。这就解释了为什么当你不断地将所有口味添加到这一变量中时,你会看到两个品牌的全部口味列表 因此,您需要绑定到结果中的每个品牌列表,而不是使用这个完整列表变量,这样您就可以使用相同的linq,但使用不同的源变量 试着这样做:
var flavours = string.Join(Environment.NewLine, dc.IceCreams[cID].Brands[j].Flavour.Select(x => x.Name));
sourceIceCreamBrands.Add(new IceCreamBrands
{
IceCreamBrandName = dc.IceCreams[cID].Brands[i].Name,
IceCreamBrandImage = bmp,
IceCreamBrandFlavour = flavours
});
您好,谢谢您的回复,但这一次它将上一个品牌的味道返回到所有品牌中:您能在GetIceCreamBrands末尾检查sourceIceCreamBrands的结果吗?这是你所期望的两种产品吗,每种都有正确的图像和味道列表?如果是这样,您是否正确绑定到这个变量sourceIceCreamBrands?是的,我得到了正确的图像和正确的品牌名称,但我想我刚刚能够找到它…我刚刚找到它!我创建了一个新的列表,并在每次出现j++和I++时将var-flavors添加到列表中——我通过指定[I]作为列表的索引获得了这些味道:非常感谢您的帮助
string mystring = string.Join(Environment.NewLine, sourceFlavourList.Select(x => x.IceCreamBrandFlavourName));
var flavours = string.Join(Environment.NewLine, dc.IceCreams[cID].Brands[j].Flavour.Select(x => x.Name));
sourceIceCreamBrands.Add(new IceCreamBrands
{
IceCreamBrandName = dc.IceCreams[cID].Brands[i].Name,
IceCreamBrandImage = bmp,
IceCreamBrandFlavour = flavours
});