Inheritance: Windows.UI.Xaml.Controls.Primitives.Selector, IListBox
Esempio n. 1
0
 public SelectedItemsBehavior(ListBox listBox, IList boundList)
 {
     _boundList = boundList;
     _listBox = listBox;
     _listBox.Loaded += ListBox_Loaded;
     AddCollectionChangedHandler();
 }
        public async Task ActivatingTheViewShouldUpdateTheSelectedItem()
        {
            await ExecuteOnUIThread(() =>
                {
                    var selector = new ListBox();
                    var view1 = new object();
                    var view2 = new object();

                    IRegionAdapter adapter = new SelectorRegionAdapter(null);

                    var region = adapter.Initialize(selector, "Region1");
                    region.Add(view1);
                    region.Add(view2);

                    Assert.AreNotEqual(view1, selector.SelectedItem);

                    region.Activate(view1);

                    Assert.AreEqual(view1, selector.SelectedItem);

                    region.Activate(view2);

                    Assert.AreEqual(view2, selector.SelectedItem);
                });
        }
        public async Task AdapterDoesNotPreventRegionFromBeingGarbageCollected()
        {
            await ExecuteOnUIThread(() =>
                {
                    var selector = new ListBox();
                    object model = new object();
                    IRegionAdapter adapter = new SelectorRegionAdapter(null);

                    var region = adapter.Initialize(selector, "Region1");
                    region.Add(model);

                    WeakReference regionWeakReference = new WeakReference(region);
                    WeakReference controlWeakReference = new WeakReference(selector);
                    Assert.IsTrue(regionWeakReference.IsAlive);
                    Assert.IsTrue(controlWeakReference.IsAlive);

                    region = null;
                    selector = null;
                    GC.Collect();
                    GC.Collect();

                    Assert.IsFalse(regionWeakReference.IsAlive);
                    Assert.IsFalse(controlWeakReference.IsAlive);
                });
        }
Esempio n. 4
0
 // XAML elements inside the HubSection are template-based and cannot be directly access, hook the ListBox instance here
 private void ServiceListLoaded(object sender, RoutedEventArgs e)
 {
     if (sender != null)
     {
         _serviceListBox = (ListBox)sender;
     }
 }
        protected override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            this.tb = GetTemplateChild("tbChild") as WatermarkTextBox;
            this.lb = GetTemplateChild("lbChild") as ListBox;

            this.g = GetTemplateChild("spContainer") as Grid;

            if (tb != null && this.lb != null)
            {
                //tb.TextChanged += tb_TextChanged;
                if (Windows.ApplicationModel.DesignMode.DesignModeEnabled) return;
                var keys = Observable.FromEventPattern<KeyRoutedEventArgs>(tb, "KeyUp").Throttle(TimeSpan.FromSeconds(0.5), CoreDispatcherScheduler.Current);
                keys.Subscribe(evt =>
                {
                    if (evt.EventArgs.Key == Windows.System.VirtualKey.Enter)
                    {
                        HideAndSelectFirst();                        
                        return;
                    }

                    if (!isShowing) return;

                    this.lb.SelectionChanged -= lb_SelectionChanged;

                    this.lb.Visibility = Windows.UI.Xaml.Visibility.Collapsed;

                    if (String.IsNullOrWhiteSpace(this.tb.Text) || this.ItemsSource == null || this.ItemsSource.Count == 0)
                        return;

                    //var sel = (from d in this.ItemsSource where d.ToLower().RemoveDiacritics().StartsWith(this.tb.Text.ToLower().RemoveDiacritics()) select d);
                    var sel = (from d in this.ItemsSource where SearchFunction(d,this.tb.Text) select d);

                    if (sel != null && sel.Count() > 0)
                    {
                        this.lb.ItemsSource = sel;
                        this.lb.Visibility = Windows.UI.Xaml.Visibility.Visible;

                        this.lb.SelectionChanged += lb_SelectionChanged;
                    }
                });

                tb.LostFocus += (s, e) =>
                {
                    HideAndSelectFirst();
                };
                tb.GotFocus += (s, e) =>
                {
                    isShowing = true;
                };
                
            }

            if (this.ItemsSource != null)
                this.lb.ItemsSource = ItemsSource;

            this.g.MaxHeight = this.MaxHeight;
        }
Esempio n. 6
0
 public SearchBar(TextBox searchControl, ListBox resultSearchControl, SongTextControl songTextControl, ListBox listArtistsControl)
 {
     this.searchControl = searchControl;
     this.resultSearchControl = resultSearchControl;
     this.songTextControl = songTextControl;
     this.listArtistsControl = listArtistsControl;
     searchControl.TextChanged += searchControl_TextChanged;
     resultSearchControl.SelectionChanged += ResultSearchControl_SelectionChanged;
 }
        protected override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            popup = GetTemplateChild("Popup") as Popup;
            text = GetTemplateChild("Value") as TextBox;
            list = GetTemplateChild("Options") as ListBox;

            VisualStateManager.GoToState(this, "Normal", false);
        }
        public void InitializeComponent()
        {
            if (_contentLoaded)
                return;

            _contentLoaded = true;
            Application.LoadComponent(this, new System.Uri("ms-appx:///LineStatusControl.xaml"), Windows.UI.Xaml.Controls.Primitives.ComponentResourceLocation.Application);
 
            lineStatusesListView = (Windows.UI.Xaml.Controls.ListBox)this.FindName("lineStatusesListView");
        }
 public ListTelemetryPage()
 {
     //this.OnNavigatedTo += OnNavigatedTo;
     this.NavigationCacheMode =
         Windows.UI.Xaml.Navigation.NavigationCacheMode.Required;
     this.InitializeComponent();
     Globals.LTP = this;
     ListItems = this.listItems;
     TelemetryAPI.SetListTelemetryPage(this);
 }
        public void InitializeComponent()
        {
            if (_contentLoaded)
                return;

            _contentLoaded = true;
            Application.LoadComponent(this, new System.Uri("ms-appx:///MainPage.xaml"), Windows.UI.Xaml.Controls.Primitives.ComponentResourceLocation.Application);
 
            ListPerson = (Windows.UI.Xaml.Controls.ListBox)this.FindName("ListPerson");
            ContactLst = (Windows.UI.Xaml.Controls.Grid)this.FindName("ContactLst");
        }
Esempio n. 11
0
 public void RestoreState(AppState state, SongTextControl songTextControl, ListBox listArtistsControl)
 {
     listArtistsControl.Visibility = state.ListArtistsControlVisible;
     songTextControl.Visibility = state.SongTextControlVisible;
     songTextControl.SetStackPanel(state.SongTextControlStack);
     ((ObservableCollection<MusicItem>)listArtistsControl.ItemsSource).Clear();
     foreach (MusicItem item in state.ListArtistsControlItems)
     {
         ((ObservableCollection<MusicItem>)listArtistsControl.ItemsSource).Add(item);
     }
 }
        /// <summary>
        /// Constructor: Initialize and hook up Device Watcher events
        /// </summary>
        /// <param name="midiSelectorString">MIDI Device Selector</param>
        /// <param name="dispatcher">CoreDispatcher instance, to update UI thread</param>
        /// <param name="portListBox">The UI element to update with list of devices</param>
        internal MidiDeviceWatcher(string midiSelectorString, CoreDispatcher dispatcher, ListBox portListBox)
        {
            this.deviceWatcher = DeviceInformation.CreateWatcher(midiSelectorString);
            this.portList = portListBox;
            this.midiSelector = midiSelectorString;
            this.coreDispatcher = dispatcher;

            this.deviceWatcher.Added += DeviceWatcher_Added;
            this.deviceWatcher.Removed += DeviceWatcher_Removed;
            this.deviceWatcher.Updated += DeviceWatcher_Updated;
            this.deviceWatcher.EnumerationCompleted += DeviceWatcher_EnumerationCompleted;
        }
        public void InitializeComponent()
        {
            if (_contentLoaded)
            {
                return;
            }

            _contentLoaded = true;
            Application.LoadComponent(this, new System.Uri("ms-appx:///MainPage.xaml"), Windows.UI.Xaml.Controls.Primitives.ComponentResourceLocation.Application);

            ListPerson = (Windows.UI.Xaml.Controls.ListBox) this.FindName("ListPerson");
            ContactLst = (Windows.UI.Xaml.Controls.Grid) this.FindName("ContactLst");
        }
        public LauncherListPage()
        {
            InitializeComponent();

            View = new ListBox();
            View.Background = new SolidColorBrush(Windows.UI.Color.FromArgb(255, 240, 240, 240));
            View.Padding = new Thickness(0, 20, 0, 0);
            View.ItemsSource = Samples.List;
            View.ItemTemplate = (DataTemplate)Resources["ListItemTemplate"];
            View.SelectionChanged += OnListItemClick;

            Window.Current.Content = View;
        }
        public async Task AdapterAddsSelectorItemsSourceSyncBehavior()
        {
            await ExecuteOnUIThread(() =>
                {
                    var control = new ListBox();
                    IRegionAdapter adapter = new TestableSelectorRegionAdapter();

                    IRegion region = adapter.Initialize(control, "Region1");
                    Assert.IsNotNull(region);

                    Assert.IsInstanceOfType(region.Behaviors["SelectorItemsSourceSyncBehavior"], typeof(SelectorItemsSourceSyncBehavior));
                });
        }
Esempio n. 16
0
        private static SelectedItemsBehavior GetOrCreateBehavior(ListBox target, IList list)
        {
            var behavior = target.GetValue(SelectedItemsBehaviorProperty) as SelectedItemsBehavior;
            if (behavior == null)
            {
                behavior = new SelectedItemsBehavior(target, list);
                target.SetValue(SelectedItemsBehaviorProperty, behavior);
            }
            else
            {
                behavior.SetNewList(list);
            }

            return behavior;
        }
Esempio n. 17
0
        public void SaveState(SongTextControl songTextControl, ListBox listArtistsControl)
        {
            var state = new AppState
            {
                ListArtistsControlItems = new ObservableCollection<MusicItem>(),
            };

            state.ListArtistsControlVisible = listArtistsControl.Visibility;
            state.SongTextControlVisible = songTextControl.Visibility;
            state.SongTextControlStack = songTextControl.GetStackPanel();

            foreach (MusicItem item in (ObservableCollection<MusicItem>)listArtistsControl.ItemsSource)
            {
                state.ListArtistsControlItems.Add(item);
            }
        }
        // Initializes the given portal and populates UI
        private async Task InitializePortalAsync(string portalUrl)
        {
            try
            {
                var portal = await ArcGISPortal.CreateAsync(new Uri(portalUrl));

                ArcGISPortalInfo portalInfo = portal.ArcGISPortalInfo;
                if (portalInfo == null)
                {
					var _ = new MessageDialog("Portal Information could not be retrieved").ShowAsync();
                    return;
                }

                PropertiesListBox.Items.Add(string.Format("Current Version: {0}", portal.CurrentVersion));
                PropertiesListBox.Items.Add(string.Format("Access: {0}", portalInfo.Access));
                PropertiesListBox.Items.Add(string.Format("Host Name: {0}", portalInfo.PortalHostname));
                PropertiesListBox.Items.Add(string.Format("Name: {0}", portalInfo.PortalName));
                PropertiesListBox.Items.Add(string.Format("Mode: {0}", portalInfo.PortalMode));

                Basemap basemap = portalInfo.DefaultBasemap;

                PropertiesListBox.Items.Add(string.Format("Default BaseMap Title: {0}", basemap.Title));
                PropertiesListBox.Items.Add(string.Format("WebMap Layers ({0}):", basemap.Layers.Count));

                foreach (WebMapLayer webmapLayer in basemap.Layers)
                {
                    PropertiesListBox.Items.Add(webmapLayer.Url);
                }

                var portalgroup = await portalInfo.GetFeaturedGroupsAsync();
                PropertiesListBox.Items.Add("Groups:");

                ListBox listGroups = new ListBox();
                listGroups.ItemTemplate = LayoutRoot.Resources["PortalGroupTemplate"] as DataTemplate;
                listGroups.ItemsSource = portalgroup;
                PropertiesListBox.Items.Add(listGroups);

                var result = await portalInfo.SearchFeaturedItemsAsync(new SearchParameters() { Limit = 15 });
                FeaturedMapsList.ItemsSource = result.Results;
            }
            catch (Exception ex)
            {
				var _ = new MessageDialog("Failed to initialize" + ex.Message, "Sample Error").ShowAsync();
            }
        }
Esempio n. 19
0
        protected async override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            _listBox = (ListBox)GetTemplateChild(ListBoxElement);

            if (_listBox != null)
            {
                if (DesignMode.DesignModeEnabled)
                {
                    DataAccess<MapLocationFolderModel> dataAccess = new DataAccess<MapLocationFolderModel>();

                    _listBox.ItemsSource = await dataAccess.GetSources(DataSourceType.Design);
                }

                _listBox.SelectionChanged += ListBoxSelectionChanged;
            }
        }
        protected override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            this.tb = GetTemplateChild("tbChild") as TextBox;
            this.lb = GetTemplateChild("lbChild") as ListBox;

            this.g = GetTemplateChild("spContainer") as Grid;

            if (tb != null && this.lb != null)
            {
                tb.TextChanged += tb_TextChanged;
            }

            if (this.ItemsSource != null)
                this.lb.ItemsSource = ItemsSource;

            this.g.MaxHeight = this.MaxHeight;
        }
Esempio n. 21
0
        public MusicItemsViewer(ListBox listArtistsControl, SongTextControl songTextControl, SearchBar searchBar)
        {
            this.listArtistsControl = listArtistsControl;
            ObservableCollection<MusicItem> tmpCollection = new ObservableCollection<MusicItem>();
            List<Artist> artists = FileManager.Artists.ToList();
            List<MusicItem> musicItems = new List<MusicItem>();
            foreach (var artist in artists)
            {
                musicItems.Add(artist);
            }
            foreach (MusicItem musicItem in musicItems)
                tmpCollection.Add(musicItem);

            this.listArtistsControl.ItemsSource = tmpCollection;
            this.songTextControl = songTextControl;
            this.searchBar = searchBar;
            searchBar.SelectionChanged += SelectionChanged;
            searchBar.ArtistChanged += ArtistChanged;
            listArtistsControl.SelectionChanged += MusicItemChange;
        }
 public ListBoxBindableSelectionHandler(
     ListBox listBox, dynamic boundSelection)
 {
     _handler = OnBoundSelectionChanged;
     Attach(listBox, boundSelection);
 }
        // Display statistics for the test such as test time, errors, left-right analysis
        private void viewStatistics()
        {
            // Grab all node completions
            List<NodeCompletion> completions = testReplay.getCompletions();

            // Grab all test errors
            List<TestError> errors = testReplay.getErrors();

            // If completions do not exist for this file, return right away.
            // Otherwise it will crash
            if(completions.Count < 25)
            {
                return;
            }

            // Start with a clean screen
            removeAllStrokes();

            createTime();
            createErrors();

            // Add a Textarea for time taken between nodes
            #region paths
            ListBox nodes = new ListBox();
            nodes.Margin = new Thickness(400, 100, 0,0);
            nodes.Height = 575;
            nodes.Width = 300;
            nodes.FontSize = 17;

            if (passer.trailsTestVersion == 'A')
            {
                for(int i = 1; i < 25; i++)
                {
                    string s = "";
                    s += i.ToString();
                    s += "   ->   ";
                    s += (i+1).ToString();
                    s += "   =   ";
                    
                    
                    // Calculate how much time between each completion
                    DateTime end = completions[i].getTime();
                    DateTime begin = completions[i - 1].getTime();
                    TimeSpan span = end-begin;
                    Double time =  (span.Milliseconds / 100.0) + span.Seconds;
                    s += time.ToString();
                    s += "   seconds";
                    nodes.Items.Add(s);
                }
            }
            else if (passer.trailsTestVersion == 'B')
            {
                int num = 1;
                char let = 'A';
                for (int i = 1; i < 25; i++)
                {
                    DateTime end = completions[i].getTime();
                    DateTime begin = completions[i - 1].getTime();
                    TimeSpan span = end - begin;
                    if(i % 2 == 1)
                    {
                        string s = num.ToString() + "   ->   " + ((char)(let)).ToString();
                        Double time = (span.Milliseconds / 100.0) + span.Seconds;
                        s += "   =   ";
                        s += time.ToString();
                        s += "   seconds";
                        nodes.Items.Add(s);
                        num += 1;
                    }
                    else
                    {
                        string s = let.ToString() + "   ->   " + (num).ToString();
                        Double time = (span.Milliseconds / 100.0) + span.Seconds;
                        s += "   =   ";
                        s += time.ToString();
                        s += "   seconds";
                        nodes.Items.Add(s);
                        let = (char)(1+let);
                    }
                }
            }
            MyCanvas.Children.Add(nodes);
            #endregion

            // Add a Textarea for the test errors
            #region errors
            ListBox ers = new ListBox();
            ers.Margin = new Thickness(750, 100, 0, 0);
            ers.Height = 575;
            ers.Width = 300;
            ers.FontSize = 17;

            TextBlock errTxt = new TextBlock();
            errTxt.Margin = new Thickness(750, 75, 0, 0);
            errTxt.FontSize = 17;
            errTxt.Text = "Errors";

            for (int i = 0; i < errors.Count; i++ )
            {
                ers.Items.Add(errors[i].getBegin().getNodeText() + "      To     " + errors[i].getActualEnd().getNodeText());
            }
            MyCanvas.Children.Add(errTxt);
            MyCanvas.Children.Add(ers);
            #endregion
        }
Esempio n. 24
0
 public void RegisterUiItem(object l)
 {
     this.lb = (ListBox)l;
 }
Esempio n. 25
0
        private void LayoutDesign()
        {
            TextBoxes = new Dictionary<string, TextBox>();
            ArduinoLCDMenu = new string[0];
            buttonSwitchStatement = "     switch (command) \r\n     {\r\n";

            #if GENERATE_ALL_NON_MENUS_UI
            StackPanel VButtonsStackPanel = new StackPanel();
            VButtonsStackPanel.Margin = new Thickness(2);
            VButtonsStackPanel.Orientation = Orientation.Vertical;
            VButtonsStackPanel.HorizontalAlignment = HorizontalAlignment.Left;
            LayoutRoot.Children.Add(VButtonsStackPanel);

            Grid.SetColumn(VButtonsStackPanel, 1);
            Grid.SetRow(VButtonsStackPanel, 1);

            TextBlock DeptListHeading = new TextBlock();
            DeptListHeading.Text = "Commands";
            VButtonsStackPanel.Children.Add(DeptListHeading);

            Button ShowSerial = new Button();
            ShowSerial.Content = "Set up Serial";
            ShowSerial.Click += navButton_Click;
            VButtonsStackPanel.Children.Add(ShowSerial);

            //Create StackPanel for buttons
            StackPanel VButtonsStackPanel2 = new StackPanel();
            VButtonsStackPanel.Margin = new Thickness(2);
            VButtonsStackPanel.Orientation = Orientation.Vertical;
            VButtonsStackPanel.HorizontalAlignment = HorizontalAlignment.Left;
            VButtonsStackPanel.Children.Add(VButtonsStackPanel2);
            #endif
            // Add buttons etc to UI
            int numRows = 1 + Commands.MaxIdTag.Row;
            for (int row = 0; row < numRows; row++)
            {
                Array.Resize(ref ArduinoLCDMenu, ArduinoLCDMenu.Length + 1);
                ArduinoLCDMenu[ArduinoLCDMenu.Length - 1] = "";
                StackPanel ButtonsStackPanel = new StackPanel();
                ButtonsStackPanel.Margin = new Thickness(2);
                ButtonsStackPanel.Orientation = Orientation.Horizontal;
                ButtonsStackPanel.HorizontalAlignment = HorizontalAlignment.Left;

                VButtonsStackPanel2.Children.Add(ButtonsStackPanel);
                int numButtons = 1 + Commands.MaxIdTag.Col;

                for (int column = 0; column < numButtons; column++)
                {

                    Commands cmd = Commands.GetCommand("MainMenu", column, row);
                    if (cmd == null)
                        continue;
                    if (cmd.name[0] == Commands.ElementConfigCh["cTextBlockPrefix"])
                    {
                        //Is a TextBlock
                        TextBlock textBlock = new TextBlock();
                        textBlock.Text = cmd.name.Substring(1);
                        textBlock.Tag = cmd.idTag;

                        textBlock.HorizontalAlignment = HorizontalAlignment.Left;
                        textBlock.VerticalAlignment = VerticalAlignment.Center;
                        textBlock.TextAlignment = TextAlignment.Right;
                        ArduinoLCDMenu[ArduinoLCDMenu.Length - 1] += " " + cmd.name.Substring(1) + " ";
                        textBlock.Width = Commands.ElementConfigInt["iTextBlockWidth"];
                        textBlock.Height = Commands.ElementConfigInt["iHeight"];
                        ButtonsStackPanel.Children.Add(textBlock);
                        textBlock.Margin = new Thickness(Commands.ElementConfigInt["iMargin"]);
                    }
                    else if (cmd.name[0] == Commands.ElementConfigCh["cTextBoxPrefix"])
                    {
                        //Is a TextBlock
                        TextBox textBox = new TextBox();
                        textBox.Text = cmd.name.Substring(1);
                        textBox.Tag = cmd.idTag;
                        textBox.Name = "textBox" + textBox.Text.Replace(" ", "_");
                        textBox.HorizontalAlignment = HorizontalAlignment.Left;
                        textBox.VerticalAlignment = VerticalAlignment.Center;
                        textBox.TextAlignment = TextAlignment.Right;
                        ArduinoLCDMenu[ArduinoLCDMenu.Length - 1] += " " + cmd.name.Substring(1) + " ";
                        textBox.Width = Commands.ElementConfigInt["iTextBoxWidth"];
                        textBox.Height = Commands.ElementConfigInt["iHeight"];
                        ButtonsStackPanel.Children.Add(textBox);
                        textBox.Margin = new Thickness(Commands.ElementConfigInt["iMargin"]);
                        TextBoxes.Add(textBox.Name, textBox);
                    }
                    else
                    {
                        Button button = new Button();
                        button.Content = cmd.name;
                        button.Name = cmd.name.Replace(" ", "_");
                        button.Tag = cmd.idTag;
                        ArduinoLCDMenu[ArduinoLCDMenu.Length - 1] += "[" + cmd.name + "] ";
                        buttonSwitchStatement += "        case \"" + cmd.name + "\":\r\n          break;\r\n\r\n";
                        button.Width = Commands.ElementConfigInt["iWidth"];
                        button.Height = Commands.ElementConfigInt["iHeight"];
                        ButtonsStackPanel.Children.Add(button);
                        button.Margin = new Thickness(Commands.ElementConfigInt["iMargin"]);
                        button.Click += Button_Click;
                    }
                }
            }

            #if GENERATE_ALL_NON_MENUS_UI
            TextBox textBoxSerial = new TextBox();
            textBoxSerial.Text = "";
            textBoxSerial.TextWrapping = TextWrapping.Wrap;
            textBoxSerial.AcceptsReturn = true;
            textBoxSerial.Width = 400;
            textBoxSerial.Name = "textBoxSerial";

            VButtonsStackPanel.Children.Add(TextBoxSerial);

            ListBox listItems = new ListBox();
            VButtonsStackPanel.Children.Add(listItems);

            #endif
            TextBoxSerial = textBoxSerial;
            //ListItems = listItems;

            buttonSwitchStatement += "        default:\r\n";
            buttonSwitchStatement += "          System.Diagnostics.Debug.WriteLine(\"Command: {0} not found\",command);\r\n";
            buttonSwitchStatement += "          break;\r\n }\r\n";
            System.Diagnostics.Debug.WriteLine(buttonSwitchStatement);
            //System.Diagnostics.Debug.WriteLine(buttonSwitchStatement);
            //Button CancelButton = new Button();
        }
Esempio n. 26
0
 internal void Detach()
 {
     _listBox.Unloaded -= OnListBoxUnloaded;
     _listBox.SelectionChanged -= OnListBoxSelectionChanged;
     _listBox = null;
     _boundSelection.CollectionChanged -= OnBoundSelectionChanged;
     _boundSelection = null;
 }
Esempio n. 27
0
 private void Attach(ListBox listBox, ObservableCollection<object> boundSelection)
 {
     _listBox = listBox;
     _listBox.Unloaded += OnListBoxUnloaded;
     _listBox.SelectionChanged += OnListBoxSelectionChanged;
     _listBox.SelectedItems.Clear();
     _boundSelection = boundSelection;
     _boundSelection.CollectionChanged += OnBoundSelectionChanged;
 }
Esempio n. 28
0
 public ListBoxBindableSelectionHandler(ListBox listBox, ObservableCollection<object> boundSelection)
 {
     Attach(listBox, boundSelection);
 }
        private void Attach(ListBox listBox, dynamic boundSelection)
        {
            _listBox = listBox;
            _listBox.Unloaded += OnListBoxUnloaded;
            _listBox.SelectionChanged += OnListBoxSelectionChanged;
            _listBox.SelectedItems.Clear();

            _boundSelection = boundSelection;

            var eventInfo =
                _boundSelection.GetType().GetDeclaredEvent("CollectionChanged");
            eventInfo.AddEventHandler(_boundSelection, _handler);
            //_boundSelection.CollectionChanged += OnBoundSelectionChanged;
        }
 internal void Detach()
 {
     _listBox.Unloaded -= OnListBoxUnloaded;
     _listBox.SelectionChanged -= OnListBoxSelectionChanged;
     _listBox = null;
     var eventInfo =
         _boundSelection.GetType().GetDeclaredEvent("CollectionChanged");
     eventInfo.RemoveEventHandler(_boundSelection, _handler);
     _boundSelection = null;
 }
        /// <summary>
        /// The methods provided in this section are simply used to allow
        /// NavigationHelper to respond to the page's navigation methods.
        /// <para>
        /// Page specific logic should be placed in event handlers for the  
        /// <see cref="NavigationHelper.LoadState"/>
        /// and <see cref="NavigationHelper.SaveState"/>.
        /// The navigation parameter is available in the LoadState method 
        /// in addition to page state preserved during an earlier session.
        /// </para>
        /// </summary>
        /// <param name="e">Provides data for navigation methods and event
        /// handlers that cannot cancel the navigation request.</param>
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            this.navigationHelper.OnNavigatedTo(e);
            //Dispatcher.Invoke(new Action(() => { }), DispatcherPriority.ContextIdle, null);
           
            string currentBusNumber = (from b in App.activeBus
                                   select b.FirstAttribute.Value).ToList()[0];
            string stopName = "";
            
            SolidColorBrush scb = new SolidColorBrush(Colors.Transparent);
            TextBlock tbHeader;

            ListBox listBox1 = new ListBox();
            listBox1.Background = scb;
            listBox1.ItemTemplate = Resources["stopsRepresentation"] as DataTemplate;
            listBox1.ItemContainerStyle = Resources["styleOfListBoxSO"] as Style;
            //listBox1.Tapped += listBox1_Tapped;

            //var xd = XDocument.Load("all.xml");
            //var bus = from el in xd.Descendants("Bus")
            //          where el.Attribute("lineNumber").Value == currentBusNumber
            //          select el;


            int stopsCount = App.activeBus.Descendants("Stops").Count();



            var listFromStart = App.activeBus.Descendants("Stops").Take(1).Elements("Stop").ToList();
            List<Stop> myList1 = new List<Stop>();

            for (int i = 0; i < listFromStart.Count; i++)
            {
                stopName = listFromStart[i].Attribute("stopName").Value;

                var aaaaa = listFromStart[i].Elements("C").ToList();
                List<string> tempList = new List<string>();

                foreach (var innerStop in aaaaa)
                {
                    tempList.Add(innerStop.Value);
                }

                if (i==0)
                    myList1.Add(new Stop(stopName, tempList, tempList.Count, -1));
                else if (i == listFromStart.Count - 1)
                    myList1.Add(new Stop(stopName, tempList, tempList.Count, 1));
                else
                    myList1.Add(new Stop(stopName, tempList, tempList.Count, 0));
                //myList1.Add(new Stop(stopName, tempList, tempList.Count));
            }


            listBox1.ItemsSource = myList1;
            listBox1.Tapped += listBox1_Tapped;
            currentBusNumber = App.ChangeEnglishLettersToGreek(currentBusNumber);
            if (stopsCount == 1)
            {
                tbHeader = new TextBlock { Text = "Κυκλική \"" + currentBusNumber + "\"", FontSize = 28 };
            }
            else
            {
                tbHeader = new TextBlock { Text = "Αφετηρία \"" + currentBusNumber + "\"", FontSize = 28 };
            }
            pivotStops.Items.Add(new PivotItem()
            {
                Name = "PivotItem1",
                Header = tbHeader,
                Content = listBox1
            });

            if (stopsCount == 2)
            {
                //currentBusNumber = (string)e.Parameter;
                ListBox listBox2 = new ListBox();
                listBox2.Background = scb;
                listBox2.ItemTemplate = Resources["stopsRepresentation"] as DataTemplate;
                listBox2.ItemContainerStyle = Resources["styleOfListBoxSO"] as Style;

                var listFromFinal = App.activeBus.Descendants("Stops").Reverse().Take(1).Elements("Stop").ToList();

                List<Stop> myList2 = new List<Stop>();

                for (int i = 0; i < listFromFinal.Count; i++ )
                {
                    stopName = listFromFinal[i].Attribute("stopName").Value;

                    var aaaaa = listFromFinal[i].Elements("C").ToList();
                    List<string> tempList = new List<string>();

                    foreach (var innerStop in aaaaa)
                    {
                        tempList.Add(innerStop.Value);
                    }

                    //myList2.Add(new Stop(stopName, tempList, tempList.Count, 0));

                    if (i == 0)
                        myList2.Add(new Stop(stopName, tempList, tempList.Count, -1));
                    else if (i == listFromFinal.Count - 1)
                        myList2.Add(new Stop(stopName, tempList, tempList.Count, 1));
                    else
                        myList2.Add(new Stop(stopName, tempList, tempList.Count, 0));
                }
                listBox2.ItemsSource = myList2;
                listBox2.Tapped += listBox1_Tapped;
                currentBusNumber = App.ChangeEnglishLettersToGreek(currentBusNumber);

                tbHeader = new TextBlock { Text = "Τέρμα \"" + currentBusNumber + "\"", FontSize = 28 };
                pivotStops.Items.Add(new PivotItem()
                {
                    Name = "PivotItem2",
                    Header = tbHeader,
                    Content = listBox2
                });
            }
            currentBusNumber = "";
        }