Esempio n. 1
0
        static void OnGroupNameChanged(BindableObject bindable, object oldValue, object newValue)
        {
            RateBehavior behavior     = (RateBehavior)bindable;
            string       oldGroupName = (string)oldValue;
            string       newGroupName = (string)newValue;

            // Remove existing behavior from Group
            if (String.IsNullOrEmpty(oldGroupName))
            {
                defaultBehaviors.Remove(behavior);
            }
            else
            {
                List <RateBehavior> 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 <RateBehavior> behaviors = null;

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

                behaviors.Add(behavior);
            }
        }
Esempio n. 2
0
        static void OnIsStarredChanged(BindableObject bindable, object oldValue, object newValue)
        {
            RateBehavior behavior = (RateBehavior)bindable;

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

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

                bool itemReached = false;
                int  count = 1, position = 0;
                // all positions to left IsStarred = true and all position to the right is false
                foreach (var item in behaviors)
                {
                    if (item != behavior && !itemReached)
                    {
                        item.IsStarred = true;
                    }
                    if (item == behavior)
                    {
                        itemReached    = true;
                        item.IsStarred = true;
                        position       = count;
                    }
                    if (item != behavior && itemReached)
                    {
                        item.IsStarred = false;
                    }

                    item.Rating = position;
                    count++;
                }
            }
        }