コード例 #1
0
 public TimeRestrictionsControl()
 {
     InitializeComponent();
     for (var day = 0; day < DaysPerWeek; day++)
     {
         for (var hour = 0; hour < HoursPerDay; hour++)
         {
             _hourCells[day,hour] = new ToggleCell();
             Grid.SetColumn(_hourCells[day,hour], hour + 1);
             Grid.SetRow(_hourCells[day,hour], day + 1);
             _hourCells[day, hour].PreviewMouseLeftButtonDown += TimeGrid_PreviewMouseLeftButtonDown;
             _hourCells[day, hour].PreviewMouseLeftButtonUp += TimeGrid_PreviewMouseLeftButtonUp;
             _hourCells[day, hour].PreviewMouseMove += TimeGrid_PreviewMouseMove;
             WeekGrid.Children.Add(_hourCells[day, hour]);
         }
     }
     WeekGrid.DataContext = this;
 }
コード例 #2
0
 void EndDragging()
 {
     _mouseDragStart = null;
     _dragSource = null;
     _dragRegion = null;
 }
コード例 #3
0
 void ApplyActionToRegion(ToggleCell[,] cells, Action<ToggleCell> action)
 {
     var startx = Grid.GetColumn(TopLeft) - 1;
     var endx = Grid.GetColumn(BottomRight) - 1;
     var starty = Grid.GetRow(TopLeft) - 1;
     var endy = Grid.GetRow(BottomRight) - 1;
     for (var x = startx; x <= endx; x++)
     {
         for (var y = starty; y <= endy; y++)
         {
             action(cells[y, x]);
         }
     }
 }
コード例 #4
0
 public void SetVisualStates(ToggleCell[,] cells, string state)
 {
     ApplyActionToRegion(cells, (cell) => VisualStateManager.GoToState(cell, state, true));
 }
コード例 #5
0
 public void ApplySelection(ToggleCell[,] cells, bool select)
 {
     ApplyActionToRegion(cells, (cell) =>
     {
         VisualStateManager.GoToState(cell, "NoDrag", true);
         VisualStateManager.GoToState(cell, "Normal", true);
         cell.Selected = select;
     });
 }
コード例 #6
0
 public CellRegion(ToggleCell[,] cells, ToggleCell first, ToggleCell second)
 {
     var firstx = Grid.GetColumn(first) - 1;
     var secondx = Grid.GetColumn(second) - 1;
     var firsty = Grid.GetRow(first) - 1;
     var secondy = Grid.GetRow(second) - 1;
     var minx = Math.Min(firstx, secondx);
     var miny = Math.Min(firsty, secondy);
     var maxx = Math.Max(firstx, secondx);
     var maxy = Math.Max(firsty, secondy);
     TopLeft = cells[miny, minx];
     BottomRight = cells[maxy, maxx];
 }
コード例 #7
0
 void TimeGrid_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
 {
     var element = sender as ToggleCell;
     if (element == null) return;
     _dragSource = element;
     _dragSource.Selected = !_dragSource.Selected;
     _mouseDragStart = e.GetPosition(this);
 }