Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/three.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Windows phone 7 如何在WindowsPhone7中创建重复的文本块?_Windows Phone 7_Xaml_Data Binding - Fatal编程技术网

Windows phone 7 如何在WindowsPhone7中创建重复的文本块?

Windows phone 7 如何在WindowsPhone7中创建重复的文本块?,windows-phone-7,xaml,data-binding,Windows Phone 7,Xaml,Data Binding,数据绑定仍然让我感到困惑,我不知道如何让这些控件对我拥有的每个绑定数据重复 <Grid> <TextBlock FontSize="25" Text="this is a header"></TextBlock> <TextBlock Height="30" HorizontalAlignment="Left" Margin="19,36,0,0" Name="txt" Text="l

数据绑定仍然让我感到困惑,我不知道如何让这些控件对我拥有的每个绑定数据重复

   <Grid>
                <TextBlock FontSize="25" Text="this is a header"></TextBlock>
                <TextBlock Height="30" HorizontalAlignment="Left" Margin="19,36,0,0" Name="txt" Text="line under the header" VerticalAlignment="Top" />
                <TextBlock Height="30" FontSize="25" HorizontalAlignment="Left" Margin="306,9,0,0" Name="textBlock2" Text="530" VerticalAlignment="Top" Width="91" />
                <TextBlock Height="30" HorizontalAlignment="Left" Margin="305,42,0,0" Name="textBlock3" Text="30" VerticalAlignment="Top" Width="91" />
            </Grid>

如果我的数据源的计数为50。我希望看到50个这样的分组(我可能需要一个滚动条)


但我不知道该怎么做。我想我需要某种数据模板?另外,“标题下的行”应该可以单击并高亮显示。

我认为您需要使用名为“ItemsControl”的控件。不是派生类,不是列表框,只是简单的
ItemsControl

在代码或XAML中,可以将ItemsControl的
ItemsSource
属性设置为包含项目的任何集合

在XAML中(在VS或Blend中,要在Blend中实现所见即所得,您必须以某种方式提供设计数据),将ItemsControl的
ItemTemplate
设置为
DataTemplate
,其中包含要为集合中的每个项目重复的XAML子树

DataTemplate
中,将“标题下的行”替换为按钮控件,替换为
Content=“标题下的行”
,并根据需要设置样式。然后,将
CallMethodAction
添加到按钮中。只需在Blend中单击两次,第一次单击位于“资源”窗口。指定
TargetObject=“{Binding}”MethodName=“actSubtitleClicked”
。这样,框架将调用用户单击“标题下的行”的项目的
void actSubtitleClicked()
方法

为了获得最佳性能,您还应该修改ItemsControl的ItemsPanel模板,将StackPanel替换为VirtualzingStackPanel(同样,在Blend中单击几下,第一次是右键单击,然后单击“编辑其他模板/ItemsPanel/编辑副本”)