用户控件绑定列表到 flipview?
Binding List of user controls to flipview?
我打算实现用户控件的水平列表,我想在运行期间将其添加到翻转视图中,我尝试了以下代码:
<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 看起来像下面的代码:
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)
};
}
}
但是当我运行程序时,用户控件没有出现在翻盖中。如果我在这里遗漏了什么,请告诉我
根据 "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. 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.
根据您的要求,您可以将用户控件对象绑定到框架的 Content
。
private void LoadInitials()
{
SlideViews = new List<object>
{
new TopImageBottomTextControl(),
new TopImageBottomTextControl()
};
}
用法
<FlipView Name="SlideFlipView"
ItemsSource="{x:Bind SlideViews}"
SelectionChanged="SlideFlipView_SelectionChanged"
Background="AliceBlue">
<FlipView.ItemTemplate>
<DataTemplate>
<Frame Name="MenuDetailFram" Content="{Binding}" />
</DataTemplate>
</FlipView.ItemTemplate>
</FlipView>
以下没有数据模板的代码对我有用:
<FlipView Grid.Row="2"
Name="SlideFlipView"
ItemsSource="{x:Bind SlideViews}"
SelectionChanged="SlideFlipView_SelectionChanged"
Background="AliceBlue">
</FlipView>
Class 中 slideviews 对象的初始化看起来像
private void LoadInitials()
{
SlideViews = new List<object>
{
new UserControl1(),
new UserControl2()
};
}
我打算实现用户控件的水平列表,我想在运行期间将其添加到翻转视图中,我尝试了以下代码:
<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 看起来像下面的代码:
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)
};
}
}
但是当我运行程序时,用户控件没有出现在翻盖中。如果我在这里遗漏了什么,请告诉我
根据 "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. 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.
根据您的要求,您可以将用户控件对象绑定到框架的 Content
。
private void LoadInitials()
{
SlideViews = new List<object>
{
new TopImageBottomTextControl(),
new TopImageBottomTextControl()
};
}
用法
<FlipView Name="SlideFlipView"
ItemsSource="{x:Bind SlideViews}"
SelectionChanged="SlideFlipView_SelectionChanged"
Background="AliceBlue">
<FlipView.ItemTemplate>
<DataTemplate>
<Frame Name="MenuDetailFram" Content="{Binding}" />
</DataTemplate>
</FlipView.ItemTemplate>
</FlipView>
以下没有数据模板的代码对我有用:
<FlipView Grid.Row="2"
Name="SlideFlipView"
ItemsSource="{x:Bind SlideViews}"
SelectionChanged="SlideFlipView_SelectionChanged"
Background="AliceBlue">
</FlipView>
Class 中 slideviews 对象的初始化看起来像
private void LoadInitials()
{
SlideViews = new List<object>
{
new UserControl1(),
new UserControl2()
};
}