예제 #1
0
        public MainPage()
        {

            this.InitializeComponent();
            sn = new SearchNames { N1 = "", N2 = "" };
            ContentPanel.DataContext = sn;
            //_shakeDecetor = new ShakeDetector();
            //_shakeDecetor.ShakeEvent += _shakeDecetor_ShakeEvent;
            //_shakeDecetor.Start();
            SettingsPane.GetForCurrentView().CommandsRequested += MainPage_CommandsRequested;
        }
예제 #2
0
        async void _shakeDecetor_ShakeEvent(object sender, EventArgs e)
        {
            var res = new List<string>();

            var cp = new ContactPicker();
            var contacts = await cp.PickMultipleContactsAsync();
            if (contacts != null && contacts.Count > 0)
            {
                res.AddRange(contacts.Select(contactInformation => contactInformation.Name));
            }

            if (res.Count < 2)
            {
                Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => new MessageDialog("Not enough contacts.").ShowAsync());
            }
            else
            {
                var ran = new Random();
                var r1 = ran.Next(0, res.Count);
                var r2 = r1;
                while (r1 == r2)
                {
                    r2 = ran.Next(0, res.Count);
                }

                // App.Current.Resources.Remove("N1");
                // App.Current.Resources.Add("N1",res[r1].DisplayName);
                Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    sn = new SearchNames { N1 = res[r1], N2 = res[r2] };
                    ContentPanel.DataContext = sn;
                });
            }
        }