private void Event_Remove(object sender, RoutedEventArgs e)
        {
            WeeklyEvent ev = (sender as MenuItem).DataContext as WeeklyEvent;

            if (RemoveEvent != null)
            {
                RemoveEvent(this, new SelectEventArgs(ev.ViewModel));
            }
        }
        private void Event_Click(object sender, RoutedEventArgs e)
        {
            WeeklyEvent ev = sender as WeeklyEvent;

            if (SelectEvent != null)
            {
                SelectEvent(this, new SelectEventArgs(ev.ViewModel));
            }
        }
        private void GenerateEventControl(List <EventViewModel> events, int level, int maxLevel)
        {
            EventViewModel firstEvent = events[0];

            events.RemoveAt(0);

            bool hasOverlaps = false;

            while (events.Count > 0 && EventsOverlap(firstEvent, events[0]))
            {
                hasOverlaps = true;
                GenerateEventControl(events, level + 1, maxLevel);
            }

            WeeklyEvent control = new WeeklyEvent();

            control.Style   = Application.Current.Resources["custom:WeeklyEvent"] as Style;
            control.Content = firstEvent.Text;
            Grid.SetRow(control, firstEvent.StartHour - StartHour);
            Grid.SetColumn(control, 1);
            Grid.SetRowSpan(control, firstEvent.Duration);
            double availableWidth = grid.ColumnDefinitions[1].ActualWidth;
            double widthPerEvent  = availableWidth / (maxLevel + 1);

            control.Margin = new Thickness(level * widthPerEvent, 0, 0, 0);
            control.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
            control.ViewModel           = firstEvent;
            if (gfxNameCounter % 2 == 0)
            {
                control.GfxName = "green";
            }
            else
            {
                control.GfxName = "turquoise";
            }
            ++gfxNameCounter;

            ContextMenu menu = new ContextMenu();

            menu.IsZoomEnabled = false;
            MenuItem edit = new MenuItem();

            edit.Header      = wpweeklyplanner.AppResources.ButtonEdit;
            edit.Click      += new RoutedEventHandler(Event_Edit);
            edit.DataContext = control;
            MenuItem remove = new MenuItem();

            remove.Header      = wpweeklyplanner.AppResources.ButtonRemove;
            remove.Click      += new RoutedEventHandler(Event_Remove);
            remove.DataContext = control;

            menu.Items.Add(edit);
            menu.Items.Add(remove);
            ContextMenuService.SetContextMenu(control, menu);

            if (hasOverlaps)
            {
                control.Width = widthPerEvent;
            }
            else
            {
                control.Width = availableWidth - level * widthPerEvent;
            }

            control.Click += new RoutedEventHandler(Event_Click);
            grid.Children.Add(control);
        }
コード例 #4
0
        private void GenerateEventControl(List<EventViewModel> events, int level, int maxLevel)
        {
            EventViewModel firstEvent = events[0];
            events.RemoveAt(0);

            bool hasOverlaps = false;
            while (events.Count > 0 && EventsOverlap(firstEvent, events[0]))
            {
                hasOverlaps = true;
                GenerateEventControl(events, level + 1, maxLevel);
            }

            WeeklyEvent control = new WeeklyEvent();
            control.Style = Application.Current.Resources["custom:WeeklyEvent"] as Style;
            control.Content = firstEvent.Text;
            Grid.SetRow(control, firstEvent.StartHour - StartHour);
            Grid.SetColumn(control, 1);
            Grid.SetRowSpan(control, firstEvent.Duration);
            double availableWidth = grid.ColumnDefinitions[1].ActualWidth;
            double widthPerEvent = availableWidth / (maxLevel + 1);
            control.Margin = new Thickness(level * widthPerEvent, 0, 0, 0);
            control.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
            control.ViewModel = firstEvent;
            if (gfxNameCounter % 2 == 0)
            {
                control.GfxName = "green";
            }
            else
            {
                control.GfxName = "turquoise";
            }
            ++gfxNameCounter;

            ContextMenu menu = new ContextMenu();
            menu.IsZoomEnabled = false;
            MenuItem edit = new MenuItem();
            edit.Header = wpweeklyplanner.AppResources.ButtonEdit;
            edit.Click += new RoutedEventHandler(Event_Edit);
            edit.DataContext = control;
            MenuItem remove = new MenuItem();
            remove.Header = wpweeklyplanner.AppResources.ButtonRemove;
            remove.Click += new RoutedEventHandler(Event_Remove);
            remove.DataContext = control;

            menu.Items.Add(edit);
            menu.Items.Add(remove);
            ContextMenuService.SetContextMenu(control, menu);

            if (hasOverlaps)
            {
                control.Width = widthPerEvent;
            }
            else
            {
                control.Width = availableWidth - level * widthPerEvent;
            }

            control.Click += new RoutedEventHandler(Event_Click);
            grid.Children.Add(control);
        }