如何使用定义的某些内容模板动态添加 flipviewitems
How to add flipviewitems dynamically with some content template defined
我的 Windows 8.1 应用程序 (RT) 中有一个 FlipView,其模板定义如下:
<FlipView Grid.Row="3"
Grid.ColumnSpan="2" x:Name="FlipView1" BorderBrush="Black"
ItemsSource="{Binding ItemsCollection, RelativeSource={RelativeSource TemplatedParent}}">
<FlipView.ItemTemplate>
<DataTemplate>
<ScrollViewer>
<Grid>
<local:UserControlA x:Name="PART_UserControlA"/>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<local:UserControlB Grid.Column="1"
View="{Binding View}"
x:Name="PART_UserControlB"
ItemsSource="{Binding ItemsSourcePropertyOfAnItemInItemsCollection}"
ItemTemplate="{Binding TemplatePropertyOfAnItemInItemsCollection}" />
</Grid>
</Grid>
</ScrollViewer>
</DataTemplate>
</FlipView.ItemTemplate>
</FlipView>
基本上,这个翻转视图是用来显示日历控件的。因此,我应该在选择更改事件中添加项目(以显示 next/previous months/weeks 日历)。我怎样才能在代码后面做到这一点? ItemsCollection
包含说 ObjectA
的集合。我已经准备好新对象(它将被添加到翻转视图的 ItemsSource 集合中。我也将它添加到翻转视图的 ItemsSource 中。但是,我认为它不仅仅是将新项目添加到物品来源?
啊,忽略我对WPF知识的匮乏。就像使 ItemsCollection 成为 ObservableCollection 并将绑定定义为 TwoWay ItemsSource="{Binding ItemsCollection, RelativeSource={RelativeSource TemplatedParent}, Mode=TwoWay}"
一样简单
我的 Windows 8.1 应用程序 (RT) 中有一个 FlipView,其模板定义如下:
<FlipView Grid.Row="3"
Grid.ColumnSpan="2" x:Name="FlipView1" BorderBrush="Black"
ItemsSource="{Binding ItemsCollection, RelativeSource={RelativeSource TemplatedParent}}">
<FlipView.ItemTemplate>
<DataTemplate>
<ScrollViewer>
<Grid>
<local:UserControlA x:Name="PART_UserControlA"/>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<local:UserControlB Grid.Column="1"
View="{Binding View}"
x:Name="PART_UserControlB"
ItemsSource="{Binding ItemsSourcePropertyOfAnItemInItemsCollection}"
ItemTemplate="{Binding TemplatePropertyOfAnItemInItemsCollection}" />
</Grid>
</Grid>
</ScrollViewer>
</DataTemplate>
</FlipView.ItemTemplate>
</FlipView>
基本上,这个翻转视图是用来显示日历控件的。因此,我应该在选择更改事件中添加项目(以显示 next/previous months/weeks 日历)。我怎样才能在代码后面做到这一点? ItemsCollection
包含说 ObjectA
的集合。我已经准备好新对象(它将被添加到翻转视图的 ItemsSource 集合中。我也将它添加到翻转视图的 ItemsSource 中。但是,我认为它不仅仅是将新项目添加到物品来源?
啊,忽略我对WPF知识的匮乏。就像使 ItemsCollection 成为 ObservableCollection 并将绑定定义为 TwoWay ItemsSource="{Binding ItemsCollection, RelativeSource={RelativeSource TemplatedParent}, Mode=TwoWay}"