예제 #1
0
        public void InitControl()
        {
            foreach (var star in StarList)
            {
                var behavior = (StarBehavior)star.Behaviors[0];
                behavior.PropertyChanged -= RatingchangedEvent;
                star.Behaviors.Remove(behavior);
                Children.Remove(star);
            }

            for (int x = 0; x < this.Count; x++)
            {
                var behavior = new StarBehavior()
                {
                    GroupName = "starGrouping"
                };
                behavior.Index = (x + 1);
                var gd            = new Grid();
                var unSelectedImg = new Image();
                unSelectedImg.SetBinding(Image.SourceProperty, new Binding(source: this, path: "UnSelectedImage"));
                var selectedImg = new Image();
                selectedImg.SetBinding(Image.SourceProperty, new Binding(source: this, path: "SelectedImage"));
                selectedImg.SetBinding(Image.IsVisibleProperty, new Binding(source: behavior, path: "IsStarred"));
                gd.Children.Add(unSelectedImg, 0, 0);
                gd.Children.Add(selectedImg, 0, 0);

                if (x == (Count - 1))
                {
                    behavior.PropertyChanged += RatingchangedEvent;
                }

                gd.Behaviors.Add(behavior);
                Children.Add(gd);
            }
        }
예제 #2
0
        static void OnGroupNameChanged(BindableObject bindable, object oldValue, object newValue)
        {
            StarBehavior behavior     = (StarBehavior)bindable;
            string       oldGroupName = (string)oldValue;
            string       newGroupName = (string)newValue;

            // Remove existing behavior from Group
            if (String.IsNullOrEmpty(oldGroupName))
            {
                defaultBehaviors.Remove(behavior);
            }
            else
            {
                List <StarBehavior> behaviors = starGroups[oldGroupName];
                behaviors.Remove(behavior);

                if (behaviors.Count == 0)
                {
                    starGroups.Remove(oldGroupName);
                }
            }

            // Add New Behavior to the group
            if (String.IsNullOrEmpty(newGroupName))
            {
                defaultBehaviors.Add(behavior);
            }
            else
            {
                List <StarBehavior> behaviors = null;

                if (starGroups.ContainsKey(newGroupName))
                {
                    behaviors = starGroups[newGroupName];
                }
                else
                {
                    behaviors = new List <StarBehavior>();
                    starGroups.Add(newGroupName, behaviors);
                }

                behaviors.Add(behavior);
            }
        }
예제 #3
0
        static void OnIsStarredChanged(BindableObject bindable, object oldValue, object newValue)
        {
            StarBehavior behavior = (StarBehavior)bindable;

            if ((bool)newValue)
            {
                string groupName = behavior.GroupName;
                List <StarBehavior> behaviors = null;

                if (string.IsNullOrEmpty(groupName))
                {
                    behaviors = defaultBehaviors;
                }
                else
                {
                    behaviors = starGroups[groupName];
                }

                bool itemReached = false;

                foreach (var item in behaviors)
                {
                    if (item != behavior && !itemReached)
                    {
                        item.IsStarred = true;
                    }
                    if (item == behavior)
                    {
                        itemReached    = true;
                        item.IsStarred = true;
                    }
                    if (item != behavior && itemReached)
                    {
                        item.IsStarred = false;
                    }

                    item.Rating = behavior.Index;
                }
            }
        }