Пример #1
0
        private async void SetParkingLotListSelectionVisualState(ParkingLot selectedItem = null)
        {
            if (selectedItem == null)
            {
                selectedItem = Vm.SelectedParkingLot;
            }
            if (selectedItem != null)
            {
                ListViewItem listViewItem = null;
                var          count        = 0;
                while (listViewItem == null && count < 10)
                {
                    var itemContainer = ParkingLotList.ContainerFromItem(selectedItem);
                    listViewItem = itemContainer as ListViewItem;
                    await Task.Delay(200);

                    count++;
                }

                if (listViewItem != null)
                {
                    Debug.WriteLine("[MainView] parking lot list: set selected visual state for " + selectedItem.Name);
                    VisualStateManager.GoToState(listViewItem.ContentTemplateRoot as Control, "Selected", false);
                }
                else
                {
                    Debug.WriteLine("[MainVm] parking lot list: list view item is null :/");
                }

                ParkingLotList.ScrollIntoView(selectedItem);
            }
            else
            {
                Debug.WriteLine("[MainView] parking lot list: set selected index to -1");
                ParkingLotList.SelectedIndex = -1;
            }
        }
Пример #2
0
        public MainPage()
        {
            InitializeComponent();

            if (ResponsiveStateGroup.CurrentState == desktopViewVisualState)
            {
                //this should use "-1 * CoreApplication.GetCurrentView().TitleBar.Height" but it returns 0 at this point :(
                SetMapBottomMargin(-32);
            }

            NavigationCacheMode = NavigationCacheMode.Required;

            CoreApplication.GetCurrentView().TitleBar.ExtendViewIntoTitleBar = true;

            Map.Loaded += async(sender, args) =>
            {
                SetMapBottomMargin(0);

                Debug.WriteLine("[MainView] map: map loaded");
                if (_initialMapBbox != null)
                {
                    Debug.WriteLine("[MainView] map: map loaded, set initial bounds");
                    await Map.TrySetViewBoundsAsync(_initialMapBbox, null, MapAnimationKind.None);

                    _zoomedToInitialView = true;
                }
                else if (_initialCoordinates != null)
                {
                    Debug.WriteLine("[MainView] map: map loaded, set initial coords");
                    await Map.TrySetViewAsync(_initialCoordinates, null, null, null, MapAnimationKind.None);

                    _zoomedToInitialView = true;
                }
                _mapLoaded = true;
            };

            Messenger.Default.Register(this, (ZoomMapToBoundsMessage msg) =>
            {
                if (!_mapLoaded)
                {
                    _initialMapBbox = msg.BoundingBox;
                    //set initial bbox as the following won't work while splash screen is still visible
                }
                else
                {
                    DispatcherHelper.CheckBeginInvokeOnUI(async() =>
                    {
                        Debug.WriteLine("[MainView] map: zoom map to bounds msg");
                        await Map.TrySetViewBoundsAsync(msg.BoundingBox, null, MapAnimationKind.Bow);
                        _zoomedToInitialView = _mapLoaded;
                    });
                }
            });

            Messenger.Default.Register(this, (ZoomMapToCoordinateMessage msg) =>
            {
                if (!_mapLoaded)
                {
                    _initialCoordinates = msg.Point;
                    //set initial coordinates as the following won't work while splash screen is still visible
                }
                else
                {
                    DispatcherHelper.CheckBeginInvokeOnUI(async() =>
                    {
                        Debug.WriteLine("[MainView] map: zoom map to coordinates msg");
                        await
                        Map.TrySetViewAsync(msg.Point, null, null, null, MapAnimationKind.Bow);
                        _zoomedToInitialView = _mapLoaded;
                    });
                }
            });

            Messenger.Default.Register(this, (ShowSearchResultOnMapMessage msg) =>
            {
                DispatcherHelper.CheckBeginInvokeOnUI(async() =>
                {
                    DrawingService.DrawSearchResult(Map, msg.Result);
                    Debug.WriteLine("[MainView] map: show search result - wait until initial view was zoomed to");
                    await WaitForInitialMapZoom();
                    Debug.WriteLine("[MainView] map: show search result");
                    await Map.TrySetViewAsync(msg.Result.Point, null, null, null, MapAnimationKind.Bow);
                });
            });

            Messenger.Default.Register(this, (HideSearchResultOnMapMessage msg) =>
            {
                DrawingService.RemoveSearchResult(Map);
            });

            Messenger.Default.Register(this, (InfoDialogToggleVisibilityMessage msg) =>
            {
                FindName(nameof(InfoDialog));
                _infoDialogVisible    = msg.IsVisible;
                InfoDialog.Visibility = msg.Visibility;
            });

            Messenger.Default.Register(this, async(UpdateParkingLotListSelectionMessage msg) =>
            {
                Debug.WriteLine("[MainView] update parking lot list: message received");
                SetParkingLotListSelectionVisualState();
            });

            Vm.PropertyChanged += OnViewModelPropertyChanged;

            ParkingLotList.SelectionChanged += (sender, args) =>
            {
                try
                {
                    ParkingLotList.ScrollIntoView(ParkingLotList.SelectedItem);
                }
                catch (Exception)
                {
                    Debug.WriteLine("Cannot scroll currenct parking lot list item...");
                }
            };

            Map.MapElementClick += (sender, args) =>
            {
                Vm.SelectedParkingLot = DrawingService.GetParkingLotOfIcon(args.MapElements.GetTopmostIcon());
            };

            SystemNavigationManager.GetForCurrentView().BackRequested += (sender, args) =>
            {
                if (_infoDialogVisible)
                {
                    Messenger.Default.Send(new InfoDialogToggleVisibilityMessage(false));
                    args.Handled = true;
                }
            };

            UpdateParkingLotFilter();
        }