none
Change FlipView's "SelectedIndex" trigger "OnSelectionChanged" event twice. RRS feed

  • 问题

  • I want to dynamically change flipview's source and direct to the new item when it has created.

    But after I add the new item into flipview's items, and set the SelectedIndex = items.count - 1,

    SelectionChanged event was triggered twice,

    first time, SelectedIndex is the correct value,

    second time, SelectedIndex change to the correct 's previous Item.

    BlankPage1 page = new BlankPage1();

    FlipViewItem flpitem = new FlipViewItem();

    Appflipview.Items.Add(flpitem);

    Appflipview.Items.Add(page);

    Appflipview.SelectedIndex = 1;

    but the end i found SelectedIndex = 0.

    What's the problem.

    2013年11月1日 8:11

全部回复

  • Hi, KoVist

    When I test the project, I found there is no problem in it. When you add a new item in the FlipView .The Flipview’s default selectIndex equals to zero. But when you set the Flipview’s selectIndex to one, the FlipView can display the one item.

    Best Wishes!


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey. Thanks<br/> MSDN Community Support<br/> <br/> Please remember to &quot;Mark as Answer&quot; the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    2013年11月4日 2:53
    版主
  • Thank you for your answer,

    I debug my project by Simulator,

    found when I clik button, flipview selectedchanged currect,

    but tapped is error.

    My project is as follows:

    MainPage.xaml

        <Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
            <FlipView x:Name="FlipViewControl" Width="500" Height="500"
             SelectionChanged="FlipViewControl_SelectionChanged"></FlipView>
        </Grid>

    MainPage.xaml.cs

    public sealed partial class MainPage : Page { public MainPage() { this.InitializeComponent(); FlipViewInstanceClass.FlipViewInstance = this.FlipViewControl; this.FlipViewControl.Items.Add(new MyUserControl1()); }

    private void FlipViewControl_SelectionChanged(object sender, SelectionChangedEventArgs e) { FlipView fp = sender as FlipView; fp.SelectedIndex.ToString(); } }

    FlipViewInstance.cs

        public class FlipViewInstanceClass
        {
            public static FlipView FlipViewInstance
            {
                get
                {
                    return flipViewInstance;
                }
                set 
                {
                    flipViewInstance = value;
                }
            }
    
            private static FlipView flipViewInstance;
        }

    MyUserControl1.xaml

        <StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
            <Button Click="Button_Click" Width="200" Height="60" FontSize="35"> click </Button>
            <TextBlock FontSize="50" Text=" Control1"></TextBlock>
        </StackPanel>

    MuUserControl1.xaml.cs

    public sealed partial class MyUserControl1 : UserControl { public MyUserControl1() { this.InitializeComponent(); } private void Button_Click(object sender, RoutedEventArgs e) { FlipViewInstanceClass.FlipViewInstance.Items.Add(new MyUserControl2()); FlipViewInstanceClass.FlipViewInstance.SelectedIndex = FlipViewInstanceClass.FlipViewInstance.Items.Count - 1; }

    }

    MyUserControl2.xmal

      <StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
            <Button Click="Button_Click" Width="200" Height="60" FontSize="35">click</Button>
            <TextBlock FontSize="50" Text=" Control2 "></TextBlock>
        </StackPanel>

    MyUserControl2.xmal.cs

        public sealed partial class MyUserControl2 : UserControl
        {
            public MyUserControl2()
            {
                this.InitializeComponent();
            }
    
            private void Button_Click(object sender, RoutedEventArgs e)
            {
                FlipViewInstanceClass.FlipViewInstance.Items.Add(new MyUserControl3());
                FlipViewInstanceClass.FlipViewInstance.SelectedIndex = FlipViewInstanceClass.FlipViewInstance.Items.Count - 1;
            }
        }


    MyUserControl3.xmal

        <StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
            <Button Click="Button_Click" Width="200" Height="60" FontSize="35">click</Button>
            <TextBlock FontSize="50" Text=" Control3"></TextBlock>
        </StackPanel>


    MyUserControl3.xmal.cs

    public sealed partial class MyUserControl3 : UserControl { public MyUserControl3() { this.InitializeComponent(); } private void Button_Click(object sender, RoutedEventArgs e) { FlipViewInstanceClass.FlipViewInstance.Items.Add(new MyUserControl1()); FlipViewInstanceClass.FlipViewInstance.SelectedIndex = FlipViewInstanceClass.FlipViewInstance.Items.Count - 1; } }

    PS:

    I think this problem is the same as my question one.

    the question one:

    BlankPage1 page = new BlankPage1();
    
    FlipViewItem flpitem = new FlipViewItem();
    
    Appflipview.Items.Add(flpitem);
    
    Appflipview.Items.Add(page);
    
    Appflipview.SelectedIndex = 1;

    the "BlankPage1" has many controls,

    thoes controls binding content come from internet.








    2013年11月5日 7:09
  • Hi,

    I test your project in Simulator. I found whenever you click or tap the button, the result are same!For example, when you click the Button control in MyuserControl1, you can add the MyuserControl2 to FlipView and the FlipView display MyuserControl2, because you set the FlipView selectIndex in MyuserControl1. Also, when you tap the button in MyuserControl3, you add a new MyuserControl1 to FlipView. At the time, the FlipView Contain 4 items in it and you set the FlipView selectIndex to the new MyuserControl1’s index.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey. Thanks<br/> MSDN Community Support<br/> <br/> Please remember to &quot;Mark as Answer&quot; the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    2013年11月5日 7:46
    版主
  • My project build by VS2013 for windows store app.

    Is the same project?

    2013年11月6日 1:35
  • Hi,

    I test your project in VS2013!


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey. Thanks<br/> MSDN Community Support<br/> <br/> Please remember to &quot;Mark as Answer&quot; the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    2013年11月6日 1:38
    版主
  • Hello Anne Jing,

    Maybe the project have some diffrents between us.

    can i send my project to you by mail?

    thank you very much.


    Mail:dazen_3150@163.com
    • 已编辑 KoVist 2013年11月7日 8:44
    2013年11月7日 8:19