예제 #1
0
        private static void IsValidChangedCallback(DependencyObject obj, DependencyPropertyChangedEventArgs e)
        {
            if (!GetIsEnabled(obj))
            {
                throw new InvalidOperationException("The IsValid attached property can only be used when the IsEnabled "
                                                    + "attached property is set to true.");
            }

            Binding binding = BindingOperations.GetBinding(obj, IsValidProperty);

            if (binding != null)
            {
                CheckBindingMode(binding.Mode);
                return;
            }

            MultiBinding multiBinding = BindingOperations.GetMultiBinding(obj, IsValidProperty);

            if (multiBinding != null)
            {
                CheckBindingMode(multiBinding.Mode);
                return;
            }

            PriorityBinding priorityBinding = BindingOperations.GetPriorityBinding(obj, IsValidProperty);

            if (priorityBinding != null)
            {
                throw new InvalidOperationException("PriorityBinding is not supported for the IsValid attached dependency property!");
            }
        }
예제 #2
0
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            //Reset TabHeaderItemsControl.ItemsSource from default
            if (GetTemplateChild("TabHeaderItemsControl") is RibbonTabHeaderItemsControl tabHeaderItemsControl)
            {
                var binding = new PriorityBinding
                {
                    Bindings =
                    {
                        new Binding
                        {
                            Source = tabHeaderItemsControl.ItemsSource
                        },
                        new Binding
                        {
                            Source = this,
                            Path   = new PropertyPath(ItemsSourceProperty)
                        }
                    }
                };
                tabHeaderItemsControl.SetBinding(ItemsSourceProperty, binding);
            }
        }
예제 #3
0
        // Token: 0x060048DD RID: 18653 RVA: 0x0014AB24 File Offset: 0x00148D24
        internal static bool IsOneWay(BindingBase bindingBase)
        {
            if (bindingBase == null)
            {
                return(false);
            }
            Binding binding = bindingBase as Binding;

            if (binding != null)
            {
                return(binding.Mode == BindingMode.OneWay);
            }
            MultiBinding multiBinding = bindingBase as MultiBinding;

            if (multiBinding != null)
            {
                return(multiBinding.Mode == BindingMode.OneWay);
            }
            PriorityBinding priorityBinding = bindingBase as PriorityBinding;

            if (priorityBinding != null)
            {
                Collection <BindingBase> bindings = priorityBinding.Bindings;
                int count = bindings.Count;
                for (int i = 0; i < count; i++)
                {
                    if (DataGridHelper.IsOneWay(bindings[i]))
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
예제 #4
0
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            ImageCover = Template.FindName("PART_ImageCover", this) as Image;
            if (ImageCover != null)
            {
                var sourceBinding = new PriorityBinding();
                sourceBinding.Bindings.Add(new Binding()
                {
                    Path      = new PropertyPath(nameof(GamesCollectionViewEntry.FullscreenListItemCoverObject)),
                    IsAsync   = mainModel.AppSettings.Fullscreen.AsyncImageLoading,
                    Converter = new NullToDependencyPropertyUnsetConverter(),
                    Mode      = BindingMode.OneWay
                });
                sourceBinding.Bindings.Add(new Binding()
                {
                    Path      = new PropertyPath(nameof(GamesCollectionViewEntry.DefaultFullscreenListItemCoverObject)),
                    Converter = new NullToDependencyPropertyUnsetConverter(),
                    Mode      = BindingMode.OneWay
                });

                BindingOperations.SetBinding(ImageCover, Image.SourceProperty, sourceBinding);
            }

            ControlTemplateTools.InitializePluginControls(
                mainModel.Extensions,
                Template,
                this,
                ApplicationMode.Fullscreen,
                this,
                $"DataContext.{nameof(GamesCollectionViewEntry.Game)}");
        }
예제 #5
0
 /// <summary>
 /// Updates the priority binding.
 /// </summary>
 /// <param name="target">The target.</param>
 /// <param name="dependencyProperty">The dependency property.</param>
 /// <param name="priorityBinding">The priority binding.</param>
 private static void UpdatePriorityBinding([NotNull] this DependencyObject target, [NotNull] DependencyProperty dependencyProperty,
                                           [NotNull] PriorityBinding priorityBinding)
 {
     foreach (var binding in priorityBinding.Bindings)
     {
         target.UpdateBindingBase(dependencyProperty, binding);
     }
 }
예제 #6
0
 static BindingBase Load(string value)
 {
     return(XamlReader.Load(XmlReader.Create(new StringReader(value))) switch
     {
         null => throw new ArgumentNullException("Binding could not be cloned via Xaml Serialization Stack."),
         Binding newBinding => newBinding,
         MultiBinding newBinding => newBinding,
         PriorityBinding newBinding => newBinding,
         _ => throw new InvalidOperationException("Binding could not be cast.")
     });
예제 #7
0
        private void GetBindingSourcesRecursive(string propertyName, DependencyObject root, List <object> sources)
        {
            List <BindingBase>  bindings  = DependencyObjectHelper.GetBindingObjects(root);
            Predicate <Binding> condition =
                (b) =>
            {
                return((b.Path is PropertyPath) &&
                       b.Path.Path == propertyName &&
                       (!sources.Contains(root)));
            };

            foreach (BindingBase bindingBase in bindings)
            {
                if (bindingBase is Binding)
                {
                    if (condition(bindingBase as Binding))
                    {
                        sources.Add(root);
                    }
                }
                else if (bindingBase is MultiBinding)
                {
                    MultiBinding mb = bindingBase as MultiBinding;
                    foreach (Binding b in mb.Bindings)
                    {
                        if (condition(bindingBase as Binding))
                        {
                            sources.Add(root);
                        }
                    }
                }
                else if (bindingBase is PriorityBinding)
                {
                    PriorityBinding pb = bindingBase as PriorityBinding;
                    foreach (Binding b in pb.Bindings)
                    {
                        if (condition(bindingBase as Binding))
                        {
                            sources.Add(root);
                        }
                    }
                }
            }

            int childrenCount = VisualTreeHelper.GetChildrenCount(root);

            if (childrenCount > 0)
            {
                for (int i = 0; i < childrenCount; i++)
                {
                    DependencyObject child = VisualTreeHelper.GetChild(root, i);
                    GetBindingSourcesRecursive(propertyName, child, sources);
                }
            }
        }
예제 #8
0
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();
            if (Template == null)
            {
                return;
            }

            ViewHost = Template.FindName("PART_ViewHost", this) as FrameworkElement;
            if (ViewHost != null)
            {
                BindingTools.SetBinding(ViewHost,
                                        FocusBahaviors.FocusBindingProperty,
                                        mainModel,
                                        nameof(mainModel.GameStatusVisible));
            }

            PanelActionButtons = Template.FindName("PART_PanelActionButtons", this) as Panel;
            if (PanelActionButtons != null)
            {
                var buttonClose = new ButtonEx();
                buttonClose.Content = ResourceProvider.GetString(LOC.CloseLabel);
                buttonClose.SetResourceReference(ButtonEx.StyleProperty, "ButtonGameStatusAction");
                buttonClose.Command = mainModel.CloseGameStatusCommand;
                PanelActionButtons.Children.Add(buttonClose);
            }

            TextStatus = Template.FindName("PART_TextStatus", this) as TextBlock;
            if (TextStatus != null)
            {
                BindingTools.SetBinding(TextStatus,
                                        TextBlock.TextProperty,
                                        mainModel,
                                        nameof(mainModel.GameStatusText));
            }

            ImageCover = Template.FindName("PART_ImageCover", this) as Image;
            if (ImageCover != null)
            {
                var sourceBinding = new PriorityBinding();
                sourceBinding.Bindings.Add(new Binding()
                {
                    Path      = new PropertyPath(nameof(GamesCollectionViewEntry.CoverImageObject)),
                    Converter = new NullToDependencyPropertyUnsetConverter()
                });
                sourceBinding.Bindings.Add(new Binding()
                {
                    Path      = new PropertyPath(nameof(GamesCollectionViewEntry.DefaultCoverImageObject)),
                    Converter = new NullToDependencyPropertyUnsetConverter()
                });

                BindingOperations.SetBinding(ImageCover, Image.SourceProperty, sourceBinding);
            }
        }
예제 #9
0
        public void IsValidTest_PriorityBinding()
        {
            var view      = new PersonView();
            var viewModel = new PersonViewModel(view);

            ValidationHelper.SetIsEnabled(view, true);

            PriorityBinding binding = new PriorityBinding();

            binding.Bindings.Add(new Binding("IsValid"));
            BindingOperations.SetBinding(view, ValidationHelper.IsValidProperty, binding);
        }
예제 #10
0
        internal static void EnsureTwoWay(BindingBase bindingBase)
        {
            if (bindingBase == null)
            {
                return;
            }

            // If it is a standard Binding, then set the mode to TwoWay
            Binding binding = bindingBase as Binding;

            if (binding != null)
            {
                if (binding.Mode != BindingMode.TwoWay)
                {
                    binding.Mode = BindingMode.TwoWay;
                    binding.UpdateSourceTrigger = UpdateSourceTrigger.Explicit;
                }

                return;
            }

            // A multi-binding can be set to TwoWay as well
            MultiBinding multiBinding = bindingBase as MultiBinding;

            if (multiBinding != null)
            {
                if (multiBinding.Mode != BindingMode.TwoWay)
                {
                    multiBinding.Mode = BindingMode.TwoWay;
                    multiBinding.UpdateSourceTrigger = UpdateSourceTrigger.Explicit;
                }

                return;
            }

            // A priority binding is a list of bindings, each should be set to TwoWay
            PriorityBinding priBinding = bindingBase as PriorityBinding;

            if (priBinding != null)
            {
                Collection <BindingBase> subBindings = priBinding.Bindings;
                int count = subBindings.Count;
                for (int i = 0; i < count; i++)
                {
                    EnsureTwoWay(subBindings[i]);
                }
            }
        }
        Style CreateStyle()
        {
            var style = new Style();

            var multibinding = new PriorityBinding();

            multibinding.Bindings.Add(new Binding("FirstName"));
            multibinding.Bindings.Add(new Binding("LstName")); //purposefully misspelled

            var trigger = new DataTrigger();

            trigger.Binding = multibinding;
            trigger.Value   = "Rob Eisenberg";

            style.Triggers.Add(trigger);

            return(style);
        }
        Style CreateStyle()
        {
            var style = new Style();

            var priorityBinding = new PriorityBinding();

            priorityBinding.Bindings.Add(new Binding("FirstName"));
            priorityBinding.Bindings.Add(new Binding("LstName")); //purposefully misspelled

            style.Setters.Add(
                new Setter(
                    TextBlock.FontFamilyProperty,
                    priorityBinding
                    )
                );

            return(style);
        }
예제 #13
0
        private void findPath_Click(object sender, RoutedEventArgs e)
        {
            PriorityBinding priorityBinding = new PriorityBinding {
                FallbackValue = "0"
            };
            Binding superPrecise = new Binding("SuperPrecise")
            {
                IsAsync = true
            };
            Binding precise = new Binding("Precise")
            {
                IsAsync = true
            };
            Binding regular = new Binding("Regular")
            {
                IsAsync = true
            };
            Binding quick = new Binding("Quick")
            {
                IsAsync = true
            };
            Binding superQuick = new Binding("SuperQuick");

            priorityBinding.Bindings.Add(superPrecise);
            priorityBinding.Bindings.Add(precise);
            priorityBinding.Bindings.Add(regular);
            priorityBinding.Bindings.Add(quick);
            priorityBinding.Bindings.Add(superQuick);
            textBox.SetBinding(TextBox.TextProperty, priorityBinding);


            /*
             * if (image.Source == null) return;
             * System.Drawing.Bitmap b = new System.Drawing.Bitmap(BitmapImage2Bitmap(image.Source as BitmapImage));
             * PathFinder.PathFinder pF = new PathFinder.PathFinder(b);
             * IList<PathFinder.PathSegment> pathList = pF.FindPath(new System.Drawing.Point(0,0), new System.Drawing.Point(200, 200), PathFinder.PathFindingPrecision.SuperQuick);
             * double length = 0;
             * foreach (var p in pathList)
             * {
             *  length += p.Length;
             * }
             * textBox.Text = length.ToString();
             */
        }
        public SimpleUIWithPriorityBinding()
        {
            var stack = new StackPanel();

            Content = stack;

            var priorityBinding = new PriorityBinding();

            priorityBinding.Bindings.Add(new Binding("FirstName"));
            priorityBinding.Bindings.Add(new Binding("LstName")); //purposefully misspelled

            var textBlock = new TextBlock();

            textBlock.SetBinding(TextBlock.TextProperty, priorityBinding);
            stack.Children.Add(textBlock);

            textBlock = new TextBlock();
            textBlock.SetBinding(TextBlock.TextProperty, new Binding("Age"));
            stack.Children.Add(textBlock);
        }
예제 #15
0
        /// <summary>
        ///     Returns true if the binding (or any part of it) is OneWay.
        /// </summary>
        internal static bool IsOneWay(BindingBase bindingBase)
        {
            if (bindingBase == null)
            {
                return(false);
            }

            // If it is a standard Binding, then check if it's Mode is OneWay
            Binding binding = bindingBase as Binding;

            if (binding != null)
            {
                return(binding.Mode == BindingMode.OneWay);
            }

            // A multi-binding can be OneWay as well
            MultiBinding multiBinding = bindingBase as MultiBinding;

            if (multiBinding != null)
            {
                return(multiBinding.Mode == BindingMode.OneWay);
            }

            // A priority binding is a list of bindings, if any are OneWay, we'll call it OneWay
            PriorityBinding priBinding = bindingBase as PriorityBinding;

            if (priBinding != null)
            {
                Collection <BindingBase> subBindings = priBinding.Bindings;
                int count = subBindings.Count;
                for (int i = 0; i < count; i++)
                {
                    if (IsOneWay(subBindings[i]))
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
예제 #16
0
        public static PriorityBinding Clone(PriorityBinding original)
        {
            if (original == null)
            {
                throw new ArgumentNullException("original");
            }

            var t    = original;
            var bind = new PriorityBinding()
            {
                BindingGroupName = t.BindingGroupName,
                FallbackValue    = t.FallbackValue,
                StringFormat     = t.StringFormat,
                TargetNullValue  = t.TargetNullValue
            };

            for (int i = 0; i < t.Bindings.Count; i++)
            {
                bind.Bindings.Add(Clone(t.Bindings[i]));
            }

            return(bind);
        }
예제 #17
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));
        }
예제 #18
0
        /// <summary>
        ///     Ensures that the given binding is two way if it's not already OneWay.
        ///     The default Mode is BindingMode.Default which will become effectively OneWay
        ///     or TwoWay based on the property being bound to.  We ensure it's TwoWay & Explicit
        ///     to make sure it shows up in the bindingGroup, however this causes problems for
        ///     read-only properties, so we dont touch them.
        /// </summary>
        internal static void EnsureTwoWayIfNotOneWay(BindingBase bindingBase)
        {
            if (bindingBase == null)
            {
                return;
            }

            // If it is a standard Binding, then set the mode to TwoWay
            Binding binding = bindingBase as Binding;

            if (binding != null)
            {
                if (binding.Mode != BindingMode.OneWay)
                {
                    if (binding.Mode != BindingMode.TwoWay)
                    {
                        binding.Mode = BindingMode.TwoWay;
                    }

                    // Be careful not to modify bindings that we've already used.  We have no way to know this exactly,
                    // because that information is private, but we can avoid changing something that we've already changed.
                    if (binding.UpdateSourceTrigger != UpdateSourceTrigger.Explicit)
                    {
                        binding.UpdateSourceTrigger = UpdateSourceTrigger.Explicit;
                    }
                }

                return;
            }

            // A multi-binding can be set to TwoWay as well
            MultiBinding multiBinding = bindingBase as MultiBinding;

            if (multiBinding != null)
            {
                if (multiBinding.Mode != BindingMode.OneWay)
                {
                    if (multiBinding.Mode != BindingMode.TwoWay)
                    {
                        multiBinding.Mode = BindingMode.TwoWay;
                    }

                    // Be careful not to modify bindings that we've already used.  We have no way to know this exactly,
                    // because that information is private, but we can avoid changing something that we've already changed.
                    if (multiBinding.UpdateSourceTrigger != UpdateSourceTrigger.Explicit)
                    {
                        multiBinding.UpdateSourceTrigger = UpdateSourceTrigger.Explicit;
                    }
                }

                return;
            }

            // A priority binding is a list of bindings, each should be set to TwoWay
            PriorityBinding priBinding = bindingBase as PriorityBinding;

            if (priBinding != null)
            {
                Collection <BindingBase> subBindings = priBinding.Bindings;
                int count = subBindings.Count;
                for (int i = 0; i < count; i++)
                {
                    EnsureTwoWayIfNotOneWay(subBindings[i]);
                }
            }
        }
예제 #19
0
        private BindingBase CreateHexTileBackgroundBinding(HexTile tile)
        {
            var baseBinding = new PriorityBinding();

            if (tile != null)
            {
                BindingBase bind;

                bind = TryCreateHighQualityBinding(this, tile.TileType.ToString() + tile.CustomTileType + tile.TileVariant + "TileBackground");
                if (bind != null)
                {
                    baseBinding.Bindings.Add(bind);
                }

                bind = TryCreateBinding(this, tile.TileType.ToString() + tile.CustomTileType + tile.TileVariant + "TileBackground");
                if (bind != null)
                {
                    baseBinding.Bindings.Add(bind);
                }

                bind = TryCreateHighQualityBinding(this, tile.TileType.ToString() + tile.CustomTileType + "TileBackground");
                if (bind != null)
                {
                    baseBinding.Bindings.Add(bind);
                }

                bind = TryCreateBinding(this, tile.TileType.ToString() + tile.CustomTileType + "TileBackground");
                if (bind != null)
                {
                    baseBinding.Bindings.Add(bind);
                }

                bind = TryCreateHighQualityBinding(this, tile.TileType.ToString() + "TileBackground");
                if (bind != null)
                {
                    baseBinding.Bindings.Add(bind);
                }

                bind = TryCreateBinding(this, tile.TileType.ToString() + "TileBackground");
                if (bind != null)
                {
                    baseBinding.Bindings.Add(bind);
                }

                bind = TryCreateHighQualityBinding(this, "TileBackground");
                if (bind != null)
                {
                    baseBinding.Bindings.Add(bind);
                }

                bind = TryCreateBinding(this, "TileBackground");
                if (bind != null)
                {
                    baseBinding.Bindings.Add(bind);
                }
            }

            baseBinding.Bindings.Add(new Binding {
                Source = Brushes.Red
            });
            //baseBinding.FallbackValue = Brushes.Transparent;

            return(baseBinding);
        }
예제 #20
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.ToggleGameDetailsCommand, Key = Key.Back
                    });
                    ViewHost.InputBindings.Add(new KeyBinding()
                    {
                        Command = mainModel.ToggleGameDetailsCommand, Key = Key.Escape
                    });
                    ViewHost.InputBindings.Add(new KeyBinding()
                    {
                        Command = mainModel.SelectPrevGameCommand, Key = Key.F2
                    });
                    ViewHost.InputBindings.Add(new KeyBinding()
                    {
                        Command = mainModel.SelectNextGameCommand, Key = Key.F3
                    });
                    ViewHost.InputBindings.Add(new XInputBinding(mainModel.ToggleGameDetailsCommand, XInputButton.B));
                    ViewHost.InputBindings.Add(new XInputBinding(mainModel.SelectPrevGameCommand, XInputButton.LeftShoulder));
                    ViewHost.InputBindings.Add(new XInputBinding(mainModel.SelectNextGameCommand, XInputButton.RightShoulder));

                    BindingTools.SetBinding(ViewHost,
                                            FocusBahaviors.FocusBindingProperty,
                                            mainModel,
                                            nameof(mainModel.GameDetailsFocused));
                }

                ButtonContext = Template.FindName("PART_ButtonContext", this) as ButtonBase;
                if (ButtonContext != null)
                {
                    BindingTools.SetBinding(
                        ButtonContext,
                        ButtonBase.CommandProperty,
                        mainModel,
                        $"{nameof(mainModel.SelectedGameDetails)}.{nameof(mainModel.SelectedGameDetails.ContextActionCommand)}");
                    BindingTools.SetBinding(
                        ButtonContext,
                        ButtonBase.ContentProperty,
                        mainModel,
                        $"{nameof(mainModel.SelectedGameDetails)}.{nameof(mainModel.SelectedGameDetails.ContextActionDescription)}");
                }

                ButtonOptions = Template.FindName("PART_ButtonOptions", this) as ButtonBase;
                if (ButtonOptions != null)
                {
                    ButtonOptions.Command = mainModel.ToggleGameOptionsCommand;
                }

                ImageCover = Template.FindName("PART_ImageCover", this) as Image;
                if (ImageCover != null)
                {
                    var sourceBinding = new PriorityBinding();
                    sourceBinding.Bindings.Add(new Binding()
                    {
                        Path      = new PropertyPath(nameof(GamesCollectionViewEntry.CoverImageObject)),
                        Converter = new NullToDependencyPropertyUnsetConverter()
                    });
                    sourceBinding.Bindings.Add(new Binding()
                    {
                        Path      = new PropertyPath(nameof(GamesCollectionViewEntry.DefaultCoverImageObject)),
                        Converter = new NullToDependencyPropertyUnsetConverter()
                    });

                    BindingOperations.SetBinding(ImageCover, Image.SourceProperty, sourceBinding);
                }

                ImageBackground = Template.FindName("PART_ImageBackground", this) as FadeImage;
                if (ImageBackground != null)
                {
                    BindingTools.SetBinding(ImageBackground,
                                            FadeImage.SourceProperty,
                                            nameof(GamesCollectionViewEntry.DisplayBackgroundImage));
                }
            }
        }
예제 #21
0
        public BindingBase CloneBinding(BindingBase bindingBase, object source, bool isNumber = false)
        {
            var binding = bindingBase as Binding;

            if (binding != null)
            {
                var result = new Binding
                {
                    //Source = source,
                    //AsyncState = binding.AsyncState,
                    //BindingGroupName = binding.BindingGroupName,
                    BindsDirectlyToSource = binding.BindsDirectlyToSource,
                    Converter             = binding.Converter,
                    ConverterCulture      = binding.ConverterCulture,
                    ConverterParameter    = binding.ConverterParameter,
                    //ElementName = binding.ElementName,
                    FallbackValue           = binding.FallbackValue,
                    IsAsync                 = binding.IsAsync,
                    Mode                    = binding.Mode,
                    NotifyOnSourceUpdated   = binding.NotifyOnSourceUpdated,
                    NotifyOnTargetUpdated   = binding.NotifyOnTargetUpdated,
                    NotifyOnValidationError = binding.NotifyOnValidationError,
                    Path                    = binding.Path,
                    //RelativeSource = binding.RelativeSource,
                    StringFormat                = binding.StringFormat,
                    TargetNullValue             = binding.TargetNullValue,
                    UpdateSourceExceptionFilter = binding.UpdateSourceExceptionFilter,
                    UpdateSourceTrigger         = binding.UpdateSourceTrigger,
                    ValidatesOnDataErrors       = binding.ValidatesOnDataErrors,
                    ValidatesOnExceptions       = binding.ValidatesOnExceptions,
                    XPath = binding.XPath,
                };
                if (!isNumber)
                {
                    result.Source = source;
                }
                foreach (var validationRule in binding.ValidationRules)
                {
                    result.ValidationRules.Add(validationRule);
                }

                return(result);
            }

            var multiBinding = bindingBase as MultiBinding;

            if (multiBinding != null)
            {
                var result = new MultiBinding
                {
                    BindingGroupName   = multiBinding.BindingGroupName,
                    Converter          = multiBinding.Converter,
                    ConverterCulture   = multiBinding.ConverterCulture,
                    ConverterParameter = multiBinding.ConverterParameter,
                    FallbackValue      = multiBinding.FallbackValue,
                    Mode = multiBinding.Mode,
                    NotifyOnSourceUpdated       = multiBinding.NotifyOnSourceUpdated,
                    NotifyOnTargetUpdated       = multiBinding.NotifyOnTargetUpdated,
                    NotifyOnValidationError     = multiBinding.NotifyOnValidationError,
                    StringFormat                = multiBinding.StringFormat,
                    TargetNullValue             = multiBinding.TargetNullValue,
                    UpdateSourceExceptionFilter = multiBinding.UpdateSourceExceptionFilter,
                    UpdateSourceTrigger         = multiBinding.UpdateSourceTrigger,
                    ValidatesOnDataErrors       = multiBinding.ValidatesOnDataErrors,
                    ValidatesOnExceptions       = multiBinding.ValidatesOnDataErrors,
                };

                foreach (var validationRule in multiBinding.ValidationRules)
                {
                    result.ValidationRules.Add(validationRule);
                }

                foreach (var childBinding in multiBinding.Bindings)
                {
                    result.Bindings.Add(CloneBinding(childBinding, source));
                }

                return(result);
            }

            var priorityBinding = bindingBase as PriorityBinding;

            if (priorityBinding != null)
            {
                var result = new PriorityBinding
                {
                    BindingGroupName = priorityBinding.BindingGroupName,
                    FallbackValue    = priorityBinding.FallbackValue,
                    StringFormat     = priorityBinding.StringFormat,
                    TargetNullValue  = priorityBinding.TargetNullValue,
                };

                foreach (var childBinding in priorityBinding.Bindings)
                {
                    result.Bindings.Add(CloneBinding(childBinding, source));
                }

                return(result);
            }

            throw new NotSupportedException("Failed to clone binding");
        }
예제 #22
0
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            PanelHost = Template.FindName("PART_PanelHost", this) as FrameworkElement;
            if (PanelHost != null)
            {
                var mBinding = new MouseBinding(mainModel.StartGameCommand, new MouseGesture(MouseAction.LeftDoubleClick));
                BindingTools.SetBinding(mBinding,
                                        MouseBinding.CommandParameterProperty,
                                        nameof(GamesCollectionViewEntry.Game));
                PanelHost.InputBindings.Add(mBinding);

                if (!DesignerProperties.GetIsInDesignMode(this))
                {
                    PanelHost.ContextMenu = new GameMenu(mainModel)
                    {
                        ShowStartSection = true
                    };
                    BindingTools.SetBinding(PanelHost.ContextMenu,
                                            Button.DataContextProperty,
                                            mainModel,
                                            nameof(DesktopAppViewModel.SelectedGames));
                }
            }

            ImageIcon = Template.FindName("PART_ImageIcon", this) as Image;
            if (ImageIcon != null)
            {
                BindingTools.SetBinding(ImageIcon,
                                        Image.VisibilityProperty,
                                        mainModel.AppSettings,
                                        nameof(PlayniteSettings.ShowIconsOnList),
                                        converter: new BooleanToVisibilityConverter());

                var sourceBinding = new PriorityBinding();
                sourceBinding.Bindings.Add(new Binding()
                {
                    Path      = new PropertyPath(nameof(GamesCollectionViewEntry.DetailsListIconObjectCached)),
                    IsAsync   = mainModel.AppSettings.AsyncImageLoading,
                    Converter = new NullToDependencyPropertyUnsetConverter(),
                    Mode      = BindingMode.OneWay
                });
                sourceBinding.Bindings.Add(new Binding()
                {
                    Path      = new PropertyPath(nameof(GamesCollectionViewEntry.DefaultDetailsListIconObjectCached)),
                    Converter = new NullToDependencyPropertyUnsetConverter(),
                    Mode      = BindingMode.OneWay
                });

                BindingOperations.SetBinding(ImageIcon, Image.SourceProperty, sourceBinding);
            }

            ImageCover = Template.FindName("PART_ImageCover", this) as Image;
            if (ImageCover != null)
            {
                var sourceBinding = new PriorityBinding();
                sourceBinding.Bindings.Add(new Binding()
                {
                    Path      = new PropertyPath(nameof(GamesCollectionViewEntry.GridViewCoverObjectCached)),
                    IsAsync   = mainModel.AppSettings.AsyncImageLoading,
                    Converter = new NullToDependencyPropertyUnsetConverter(),
                    Mode      = BindingMode.OneWay
                });
                sourceBinding.Bindings.Add(new Binding()
                {
                    Path      = new PropertyPath(nameof(GamesCollectionViewEntry.DefaultGridViewCoverObjectCached)),
                    Converter = new NullToDependencyPropertyUnsetConverter(),
                    Mode      = BindingMode.OneWay
                });

                BindingOperations.SetBinding(ImageCover, Image.SourceProperty, sourceBinding);
            }

            ButtonPlay = Template.FindName("PART_ButtonPlay", this) as Button;
            if (ButtonPlay != null)
            {
                ButtonPlay.Command = mainModel.StartGameCommand;
                BindingTools.SetBinding(ButtonPlay,
                                        Button.CommandParameterProperty,
                                        nameof(GamesCollectionViewEntry.Game));
            }

            ButtonInfo = Template.FindName("PART_ButtonInfo", this) as Button;
            if (ButtonInfo != null)
            {
                ButtonInfo.Command = mainModel.ShowGameSideBarCommand;
                BindingTools.SetBinding(ButtonInfo,
                                        Button.CommandParameterProperty,
                                        string.Empty);
            }
        }
예제 #23
0
        /// <summary>
        /// Copies a <see cref="BindingBase"/>
        /// </summary>
        /// <param name="bindingBase">The binding to clone</param>
        /// <returns>A new instance of <typeparam name="T"></typeparam></returns>
        public static T Clone <T>(this T bindingBase) where T : BindingBase
        {
            var binding = bindingBase as Binding;

            if (binding != null)
            {
                var result = new Binding
                {
                    Source             = null,
                    Converter          = binding.Converter,
                    ConverterParameter = binding.ConverterParameter,
                    FallbackValue      = binding.FallbackValue,
                    Mode                = binding.Mode,
                    Path                = binding.Path,
                    TargetNullValue     = binding.TargetNullValue,
                    UpdateSourceTrigger = binding.UpdateSourceTrigger,
#if WINDOWS_UWP
                    ConverterLanguage = binding.ConverterLanguage
#else
                    AsyncState            = binding.AsyncState,
                    BindingGroupName      = binding.BindingGroupName,
                    BindsDirectlyToSource = binding.BindsDirectlyToSource,
                    ConverterCulture      = binding.ConverterCulture,
                    IsAsync = binding.IsAsync,
                    NotifyOnSourceUpdated       = binding.NotifyOnSourceUpdated,
                    NotifyOnTargetUpdated       = binding.NotifyOnTargetUpdated,
                    NotifyOnValidationError     = binding.NotifyOnValidationError,
                    StringFormat                = binding.StringFormat,
                    UpdateSourceExceptionFilter = binding.UpdateSourceExceptionFilter,
                    ValidatesOnDataErrors       = binding.ValidatesOnDataErrors,
                    ValidatesOnExceptions       = binding.ValidatesOnExceptions,
                    XPath = binding.XPath,
#endif
                };

#if !WINDOWS_UWP
                foreach (var validationRule in binding.ValidationRules)
                {
                    result.ValidationRules.Add(validationRule);
                }
#endif

                return(result as T);
            }

#if !WINDOWS_UWP // No MultiBinding and PriorityBinding in UWP
            var multiBinding = bindingBase as MultiBinding;
            if (multiBinding != null)
            {
                var result = new MultiBinding
                {
                    BindingGroupName   = multiBinding.BindingGroupName,
                    Converter          = multiBinding.Converter,
                    ConverterCulture   = multiBinding.ConverterCulture,
                    ConverterParameter = multiBinding.ConverterParameter,
                    FallbackValue      = multiBinding.FallbackValue,
                    Mode = multiBinding.Mode,
                    NotifyOnSourceUpdated       = multiBinding.NotifyOnSourceUpdated,
                    NotifyOnTargetUpdated       = multiBinding.NotifyOnTargetUpdated,
                    NotifyOnValidationError     = multiBinding.NotifyOnValidationError,
                    StringFormat                = multiBinding.StringFormat,
                    TargetNullValue             = multiBinding.TargetNullValue,
                    UpdateSourceExceptionFilter = multiBinding.UpdateSourceExceptionFilter,
                    UpdateSourceTrigger         = multiBinding.UpdateSourceTrigger,
                    ValidatesOnDataErrors       = multiBinding.ValidatesOnDataErrors,
                    ValidatesOnExceptions       = multiBinding.ValidatesOnDataErrors,
                };

                foreach (var validationRule in multiBinding.ValidationRules)
                {
                    result.ValidationRules.Add(validationRule);
                }

                return(result as T);
            }

            var priorityBinding = bindingBase as PriorityBinding;
            if (priorityBinding != null)
            {
                var result = new PriorityBinding
                {
                    BindingGroupName = priorityBinding.BindingGroupName,
                    FallbackValue    = priorityBinding.FallbackValue,
                    StringFormat     = priorityBinding.StringFormat,
                    TargetNullValue  = priorityBinding.TargetNullValue,
                };

                foreach (var childBinding in priorityBinding.Bindings)
                {
                    result.Bindings.Add(childBinding.Clone());
                }

                return(result as T);
            }
#endif
            return(null);
        }