Exemplo n.º 1
0
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            PanelSideBarItems = Template.FindName("PART_PanelSideBarItems", this) as Panel;
            if (PanelSideBarItems != null)
            {
                LoadSidebarItems();
            }

            ElemMainMenu = Template.FindName("PART_ElemMainMenu", this) as FrameworkElement;
            if (ElemMainMenu != null)
            {
                LeftClickContextMenuBehavior.SetEnabled(ElemMainMenu, true);
                ElemMainMenu.ContextMenu = new MainMenu(mainModel)
                {
                    StaysOpen = false,
                    Placement = PlacementMode.Bottom
                };
                ElemMainMenu.ContextMenu.SetResourceReference(ContextMenu.StyleProperty, "TopPanelMenu");
                BindingTools.SetBinding(ElemMainMenu,
                                        FrameworkElement.VisibilityProperty,
                                        mainModel.AppSettings,
                                        nameof(PlayniteSettings.ShowMainMenuOnTopPanel),
                                        converter: new InvertedBooleanToVisibilityConverter());
            }
        }
Exemplo n.º 2
0
        private TopPanelItem AssignPanelButton(string contentTemplate, ContextMenu menu, string tooltip, out TopPanelWrapperItem panelItem)
        {
            panelItem = new TopPanelWrapperItem(new SDK.Plugins.TopPanelItem {
                Title = ResourceProvider.GetString(tooltip)
            }, mainModel);
            var item = new TopPanelItem()
            {
                DataContext = panelItem
            };

            item.SetResourceReference(TopPanelItem.ContentTemplateProperty, contentTemplate);
            LeftClickContextMenuBehavior.SetEnabled(item, true);
            menu.SetResourceReference(ContextMenu.StyleProperty, "TopPanelMenu");
            item.ContextMenu = menu;
            return(item);
        }
Exemplo n.º 3
0
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            ListSideBarItems = Template.FindName("PART_ListSideBarItems", this) as ItemsControl;
            if (ListSideBarItems != null)
            {
                BindingTools.SetBinding(ListSideBarItems,
                                        ItemsControl.ItemsSourceProperty,
                                        mainModel,
                                        nameof(DesktopAppViewModel.AppViewItems));
            }

            ElemMainMenu = Template.FindName("PART_ElemMainMenu", this) as FrameworkElement;
            if (ElemMainMenu != null)
            {
                LeftClickContextMenuBehavior.SetEnabled(ElemMainMenu, true);
                ElemMainMenu.ContextMenu = new MainMenu(mainModel)
                {
                    StaysOpen = false,
                    Placement = PlacementMode.Bottom
                };
            }
        }
Exemplo n.º 4
0
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            ButtonPlayAction = Template.FindName("PART_ButtonPlayAction", this) as Button;
            if (ButtonPlayAction != null)
            {
                BindingTools.SetBinding(ButtonPlayAction,
                                        Button.CommandProperty,
                                        nameof(GameDetailsViewModel.PlayCommand));
                BindingTools.SetBinding(ButtonPlayAction,
                                        Button.ContentProperty,
                                        nameof(GameDetailsViewModel.ContextActionDescription));
                BindingTools.SetBinding(ButtonPlayAction,
                                        Button.VisibilityProperty,
                                        nameof(GameDetailsViewModel.IsPlayAvailable),
                                        converter: new BooleanToVisibilityConverter());
            }

            ButtonContextAction = Template.FindName("PART_ButtonContextAction", this) as Button;
            if (ButtonContextAction != null)
            {
                BindingTools.SetBinding(ButtonContextAction,
                                        Button.CommandProperty,
                                        nameof(GameDetailsViewModel.ContextActionCommand));
                BindingTools.SetBinding(ButtonContextAction,
                                        Button.ContentProperty,
                                        nameof(GameDetailsViewModel.ContextActionDescription));
                BindingTools.SetBinding(ButtonContextAction,
                                        Button.VisibilityProperty,
                                        nameof(GameDetailsViewModel.IsContextAvailable),
                                        converter: new BooleanToVisibilityConverter());
            }

            ButtonMoreActions = Template.FindName("PART_ButtonMoreActions", this) as Button;
            if (ButtonMoreActions != null)
            {
                LeftClickContextMenuBehavior.SetEnabled(ButtonMoreActions, true);

                if (!DesignerProperties.GetIsInDesignMode(this))
                {
                    ButtonMoreActions.ContextMenu = new GameMenu(mainModel)
                    {
                        ShowStartSection = false,
                        Placement        = PlacementMode.Bottom
                    };
                    BindingTools.SetBinding(ButtonMoreActions.ContextMenu,
                                            Button.DataContextProperty,
                                            mainModel,
                                            nameof(DesktopAppViewModel.SelectedGame));
                }
            }

            HtmlDescription = Template.FindName("PART_HtmlDescription", this) as HtmlTextView;
            if (HtmlDescription != null)
            {
                BindingTools.SetBinding(HtmlDescription,
                                        HtmlTextView.HtmlTextProperty,
                                        GetGameBindingPath(nameof(GamesCollectionViewEntry.Description)));
                BindingTools.SetBinding(HtmlDescription,
                                        HtmlTextView.VisibilityProperty,
                                        nameof(GameDetailsViewModel.DescriptionVisibility));
            }

            ImageCover = Template.FindName("PART_ImageCover", this) as Image;
            if (ImageCover != null)
            {
                BindingTools.SetBinding(ImageCover,
                                        Image.SourceProperty,
                                        GetGameBindingPath(nameof(GamesCollectionViewEntry.CoverImageObject)),
                                        converter: new NullToDependencyPropertyUnsetConverter());
                BindingTools.SetBinding(ImageCover,
                                        Image.VisibilityProperty,
                                        nameof(GameDetailsViewModel.CoverVisibility));
            }

            ImageIcon = Template.FindName("PART_ImageIcon", this) as Image;
            if (ImageIcon != null)
            {
                var sourceBinding = new PriorityBinding();
                sourceBinding.Bindings.Add(new Binding()
                {
                    Path      = new PropertyPath(GetGameBindingPath(nameof(GamesCollectionViewEntry.IconObject))),
                    Converter = new NullToDependencyPropertyUnsetConverter()
                });
                sourceBinding.Bindings.Add(new Binding()
                {
                    Path      = new PropertyPath(GetGameBindingPath(nameof(GamesCollectionViewEntry.DefaultIconObject))),
                    Converter = new NullToDependencyPropertyUnsetConverter()
                });

                BindingOperations.SetBinding(ImageIcon, Image.SourceProperty, sourceBinding);
                BindingTools.SetBinding(ImageIcon,
                                        Image.VisibilityProperty,
                                        nameof(GameDetailsViewModel.IconVisibility));
            }

            ImageBackground = Template.FindName("PART_ImageBackground", this) as FadeImage;
            if (ImageBackground != null)
            {
                SetBackgroundBinding();
                BindingTools.SetBinding(ImageBackground,
                                        Image.VisibilityProperty,
                                        nameof(GameDetailsViewModel.BackgroundVisibility));
            }

            SetElemVisibility(ref ElemPlayTime, "PART_ElemPlayTime", nameof(GameDetailsViewModel.PlayTimeVisibility));
            SetElemVisibility(ref ElemLastPlayed, "PART_ElemLastPlayed", nameof(GameDetailsViewModel.LastPlayedVisibility));
            SetElemVisibility(ref ElemCompletionStatus, "PART_ElemCompletionStatus", nameof(GameDetailsViewModel.CompletionStatusVisibility));
            SetElemVisibility(ref ElemLibrary, "PART_ElemLibrary", nameof(GameDetailsViewModel.SourceLibraryVisibility));
            SetElemVisibility(ref ElemPlatform, "PART_ElemPlatform", nameof(GameDetailsViewModel.PlatformVisibility));
            SetElemVisibility(ref ElemGenres, "PART_ElemGenres", nameof(GameDetailsViewModel.GenreVisibility));
            SetElemVisibility(ref ElemDevelopers, "PART_ElemDevelopers", nameof(GameDetailsViewModel.DeveloperVisibility));
            SetElemVisibility(ref ElemPublishers, "PART_ElemPublishers", nameof(GameDetailsViewModel.PublisherVisibility));
            SetElemVisibility(ref ElemReleaseDate, "PART_ElemReleaseDate", nameof(GameDetailsViewModel.ReleaseDateVisibility));
            SetElemVisibility(ref ElemTags, "PART_ElemCategories", nameof(GameDetailsViewModel.CategoryVisibility));
            SetElemVisibility(ref ElemCategories, "PART_ElemTags", nameof(GameDetailsViewModel.TagVisibility));
            SetElemVisibility(ref ElemLinks, "PART_ElemLinks", nameof(GameDetailsViewModel.LinkVisibility));
            SetElemVisibility(ref ElemDescription, "PART_ElemDescription", nameof(GameDetailsViewModel.DescriptionVisibility));
            SetElemVisibility(ref ElemDescription, "PART_ElemAgeRating", nameof(GameDetailsViewModel.AgeRatingVisibility));
            SetElemVisibility(ref ElemDescription, "PART_ElemSeries", nameof(GameDetailsViewModel.SeriesVisibility));
            SetElemVisibility(ref ElemDescription, "PART_ElemRegion", nameof(GameDetailsViewModel.RegionVisibility));
            SetElemVisibility(ref ElemDescription, "PART_ElemSource", nameof(GameDetailsViewModel.SourceVisibility));
            SetElemVisibility(ref ElemDescription, "PART_ElemVersion", nameof(GameDetailsViewModel.VersionVisibility));
            SetElemVisibility(ref ElemDescription, "PART_ElemCommunityScore", nameof(GameDetailsViewModel.CommunityScoreVisibility));
            SetElemVisibility(ref ElemDescription, "PART_ElemCriticScore", nameof(GameDetailsViewModel.CriticScoreVisibility));
            SetElemVisibility(ref ElemDescription, "PART_ElemUserScore", nameof(GameDetailsViewModel.UserScoreVisibility));

            SetGameItemButtonBinding(ref ButtonLibrary, "PART_ButtonLibrary",
                                     nameof(GameDetailsViewModel.SetLibraryFilterCommand),
                                     GetGameBindingPath(nameof(GamesCollectionViewEntry.PluginId)),
                                     GetGameBindingPath($"{nameof(GamesCollectionViewEntry.LibraryPlugin)}.{nameof(GamesCollectionViewEntry.LibraryPlugin.Name)}"),
                                     nameof(GameDetailsViewModel.SourceLibraryVisibility));

            SetGameItemButtonBinding(ref ButtonPlatform, "PART_ButtonPlatform",
                                     nameof(GameDetailsViewModel.SetPlatformFilterCommand),
                                     GetGameBindingPath(nameof(GamesCollectionViewEntry.Platform)),
                                     GetGameBindingPath($"{nameof(GamesCollectionViewEntry.Platform)}.{nameof(GamesCollectionViewEntry.Platform.Name)}"),
                                     nameof(GameDetailsViewModel.PlatformVisibility));

            SetGameItemButtonBinding(ref ButtonReleaseDate, "PART_ButtonReleaseDate",
                                     nameof(GameDetailsViewModel.SetReleaseDateFilterCommand),
                                     GetGameBindingPath(nameof(GamesCollectionViewEntry.ReleaseDate)),
                                     GetGameBindingPath(nameof(GamesCollectionViewEntry.ReleaseDate)),
                                     nameof(GameDetailsViewModel.ReleaseDateVisibility),
                                     new NullableDateToStringConverter());

            SetGameItemButtonBinding(ref ButtonVersion, "PART_ButtonVersion",
                                     nameof(GameDetailsViewModel.SetVersionFilterCommand),
                                     GetGameBindingPath(nameof(GamesCollectionViewEntry.Version)),
                                     GetGameBindingPath(nameof(GamesCollectionViewEntry.Version)),
                                     nameof(GameDetailsViewModel.VersionVisibility));

            SetGameItemButtonBinding(ref ButtonAgeRating, "PART_ButtonAgeRating",
                                     nameof(GameDetailsViewModel.SetAgeRatingCommand),
                                     GetGameBindingPath(nameof(GamesCollectionViewEntry.AgeRating)),
                                     GetGameBindingPath($"{nameof(GamesCollectionViewEntry.AgeRating)}.{nameof(GamesCollectionViewEntry.AgeRating.Name)}"),
                                     nameof(GameDetailsViewModel.AgeRatingVisibility));

            SetGameItemButtonBinding(ref ButtonSeries, "PART_ButtonSeries",
                                     nameof(GameDetailsViewModel.SetSeriesFilterCommand),
                                     GetGameBindingPath(nameof(GamesCollectionViewEntry.Series)),
                                     GetGameBindingPath($"{nameof(GamesCollectionViewEntry.Series)}.{nameof(GamesCollectionViewEntry.Series.Name)}"),
                                     nameof(GameDetailsViewModel.SeriesVisibility));

            SetGameItemButtonBinding(ref ButtonSource, "PART_ButtonSource",
                                     nameof(GameDetailsViewModel.SetSourceFilterCommand),
                                     GetGameBindingPath(nameof(GamesCollectionViewEntry.Source)),
                                     GetGameBindingPath($"{nameof(GamesCollectionViewEntry.Source)}.{nameof(GamesCollectionViewEntry.Source.Name)}"),
                                     nameof(GameDetailsViewModel.SourceVisibility));

            SetGameItemButtonBinding(ref ButtonRegion, "PART_ButtonRegion",
                                     nameof(GameDetailsViewModel.SetRegionFilterCommand),
                                     GetGameBindingPath(nameof(GamesCollectionViewEntry.Region)),
                                     GetGameBindingPath($"{nameof(GamesCollectionViewEntry.Region)}.{nameof(GamesCollectionViewEntry.Region.Name)}"),
                                     nameof(GameDetailsViewModel.RegionVisibility));

            SetGameItemTextBinding(ref TextPlayTime, "PART_TextPlayTime",
                                   nameof(GameDetailsViewModel.Game.Playtime),
                                   nameof(GameDetailsViewModel.PlayTimeVisibility),
                                   new LongToTimePlayedConverter());

            SetGameItemTextBinding(ref TextLastActivity, "PART_TextLastActivity",
                                   nameof(GameDetailsViewModel.Game.LastActivity),
                                   nameof(GameDetailsViewModel.LastPlayedVisibility),
                                   new DateTimeToLastPlayedConverter());

            SetGameItemTextBinding(ref TextCompletionStatus, "PART_TextCompletionStatus",
                                   nameof(GameDetailsViewModel.Game.CompletionStatus),
                                   nameof(GameDetailsViewModel.CompletionStatusVisibility),
                                   new ObjectToStringConverter());

            SetGameItemTextBinding(ref TextCommunityScore, "PART_TextCommunityScore",
                                   nameof(GameDetailsViewModel.Game.CommunityScore),
                                   nameof(GameDetailsViewModel.CommunityScoreVisibility));
            if (TextCommunityScore != null)
            {
                BindingTools.SetBinding(TextCommunityScore,
                                        TextBlock.TagProperty,
                                        GetGameBindingPath(nameof(GamesCollectionViewEntry.CommunityScoreRating)));
            }

            SetGameItemTextBinding(ref TextCriticScore, "PART_TextCriticScore",
                                   nameof(GameDetailsViewModel.Game.CriticScore),
                                   nameof(GameDetailsViewModel.CriticScoreVisibility));
            if (TextCriticScore != null)
            {
                BindingTools.SetBinding(TextCriticScore,
                                        TextBlock.TagProperty,
                                        GetGameBindingPath(nameof(GamesCollectionViewEntry.CriticScoreRating)));
            }

            SetGameItemTextBinding(ref TextUserScore, "PART_TextUserScore",
                                   nameof(GameDetailsViewModel.Game.UserScore),
                                   nameof(GameDetailsViewModel.UserScoreVisibility));
            if (TextUserScore != null)
            {
                BindingTools.SetBinding(TextUserScore,
                                        TextBlock.TagProperty,
                                        GetGameBindingPath(nameof(GamesCollectionViewEntry.UserScoreRating)));
            }

            SetItemsControlBinding(ref ItemsGenres, "PART_ItemsGenres",
                                   nameof(GameDetailsViewModel.SetGenreFilterCommand),
                                   nameof(GamesCollectionViewEntry.Genres),
                                   nameof(GameDetailsViewModel.GenreVisibility));

            SetItemsControlBinding(ref ItemsDevelopers, "PART_ItemsDevelopers",
                                   nameof(GameDetailsViewModel.SetDeveloperFilterCommand),
                                   nameof(GamesCollectionViewEntry.Developers),
                                   nameof(GameDetailsViewModel.DeveloperVisibility));

            SetItemsControlBinding(ref ItemsPublishers, "PART_ItemsPublishers",
                                   nameof(GameDetailsViewModel.SetPublisherFilterCommand),
                                   nameof(GamesCollectionViewEntry.Publishers),
                                   nameof(GameDetailsViewModel.PublisherVisibility));

            SetItemsControlBinding(ref ItemsCategories, "PART_ItemsCategories",
                                   nameof(GameDetailsViewModel.SetCategoryFilterCommand),
                                   nameof(GamesCollectionViewEntry.Categories),
                                   nameof(GameDetailsViewModel.CategoryVisibility));

            SetItemsControlBinding(ref ItemsTags, "PART_ItemsTags",
                                   nameof(GameDetailsViewModel.SetTagFilterCommand),
                                   nameof(GamesCollectionViewEntry.Tags),
                                   nameof(GameDetailsViewModel.TagVisibility));

            SetItemsControlBinding(ref ItemsLinks, "PART_ItemsLinks",
                                   nameof(GameDetailsViewModel.OpenLinkCommand),
                                   nameof(GamesCollectionViewEntry.Links),
                                   nameof(GameDetailsViewModel.LinkVisibility),
                                   nameof(Link.Url));
        }
Exemplo n.º 5
0
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            PanelMainItems = Template.FindName("PART_PanelMainItems", this) as Panel;
            if (PanelMainItems != null)
            {
                PanelMainItems.Children.Add(AssignPanelButton("TopPanelGeneralViewSettingsTemplate", new ViewSettingsMenu(mainModel.AppSettings), LOC.SettingsTopPanelGeneralViewItem, out ButtonViewSettings));
                PanelMainItems.Children.Add(AssignPanelButton("TopPanelFilterPresetsSelectionTemplate", new FilterPresetsMenu(mainModel), LOC.SettingsTopPanelFilterPresetsItem, out ButtonFilterPresets));
                PanelMainItems.Children.Add(AssignPanelButton("TopPanelGroupSettingsTemplate", new GroupSettingsMenu(mainModel.AppSettings), LOC.SettingsTopPanelGroupingItem, out ButtonGroupSettings));
                PanelMainItems.Children.Add(AssignPanelButton("TopPanelSortSettingsTemplate", new SortSettingsMenu(mainModel.AppSettings), LOC.SettingsTopPanelSortingItem, out ButtonSortSettings));

                LeftViewSeparator.Width  = mainModel.AppSettings.TopPanelSectionSeparatorWidth;
                RightViewSeparator.Width = mainModel.AppSettings.TopPanelSectionSeparatorWidth;
                PanelMainItems.Children.Add(LeftViewSeparator);

                var detailsButton = AssignPanelButton("TopPanelSwitchDetailsViewTemplate", mainModel.SwitchDetailsViewCommand, ViewType.Details.GetDescription(), out ButtonSwitchDetailsView);
                BindingTools.SetBinding(detailsButton,
                                        TopPanelItem.IsToggledProperty,
                                        mainModel.AppSettings.ViewSettings,
                                        nameof(ViewSettings.GamesViewType),
                                        converter: new EnumToBooleanConverter(),
                                        converterParameter: ViewType.Details);
                PanelMainItems.Children.Add(detailsButton);

                var gridButton = AssignPanelButton("TopPanelSwitchGridViewTemplate", mainModel.SwitchGridViewCommand, ViewType.Grid.GetDescription(), out ButtonSwitchGridView);
                BindingTools.SetBinding(gridButton,
                                        TopPanelItem.IsToggledProperty,
                                        mainModel.AppSettings.ViewSettings,
                                        nameof(ViewSettings.GamesViewType),
                                        converter: new EnumToBooleanConverter(),
                                        converterParameter: ViewType.Grid);
                PanelMainItems.Children.Add(gridButton);

                var listButton = AssignPanelButton("TopPanelSwitchListViewTemplate", mainModel.SwitchListViewCommand, ViewType.List.GetDescription(), out ButtonSwitchListView);
                BindingTools.SetBinding(listButton,
                                        TopPanelItem.IsToggledProperty,
                                        mainModel.AppSettings.ViewSettings,
                                        nameof(ViewSettings.GamesViewType),
                                        converter: new EnumToBooleanConverter(),
                                        converterParameter: ViewType.List);
                PanelMainItems.Children.Add(listButton);
                PanelMainItems.Children.Add(RightViewSeparator);

                var updatesButton = AssignPanelButton("TopPanelUpdateButtonTemplate", mainModel.OpenUpdatesCommand, ResourceProvider.GetString(LOC.UpdateIsAvailableNotificationBody), out _);
                BindingTools.SetBinding(updatesButton,
                                        Button.VisibilityProperty,
                                        mainModel,
                                        nameof(mainModel.UpdatesAvailable),
                                        converter: new BooleanToVisibilityConverter());
                PanelMainItems.Children.Add(updatesButton);
                PanelMainItems.Children.Add(AssignPanelButton("TopPanelSelectRandomGameButtonTemplate", mainModel.SelectRandomGameCommand, ResourceProvider.GetString(LOC.TopPanelSelectRandomGameButton), out ButtonSelectRandomGame));
                PanelMainItems.Children.Add(AssignPanelButton("TopPanelExplorerSwitchTemplate", mainModel.ToggleExplorerPanelCommand, ResourceProvider.GetString(LOC.TopPanelExplorerSwitch), out ButtonExplorerSwitch));
                SetButtonVisibility();
            }

            PanelMainPluginItems = Template.FindName("PART_PanelMainPluginItems", this) as Panel;
            if (PanelMainPluginItems != null)
            {
                PanelMainPluginItems.Children.Clear();
                foreach (var item in mainModel.GetTopPanelPluginItems())
                {
                    PanelMainPluginItems.Children.Add(AssignPluginButton(item));
                }
            }

            ElemMainMenu = Template.FindName("PART_ElemMainMenu", this) as FrameworkElement;
            if (ElemMainMenu != null)
            {
                LeftClickContextMenuBehavior.SetEnabled(ElemMainMenu, true);
                ElemMainMenu.ContextMenu = new MainMenu(mainModel);
                ElemMainMenu.ContextMenu.SetResourceReference(ContextMenu.StyleProperty, "TopPanelMenu");

                BindingTools.SetBinding(ElemMainMenu,
                                        FrameworkElement.VisibilityProperty,
                                        mainModel.AppSettings,
                                        nameof(PlayniteSettings.ShowMainMenuOnTopPanel),
                                        converter: new BooleanToVisibilityConverter());
            }

            TextMainSearch = Template.FindName("PART_TextMainSearch", this) as SearchBox;
            if (TextMainSearch != null)
            {
                BindingTools.SetBinding(TextMainSearch,
                                        SearchBox.TextProperty,
                                        mainModel.AppSettings.FilterSettings,
                                        nameof(FilterSettings.Name),
                                        BindingMode.TwoWay,
                                        delay: 100);
                BindingTools.SetBinding(TextMainSearch,
                                        SearchBox.IsFocusedProperty,
                                        mainModel,
                                        nameof(mainModel.SearchOpened),
                                        BindingMode.TwoWay);
            }

            ToggleFilter = Template.FindName("PART_ToggleFilter", this) as ToggleButton;
            if (ToggleFilter != null)
            {
                BindingTools.SetBinding(ToggleFilter,
                                        ToggleButton.IsCheckedProperty,
                                        mainModel.AppSettings,
                                        nameof(PlayniteSettings.FilterPanelVisible),
                                        BindingMode.TwoWay);
                BindingTools.SetBinding(ToggleFilter,
                                        ToggleButton.TagProperty,
                                        mainModel.AppSettings.FilterSettings,
                                        nameof(FilterSettings.IsActive));
            }

            ToggleNotifications = Template.FindName("PART_ToggleNotifications", this) as ToggleButton;
            if (ToggleNotifications != null)
            {
                BindingTools.SetBinding(ToggleNotifications,
                                        ToggleButton.IsCheckedProperty,
                                        mainModel.AppSettings,
                                        nameof(PlayniteSettings.NotificationPanelVisible),
                                        BindingMode.TwoWay);
            }

            ProgressGlobal = Template.FindName("PART_ProgressGlobal", this) as ProgressBar;
            if (ProgressGlobal != null)
            {
                BindingTools.SetBinding(ProgressGlobal,
                                        ProgressBar.MaximumProperty,
                                        mainModel,
                                        nameof(mainModel.ProgressTotal));
                BindingTools.SetBinding(ProgressGlobal,
                                        ProgressBar.ValueProperty,
                                        mainModel,
                                        nameof(mainModel.ProgressValue));
                BindingTools.SetBinding(ProgressGlobal,
                                        ProgressBar.VisibilityProperty,
                                        mainModel,
                                        nameof(mainModel.ProgressActive),
                                        converter: new BooleanToVisibilityConverter());
            }

            TextProgressText = Template.FindName("PART_TextProgressText", this) as TextBlock;
            if (TextProgressText != null)
            {
                BindingTools.SetBinding(TextProgressText,
                                        TextBlock.TextProperty,
                                        mainModel,
                                        nameof(mainModel.ProgressStatus));
                BindingTools.SetBinding(TextProgressText,
                                        TextBlock.VisibilityProperty,
                                        mainModel,
                                        nameof(mainModel.ProgressActive),
                                        converter: new BooleanToVisibilityConverter());
            }

            ButtonProgressCancel = Template.FindName("PART_ButtonProgressCancel", this) as ButtonBase;
            if (ButtonProgressCancel != null)
            {
                ButtonProgressCancel.Command = mainModel.CancelProgressCommand;
                BindingTools.SetBinding(ButtonProgressCancel,
                                        ButtonBase.VisibilityProperty,
                                        mainModel,
                                        nameof(mainModel.ProgressActive),
                                        converter: new BooleanToVisibilityConverter());
            }
        }
Exemplo n.º 6
0
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            ElemMainMenu = Template.FindName("PART_ElemMainMenu", this) as FrameworkElement;
            if (ElemMainMenu != null)
            {
                LeftClickContextMenuBehavior.SetEnabled(ElemMainMenu, true);
                ElemMainMenu.ContextMenu = new MainMenu(mainModel)
                {
                    StaysOpen = false,
                    Placement = PlacementMode.Bottom
                };
            }

            ElemViewMenu = Template.FindName("PART_ElemViewMenu", this) as FrameworkElement;
            if (ElemViewMenu != null)
            {
                LeftClickContextMenuBehavior.SetEnabled(ElemViewMenu, true);
                ElemViewMenu.ContextMenu = new ViewSettingsMenu(mainModel.AppSettings)
                {
                    StaysOpen = false,
                    Placement = PlacementMode.Bottom
                };
            }

            TextMainSearch = Template.FindName("PART_TextMainSearch", this) as SearchBox;
            if (TextMainSearch != null)
            {
                BindingTools.SetBinding(TextMainSearch,
                                        SearchBox.TextProperty,
                                        mainModel.AppSettings.FilterSettings,
                                        nameof(FilterSettings.Name),
                                        BindingMode.TwoWay,
                                        delay: 100);
                BindingTools.SetBinding(TextMainSearch,
                                        SearchBox.IsFocusedProperty,
                                        mainModel,
                                        nameof(mainModel.SearchOpened),
                                        BindingMode.TwoWay);
            }

            ToggleFilter = Template.FindName("PART_ToggleFilter", this) as ToggleButton;
            if (ToggleFilter != null)
            {
                BindingTools.SetBinding(ToggleFilter,
                                        ToggleButton.IsCheckedProperty,
                                        mainModel.AppSettings,
                                        nameof(PlayniteSettings.FilterPanelVisible),
                                        BindingMode.TwoWay);
                BindingTools.SetBinding(ToggleFilter,
                                        ToggleButton.TagProperty,
                                        mainModel.AppSettings.FilterSettings,
                                        nameof(FilterSettings.IsActive));
            }

            ToggleNotifications = Template.FindName("PART_ToggleNotifications", this) as ToggleButton;
            if (ToggleNotifications != null)
            {
                BindingTools.SetBinding(ToggleNotifications,
                                        ToggleButton.IsCheckedProperty,
                                        mainModel.AppSettings,
                                        nameof(PlayniteSettings.NotificationPanelVisible),
                                        BindingMode.TwoWay);
            }

            ButtonSteamFriends = Template.FindName("PART_ButtonSteamFriends", this) as ButtonBase;
            if (ButtonSteamFriends != null)
            {
                ButtonSteamFriends.Command = mainModel.OpenSteamFriendsCommand;
                BindingTools.SetBinding(ButtonSteamFriends,
                                        ButtonBase.VisibilityProperty,
                                        mainModel.AppSettings,
                                        nameof(PlayniteSettings.ShowSteamFriendsButton),
                                        converter: new BooleanToVisibilityConverter());
            }

            ProgressGlobal = Template.FindName("PART_ProgressGlobal", this) as ProgressBar;
            if (ProgressGlobal != null)
            {
                BindingTools.SetBinding(ProgressGlobal,
                                        ProgressBar.MaximumProperty,
                                        mainModel,
                                        nameof(mainModel.ProgressTotal));
                BindingTools.SetBinding(ProgressGlobal,
                                        ProgressBar.ValueProperty,
                                        mainModel,
                                        nameof(mainModel.ProgressValue));
                BindingTools.SetBinding(ProgressGlobal,
                                        ProgressBar.VisibilityProperty,
                                        mainModel,
                                        nameof(mainModel.ProgressVisible),
                                        converter: new BooleanToVisibilityConverter());
            }

            TextProgressText = Template.FindName("PART_TextProgressText", this) as TextBlock;
            if (TextProgressText != null)
            {
                BindingTools.SetBinding(TextProgressText,
                                        TextBlock.TextProperty,
                                        mainModel,
                                        nameof(mainModel.ProgressStatus));
                BindingTools.SetBinding(TextProgressText,
                                        TextBlock.VisibilityProperty,
                                        mainModel,
                                        nameof(mainModel.ProgressVisible),
                                        converter: new BooleanToVisibilityConverter());
            }

            ButtonProgressCancel = Template.FindName("PART_ButtonProgressCancel", this) as ButtonBase;
            if (ButtonProgressCancel != null)
            {
                ButtonProgressCancel.Command = mainModel.CancelProgressCommand;
                BindingTools.SetBinding(ButtonProgressCancel,
                                        ButtonBase.VisibilityProperty,
                                        mainModel,
                                        nameof(mainModel.ProgressVisible),
                                        converter: new BooleanToVisibilityConverter());
            }
        }