[英]How to check that which item is selected currently in Flip view in XAML C#
How can i check that which item of the flipview is currently selected and i want different action in code behind. 我如何检查当前是否选中了活动挂图的哪个项目,并且我想在后面的代码中执行其他操作。
here is the code 这是代码
<FlipView SelectionChanged="FlipView_SelectionChanged">
<Stackpanel Name="sp1">
// Stack panel 1
</Stackpanel>
<Stackpanel Name="sp2">
// Stack panel 2
</Stackpanel>
</FlipView>
My question is how i know that "sp1" is selected currently or "sp2" is selected in code behing? 我的问题是我如何知道当前在代码行为中选择了“ sp1”或“ sp2”? any event or other method? 任何事件或其他方法? or in other words who can i know that user flipped from one view to the next view 或者换句话说,我能知道那个用户从一个视图切换到了另一个视图
Any response will be highly appreciated. 任何回应将不胜感激。
Give the FlipView a Name then you can reference the SelectedItem 给FlipView命名,然后可以引用SelectedItem
XAML XAML
<FlipView Name="myFlipView" SelectionChanged="FlipView_SelectionChanged">
<Stackpanel Name="sp1">
// Stack panel 1
</Stackpanel>
<Stackpanel Name="sp2">
// Stack panel 2
</Stackpanel>
</FlipView>
C# C#
// get selected index/item
StackPanel sp = (StackPanel) myFlipView.SelectedItem;
int selected_index = myFlipView.SelectedIndex;
string name_of_selected_panel = sp.Name;
// set selected index/item
myFlipView.SelectedIndex = 1; // any valid index
myFlipView.SelectedItem = sp1; // or any name of an item in the collection
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.