public static void AssignItemListPanel(ItemsControl itemsHost)
        {
            XNamespace pns = "http://schemas.microsoft.com/winfx/2006/xaml/presentation";

            itemsHost.ItemsPanel = Xaml.FromString <ItemsPanelTemplate>(new XDocument(
                                                                            new XElement(pns + nameof(ItemsPanelTemplate),
                                                                                         new XElement(pns + nameof(VirtualizingStackPanel)))
                                                                            ).ToString());

            itemsHost.Template = Xaml.FromString <ControlTemplate>(new XDocument(
                                                                       new XElement(pns + nameof(ControlTemplate),
                                                                                    new XElement(pns + nameof(ScrollViewer),
                                                                                                 new XAttribute(nameof(ScrollViewer.Focusable), false),
                                                                                                 new XAttribute(nameof(ScrollViewer.HorizontalScrollBarVisibility), ScrollBarVisibility.Disabled),
                                                                                                 new XAttribute(nameof(ScrollViewer.VerticalScrollBarVisibility), ScrollBarVisibility.Auto),
                                                                                                 new XAttribute(nameof(ScrollViewer.CanContentScroll), true),
                                                                                                 new XElement(pns + nameof(ItemsPresenter))))
                                                                       ).ToString());

            itemsHost.ItemTemplate = Xaml.FromString <DataTemplate>(new XDocument(
                                                                        new XElement(pns + nameof(DataTemplate),
                                                                                     new XElement(pns + nameof(CheckBoxEx),
                                                                                                  new XAttribute(nameof(CheckBoxEx.IsChecked), "{Binding Selected}"),
                                                                                                  new XAttribute(nameof(CheckBoxEx.Content), "{Binding Item.Name}"),
                                                                                                  new XAttribute(nameof(CheckBoxEx.Style), $"{{DynamicResource FilterItemtSelectionStyle}}")))
                                                                        ).ToString());
        }
        private ItemsPanelTemplate GetItemsPanelTemplate()
        {
            XNamespace pns         = "http://schemas.microsoft.com/winfx/2006/xaml/presentation";
            XNamespace pctrls      = "clr-namespace:Playnite.DesktopApp.Controls;assembly=Playnite.DesktopApp";
            var        templateDoc = new XDocument(
                new XElement(pns + nameof(ItemsPanelTemplate),
                             new XElement(pctrls + nameof(GridViewPanel))));

            return(Xaml.FromString <ItemsPanelTemplate>(templateDoc.ToString()));
        }
Exemple #3
0
        private ItemsPanelTemplate GetItemsPanelTemplate()
        {
            XNamespace pns         = "http://schemas.microsoft.com/winfx/2006/xaml/presentation";
            var        templateDoc = new XDocument(
                new XElement(pns + nameof(ItemsPanelTemplate),
                             new XElement(pns + nameof(FullscreenTilePanel),
                                          new XAttribute("Rows", "{Settings Fullscreen.Rows}"),
                                          new XAttribute("Columns", "{Settings Fullscreen.Columns}"),
                                          new XAttribute("UseHorizontalLayout", "{Settings Fullscreen.HorizontalLayout}"),
                                          new XAttribute("ItemAspectRatio", "{Settings CoverAspectRatio}"),
                                          new XAttribute("ItemSpacing", "{Settings FullscreenItemSpacing}"))));

            var str = templateDoc.ToString();

            return(Xaml.FromString <ItemsPanelTemplate>(str));
        }
Exemple #4
0
        private DataTemplate GetFieldItemTemplate(string command, string tooltip = null)
        {
            XNamespace pns        = "http://schemas.microsoft.com/winfx/2006/xaml/presentation";
            var        buttonElem = new XElement(pns + nameof(Button),
                                                 new XAttribute("Command", $"{{Binding DataContext.{command}, RelativeSource={{RelativeSource AncestorType=ItemsControl}}}}"),
                                                 new XAttribute("CommandParameter", "{Binding}"),
                                                 new XAttribute("Content", "{Binding Name}"),
                                                 new XAttribute("Style", "{StaticResource PropertyItemButton}"));

            if (!tooltip.IsNullOrEmpty())
            {
                buttonElem.Add(new XAttribute("ToolTip", $"{{Binding {tooltip}}}"));
            }

            var templateDoc = new XDocument(
                new XElement(pns + nameof(DataTemplate), buttonElem)
                );

            return(Xaml.FromString <DataTemplate>(templateDoc.ToString()));
        }
Exemple #5
0
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();
            if (Template != null)
            {
                ViewHost = Template.FindName("PART_ViewHost", this) as FrameworkElement;
                if (ViewHost != null)
                {
                    ViewHost.InputBindings.Add(new KeyBinding()
                    {
                        Command = mainModel.OpenMainMenuCommand, Key = Key.F1
                    });
                    ViewHost.InputBindings.Add(new KeyBinding()
                    {
                        Command = mainModel.PrevFilterViewCommand, Key = Key.F2
                    });
                    ViewHost.InputBindings.Add(new KeyBinding()
                    {
                        Command = mainModel.NextFilterViewCommand, Key = Key.F3
                    });
                    ViewHost.InputBindings.Add(new KeyBinding()
                    {
                        Command = mainModel.OpenSearchCommand, Key = Key.Y
                    });
                    ViewHost.InputBindings.Add(new KeyBinding()
                    {
                        Command = mainModel.ToggleFiltersCommand, Key = Key.F
                    });
                    ViewHost.InputBindings.Add(new KeyBinding()
                    {
                        Command = mainModel.SwitchToDesktopCommand, Key = Key.F11
                    });

                    ViewHost.InputBindings.Add(new XInputBinding(mainModel.PrevFilterViewCommand, XInputButton.LeftShoulder));
                    ViewHost.InputBindings.Add(new XInputBinding(mainModel.NextFilterViewCommand, XInputButton.RightShoulder));
                    ViewHost.InputBindings.Add(new XInputBinding(mainModel.OpenSearchCommand, XInputButton.Y));
                    ViewHost.InputBindings.Add(new XInputBinding(mainModel.ToggleFiltersCommand, XInputButton.RightStick));
                    ViewHost.InputBindings.Add(new XInputBinding(mainModel.OpenMainMenuCommand, XInputButton.Back));
                }

                MainHost = Template.FindName("PART_MainHost", this) as FrameworkElement;
                if (MainHost != null)
                {
                    BindingTools.SetBinding(MainHost, FrameworkElement.WidthProperty, mainModel, nameof(FullscreenAppViewModel.ViewportWidth));
                    BindingTools.SetBinding(MainHost, FrameworkElement.HeightProperty, mainModel, nameof(FullscreenAppViewModel.ViewportHeight));
                }

                AssignButtonWithCommand(ref ButtonProgramUpdate, "PART_ButtonProgramUpdate", mainModel.OpenUpdatesCommand);
                AssignButtonWithCommand(ref ButtonMainMenu, "PART_ButtonMainMenu", mainModel.OpenMainMenuCommand);
                AssignButtonWithCommand(ref ButtonNotifications, "PART_ButtonNotifications", mainModel.OpenNotificationsMenuCommand);

                if (ButtonProgramUpdate != null)
                {
                    BindingTools.SetBinding(ButtonProgramUpdate,
                                            Button.VisibilityProperty,
                                            mainModel,
                                            nameof(mainModel.UpdatesAvailable),
                                            converter: new Converters.BooleanToVisibilityConverter());
                }

                ImageBackground = Template.FindName("PART_ImageBackground", this) as FadeImage;
                if (ImageBackground != null)
                {
                    SetBackgroundBinding();
                    SetBackgroundEffect();
                }

                TextClock = Template.FindName("PART_TextClock", this) as TextBlock;
                if (TextClock != null)
                {
                    BindingTools.SetBinding(TextClock, TextBlock.TextProperty, mainModel.CurrentTime, nameof(ObservableTime.Time));
                    BindingTools.SetBinding(
                        TextClock,
                        TextBlock.VisibilityProperty,
                        mainModel.AppSettings.Fullscreen,
                        nameof(FullscreenSettings.ShowClock),
                        converter: new Converters.BooleanToVisibilityConverter());
                }

                TextBatteryPercentage = Template.FindName("PART_TextBatteryPercentage", this) as TextBlock;
                if (TextBatteryPercentage != null)
                {
                    BindingTools.SetBinding(TextBatteryPercentage,
                                            TextBlock.TextProperty,
                                            mainModel.PowerStatus,
                                            nameof(ObservablePowerStatus.PercentCharge),
                                            stringFormat: "{0}%");
                    BindingTools.SetBinding(TextBatteryPercentage,
                                            TextBlock.VisibilityProperty,
                                            mainModel.AppSettings.Fullscreen,
                                            nameof(FullscreenSettings.ShowBatteryPercentage),
                                            converter: new Converters.BooleanToVisibilityConverter());
                }

                ElemBatteryStatus = Template.FindName("PART_ElemBatteryStatus", this) as FrameworkElement;
                if (ElemBatteryStatus != null)
                {
                    BindingTools.SetBinding(
                        ElemBatteryStatus,
                        TextBlock.VisibilityProperty,
                        mainModel.AppSettings.Fullscreen,
                        nameof(FullscreenSettings.ShowBattery),
                        converter: new Converters.BooleanToVisibilityConverter());
                }

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

                ElemProgressIndicator = Template.FindName("PART_ElemProgressIndicator", this) as FrameworkElement;
                if (ElemProgressIndicator != null)
                {
                    BindingTools.SetBinding(ElemProgressIndicator,
                                            ToggleButton.VisibilityProperty,
                                            mainModel,
                                            nameof(FullscreenAppViewModel.ProgressActive),
                                            converter: new Converters.BooleanToVisibilityConverter());
                }

                ElemExtraFilterActive = Template.FindName("PART_ElemExtraFilterActive", this) as FrameworkElement;
                if (ElemExtraFilterActive != null)
                {
                    BindingTools.SetBinding(ElemExtraFilterActive,
                                            FrameworkElement.VisibilityProperty,
                                            mainModel,
                                            nameof(FullscreenAppViewModel.IsExtraFilterActive),
                                            converter: new Converters.BooleanToVisibilityConverter());
                }

                ElemSearchActive = Template.FindName("PART_ElemSearchActive", this) as FrameworkElement;
                if (ElemSearchActive != null)
                {
                    BindingTools.SetBinding(ElemSearchActive,
                                            FrameworkElement.VisibilityProperty,
                                            mainModel,
                                            nameof(FullscreenAppViewModel.IsSearchActive),
                                            converter: new Converters.BooleanToVisibilityConverter());
                }

                ListGameItems = Template.FindName("PART_ListGameItems", this) as ListBox;
                if (ListGameItems != null)
                {
                    XNamespace pns = "http://schemas.microsoft.com/winfx/2006/xaml/presentation";
                    ListGameItems.ItemsPanel = Xaml.FromString <ItemsPanelTemplate>(new XDocument(
                                                                                        new XElement(pns + nameof(ItemsPanelTemplate),
                                                                                                     new XElement(pns + nameof(FullscreenTilePanel),
                                                                                                                  new XAttribute(nameof(FullscreenTilePanel.Rows), "{Settings Fullscreen.Rows}"),
                                                                                                                  new XAttribute(nameof(FullscreenTilePanel.Columns), "{Settings Fullscreen.Columns}"),
                                                                                                                  new XAttribute(nameof(FullscreenTilePanel.UseHorizontalLayout), "{Settings Fullscreen.HorizontalLayout}"),
                                                                                                                  new XAttribute(nameof(FullscreenTilePanel.ItemAspectRatio), "{Settings CoverAspectRatio}"),
                                                                                                                  new XAttribute(nameof(FullscreenTilePanel.ItemSpacing), "{Settings FullscreenItemSpacing}")))
                                                                                        ).ToString());

                    ListGameItems.ItemTemplate = Xaml.FromString <DataTemplate>(new XDocument(
                                                                                    new XElement(pns + nameof(DataTemplate),
                                                                                                 new XElement(pns + nameof(GameListItem),
                                                                                                              new XAttribute(nameof(GameListItem.Style), "{StaticResource ListGameItemTemplate}")))
                                                                                    ).ToString());

                    ListGameItems.SetResourceReference(ListBoxEx.ItemContainerStyleProperty, "ListGameItemStyle");

                    BindingTools.SetBinding(ListGameItems,
                                            ListBox.VisibilityProperty,
                                            mainModel,
                                            nameof(FullscreenAppViewModel.GameListVisible),
                                            converter: new Converters.BooleanToVisibilityConverter());
                    BindingTools.SetBinding(ListGameItems,
                                            ListBox.SelectedItemProperty,
                                            mainModel,
                                            nameof(FullscreenAppViewModel.SelectedGame),
                                            BindingMode.TwoWay);
                    BindingTools.SetBinding(ListGameItems,
                                            ListBox.ItemsSourceProperty,
                                            mainModel,
                                            $"{nameof(FullscreenAppViewModel.GamesView)}.{nameof(FullscreenCollectionView.CollectionView)}");
                    BindingTools.SetBinding(ListGameItems,
                                            FocusBahaviors.FocusBindingProperty,
                                            mainModel,
                                            nameof(mainModel.GameListFocused));
                }

                AssignButtonWithCommand(ref ButtonInstall, "PART_ButtonInstall", mainModel.ActivateSelectedCommand);
                if (ButtonInstall != null)
                {
                    BindingTools.SetBinding(
                        ButtonInstall,
                        ButtonBase.VisibilityProperty,
                        mainModel,
                        $"{nameof(FullscreenAppViewModel.SelectedGame)}.{nameof(GamesCollectionViewEntry.IsInstalled)}",
                        converter: new InvertedBooleanToVisibilityConverter(),
                        fallBackValue: Visibility.Collapsed);
                }

                AssignButtonWithCommand(ref ButtonPlay, "PART_ButtonPlay", mainModel.ActivateSelectedCommand);
                if (ButtonPlay != null)
                {
                    ButtonPlay.Command = mainModel.ActivateSelectedCommand;
                    BindingTools.SetBinding(
                        ButtonPlay,
                        ButtonBase.VisibilityProperty,
                        mainModel,
                        $"{nameof(FullscreenAppViewModel.SelectedGame)}.{nameof(GamesCollectionViewEntry.IsInstalled)}",
                        converter: new Converters.BooleanToVisibilityConverter(),
                        fallBackValue: Visibility.Collapsed);
                }

                AssignButtonWithCommand(ref ButtonDetails, "PART_ButtonDetails", mainModel.ToggleGameDetailsCommand);
                if (ButtonDetails != null)
                {
                    BindingTools.SetBinding(
                        ButtonDetails,
                        ButtonBase.VisibilityProperty,
                        mainModel,
                        nameof(FullscreenAppViewModel.GameDetailsButtonVisible),
                        converter: new Converters.BooleanToVisibilityConverter());
                }

                AssignButtonWithCommand(ref ButtonGameOptions, "PART_ButtonGameOptions", mainModel.OpenGameMenuCommand);
                if (ButtonGameOptions != null)
                {
                    BindingTools.SetBinding(
                        ButtonGameOptions,
                        ButtonBase.VisibilityProperty,
                        mainModel,
                        nameof(FullscreenAppViewModel.GameDetailsButtonVisible),
                        converter: new Converters.BooleanToVisibilityConverter());
                    ButtonGameOptions.SetResourceReference(ButtonEx.InputHintProperty, "ButtonPromptStart");
                }

                AssignButtonWithCommand(ref ButtonSearch, "PART_ButtonSearch", mainModel.OpenSearchCommand);
                ButtonSearch?.SetResourceReference(ButtonEx.InputHintProperty, "ButtonPromptY");
                AssignButtonWithCommand(ref ButtonFilter, "PART_ButtonFilter", mainModel.ToggleFiltersCommand);
                ButtonFilter?.SetResourceReference(ButtonEx.InputHintProperty, "ButtonPromptRS");

                ElemFilters = Template.FindName("PART_ElemFilters", this) as FrameworkElement;
                if (ElemFilters != null)
                {
                    BindingTools.SetBinding(ElemFilters,
                                            FrameworkElement.VisibilityProperty,
                                            mainModel,
                                            nameof(FullscreenAppViewModel.FilterPanelVisible),
                                            converter: new Converters.BooleanToVisibilityConverter());
                }

                ElemFiltersAdditional = Template.FindName("PART_ElemFiltersAdditional", this) as FrameworkElement;
                if (ElemFiltersAdditional != null)
                {
                    BindingTools.SetBinding(ElemFiltersAdditional,
                                            FrameworkElement.VisibilityProperty,
                                            mainModel,
                                            nameof(FullscreenAppViewModel.FilterAdditionalPanelVisible),
                                            converter: new Converters.BooleanToVisibilityConverter());
                }

                ContentFilterItems = Template.FindName("PART_ContentFilterItems", this) as ContentControl;
                if (ContentFilterItems != null)
                {
                    BindingTools.SetBinding(ContentFilterItems,
                                            ContentControl.VisibilityProperty,
                                            mainModel,
                                            nameof(FullscreenAppViewModel.SubFilterVisible),
                                            converter: new Converters.BooleanToVisibilityConverter());
                    BindingTools.SetBinding(ContentFilterItems,
                                            ContentControl.ContentProperty,
                                            mainModel,
                                            nameof(FullscreenAppViewModel.SubFilterControl));
                }

                ElemGameDetails = Template.FindName("PART_ElemGameDetails", this) as FrameworkElement;
                if (ElemGameDetails != null)
                {
                    BindingTools.SetBinding(ElemGameDetails,
                                            FrameworkElement.VisibilityProperty,
                                            mainModel,
                                            nameof(FullscreenAppViewModel.GameDetailsVisible),
                                            converter: new Converters.BooleanToVisibilityConverter());
                    BindingTools.SetBinding(ElemGameDetails,
                                            FrameworkElement.DataContextProperty,
                                            mainModel,
                                            nameof(FullscreenAppViewModel.SelectedGame));
                }

                ElemGameStatus = Template.FindName("PART_ElemGameStatus", this) as FrameworkElement;
                if (ElemGameStatus != null)
                {
                    BindingTools.SetBinding(ElemGameStatus,
                                            FrameworkElement.VisibilityProperty,
                                            mainModel,
                                            nameof(FullscreenAppViewModel.GameStatusVisible),
                                            converter: new Converters.BooleanToVisibilityConverter());
                    BindingTools.SetBinding(ElemGameStatus,
                                            FrameworkElement.DataContextProperty,
                                            mainModel,
                                            nameof(FullscreenAppViewModel.SelectedGame));
                }

                SetListCommandBindings();

                ControlTemplateTools.InitializePluginControls(
                    mainModel.Extensions,
                    Template,
                    this,
                    ApplicationMode.Fullscreen,
                    mainModel,
                    $"{nameof(FullscreenAppViewModel.SelectedGameDetails)}.{nameof(GameDetailsViewModel.Game)}.{nameof(GameDetailsViewModel.Game.Game)}");
            }
        }
Exemple #6
0
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            if (Template != null)
            {
                MenuHost = Template.FindName("PART_MenuHost", this) as FrameworkElement;
                if (MenuHost != null)
                {
                    MenuHost.InputBindings.Add(new KeyBinding(mainModel.CloseAdditionalFiltersCommand, new KeyGesture(Key.Back)));
                    MenuHost.InputBindings.Add(new KeyBinding(mainModel.CloseAdditionalFiltersCommand, new KeyGesture(Key.Escape)));
                    MenuHost.InputBindings.Add(new KeyBinding()
                    {
                        Command = mainModel.ToggleFiltersCommand, Key = Key.F
                    });
                    MenuHost.InputBindings.Add(new XInputBinding(mainModel.CloseAdditionalFiltersCommand, XInputButton.B));
                }

                ButtonBack = Template.FindName("PART_ButtonBack", this) as ButtonBase;
                if (ButtonBack != null)
                {
                    ButtonBack.Command = mainModel.CloseAdditionalFiltersCommand;
                    BindingTools.SetBinding(ButtonBack,
                                            FocusBahaviors.FocusBindingProperty,
                                            mainModel,
                                            nameof(mainModel.FilterAdditionalPanelVisible));
                }

                ItemsHost = Template.FindName("PART_ItemsHost", this) as ItemsControl;
                if (ItemsHost != null)
                {
                    XNamespace pns = "http://schemas.microsoft.com/winfx/2006/xaml/presentation";
                    ItemsHost.ItemsPanel = Xaml.FromString <ItemsPanelTemplate>(new XDocument(
                                                                                    new XElement(pns + nameof(ItemsPanelTemplate),
                                                                                                 new XElement(pns + nameof(VirtualizingStackPanel)))
                                                                                    ).ToString());
                    ItemsHost.Template = Xaml.FromString <ControlTemplate>(new XDocument(
                                                                               new XElement(pns + nameof(ControlTemplate),
                                                                                            new XElement(pns + nameof(ScrollViewer),
                                                                                                         new XAttribute(nameof(ScrollViewer.Focusable), false),
                                                                                                         new XAttribute(nameof(ScrollViewer.HorizontalScrollBarVisibility), ScrollBarVisibility.Disabled),
                                                                                                         new XAttribute(nameof(ScrollViewer.VerticalScrollBarVisibility), ScrollBarVisibility.Auto),
                                                                                                         new XAttribute(nameof(ScrollViewer.CanContentScroll), true),
                                                                                                         new XElement(pns + nameof(ItemsPresenter))))
                                                                               ).ToString());

                    AssignFilter("LOCGenreLabel", "PART_ButtonGenre", GameField.Genres, nameof(FilterSettings.Genre));
                    AssignFilter("LOCGameReleaseYearTitle", "PART_ButtonReleaseYear", GameField.ReleaseYear, nameof(FilterSettings.ReleaseYear));
                    AssignFilter("LOCDeveloperLabel", "PART_ButtonDeveloper", GameField.Developers, nameof(FilterSettings.Developer));
                    AssignFilter("LOCPublisherLabel", "PART_ButtonPublisher", GameField.Publishers, nameof(FilterSettings.Publisher));
                    AssignFilter("LOCFeatureLabel", "PART_ButtonFeature", GameField.Features, nameof(FilterSettings.Feature));
                    AssignFilter("LOCTagLabel", "PART_ButtonTag", GameField.Tags, nameof(FilterSettings.Tag));
                    AssignFilter("LOCTimePlayed", "PART_ButtonPlayTime", GameField.Playtime, nameof(FilterSettings.PlayTime));
                    AssignFilter("LOCCompletionStatus", "PART_ButtonCompletionStatus", GameField.CompletionStatus, nameof(FilterSettings.CompletionStatuses));
                    AssignFilter("LOCSeriesLabel", "PART_ButtonSeries", GameField.Series, nameof(FilterSettings.Series));
                    AssignFilter("LOCRegionLabel", "PART_ButtonRegion", GameField.Regions, nameof(FilterSettings.Region));
                    AssignFilter("LOCSourceLabel", "PART_ButtonSource", GameField.Source, nameof(FilterSettings.Source));
                    AssignFilter("LOCAgeRatingLabel", "PART_ButtonAgeRating", GameField.AgeRatings, nameof(FilterSettings.AgeRating));
                    AssignFilter("LOCUserScore", "PART_ButtonUserScore", GameField.UserScore, nameof(FilterSettings.UserScore));
                    AssignFilter("LOCCommunityScore", "PART_ButtonCommunityScore", GameField.CommunityScore, nameof(FilterSettings.CommunityScore));
                    AssignFilter("LOCCriticScore", "PART_ButtonCriticScore", GameField.CriticScore, nameof(FilterSettings.CriticScore));
                    AssignFilter("LOCGameLastActivityTitle", "PART_ButtonLastActivity", GameField.LastActivity, nameof(FilterSettings.LastActivity));
                    AssignFilter("LOCAddedLabel", "PART_ButtonAdded", GameField.Added, nameof(FilterSettings.Added));
                    AssignFilter("LOCModifiedLabel", "PART_ButtonModified", GameField.Modified, nameof(FilterSettings.Modified));
                }
            }
        }