[英]Binding List of user controls to flipview?
I am planning to implement horizontal list of user controls, which i want to add it to the flip view during runtime, I tried the following code: 我打算实现用户控件的水平列表,我想在运行时将其添加到翻转视图中,我尝试了以下代码:
<FlipView Grid.Row="2" Name="SlideFlipView"
ItemsSource="{x:Bind SlideViews}"
SelectionChanged="SlideFlipView_SelectionChanged"
Background="AliceBlue">
<FlipView.ItemTemplate>
<DataTemplate>
<Frame Name="MenuDetailFrame" SourcePageType="{Binding}"/>
</DataTemplate>
</FlipView.ItemTemplate>
</FlipView>
Class looks like the following code: 类看起来像下面的代码:
public sealed partial class MenuDetailPage : Page
{
private List<object> SlideViews;
public MenuDetailPage()
{
this.InitializeComponent();
LoadInitials();
}
private void LoadInitials()
{
SlideViews = new List<object>
{
typeof(TopImageBottomTextControl),
typeof(TopTextBottomImageControl)
};
}
}
but the user control doesn't appear in the flip when I run the program. 但是当我运行程序时,用户控件没有出现在键盘盖上。 Let me know if I am missing something here 让我知道我是否想念这里的东西
According to the "Frame Class" : 根据“框架类别” :
SourcePageType can be set in XAML, using string-to-type conversion that's interpreted using XAML namespace mappings, but that's rarely done. 可以在XAML中使用通过XAML名称空间映射解释的字符串到类型的转换来设置SourcePageType,但这很少做到。 It's a better practice to have code at the app level that tracks activation and whether a suspended app is resuming, which then uses Frame.Navigate to set the current page. 更好的做法是在应用程序级别使用代码来跟踪激活以及是否暂停了正在恢复的应用程序,然后使用Frame.Navigate来设置当前页面。
For your requirement, you could bind the user control object to the Content
of Frame. 根据您的要求,可以将用户控件对象绑定到框架的Content
。
private void LoadInitials()
{
SlideViews = new List<object>
{
new TopImageBottomTextControl(),
new TopImageBottomTextControl()
};
}
Usage 用法
<FlipView Name="SlideFlipView"
ItemsSource="{x:Bind SlideViews}"
SelectionChanged="SlideFlipView_SelectionChanged"
Background="AliceBlue">
<FlipView.ItemTemplate>
<DataTemplate>
<Frame Name="MenuDetailFram" Content="{Binding}" />
</DataTemplate>
</FlipView.ItemTemplate>
</FlipView>
following code without datatemplate worked for me: 以下没有datatemplate的代码对我有用:
<FlipView Grid.Row="2"
Name="SlideFlipView"
ItemsSource="{x:Bind SlideViews}"
SelectionChanged="SlideFlipView_SelectionChanged"
Background="AliceBlue">
</FlipView>
initialization of slideviews object in Class looks like Class中slideviews对象的初始化看起来像
private void LoadInitials()
{
SlideViews = new List<object>
{
new UserControl1(),
new UserControl2()
};
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.