示例#1
0
        static void OnGroupNameChanged(BindableObject bindable, object oldValue, object newValue)
        {
            StarBehavior behavior     = (StarBehavior)bindable;
            string       oldGroupName = (string)oldValue;
            string       newGroupName = (string)newValue;

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

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


            if (String.IsNullOrEmpty(newGroupName))             // add New Behavior to the group
            {
                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);
            }
        }
示例#2
0
        static void OnIsStarredChanged(BindableObject bindable, object oldValue, object newValue)         //sets star rating
        {
            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;
                int  count       = 1;
                // 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;
                    }
                    if (item != behavior && itemReached)
                    {
                        item.IsStarred = false;
                    }
                    count++;
                }
            }
        }