【发布时间】:2013-10-22 10:00:57
【问题描述】:
我有一个可以水平滚动页面的 FlipVIew。 每个页面都包含一个带有 ItemsControl 的 ScrollViewer(垂直滚动)。 itemsControl 包含一个 itemTemplate,它是一行(每个页面包含数据行)。
I want to change the template of a row at some button click。现在我有 1 种类型的行,但我想实现另外 2 种类型,但不知道如何......基本上当前行类型是通过 DataTemplate 定义的,我想定义另外 2 个 DataTemplate 并将 dataTemplate 绑定到 ItemsControl。项目模板
<ItemsControl x:Name="RowItemsControl" ItemsSource="{Binding OptionItems, Mode=OneWay}" Visibility="{Binding OptionsPageVisibility}">
<ItemsControl.ItemTemplate>
<DataTemplate x:Name="RowType1">
<Grid x:Name="OptionItemGrid" Background="White" HorizontalAlignment="Stretch">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<!-- here is the content of the rowType1 -->
</Grid>
</DataTemplate>
<!--<DataTemplate x:Name="RowType2"> --- I want just 1 of these 3 data to be my item template
</DataTemplate x:Name="RowType2">
<DataTemplate x:Name="RowType3">
</DataTemplate x:Name="RowType3"> -->
</ItemsControl.ItemTemplate>
</ItemsControl>
【问题讨论】:
-
RowItemsControl声明在哪里,哪一部分你不知道怎么做? -
RowItemsControl 是一个 ItemsControl - 它绑定到一些包含数据数组的 ObservableCollection。现在我在
中有 1 个 DataTemplate。如何定义另外 2 个 DataTemplates(当然还有其他外观)并选择这 3 个 dataTemplates 中的 1 个作为 的内容? -
@Sheridan - 请再次查看我的帖子(我在其中进行了一些编辑(在 xaml 中))
-
我希望每个 DataTemplate 都有它的 Gui 并且当用户按下按钮来更改数据模板(行的 gui)
标签: wpf xaml windows-store-apps