Exemple #1
0
        private UIElement CreateHeader(Todos todos)
        {
            return(new Grid()
            {
            }
                   .DoWith(g =>
            {
                g.ColumnDefinitions.Add(new ColumnDefinition()
                {
                    Width = GridLength.Auto
                });
                g.ColumnDefinitions.Add(new ColumnDefinition());
            })
                   .Containing(
                       new TextBlock()
            {
                Text = "Add a todo",
                HorizontalAlignment = HorizontalAlignment.Stretch
            }
                       .DoWith(t => t.SetValue(Grid.ColumnProperty, 0)),

                       new TextBox()
            {
            }.DoWith(t =>
            {
                t.Loaded += (sender, args) => t.Focus();

                t.KeyDown += (sender, args) =>
                {
                    if (args.Key == Key.Enter)
                    {
                        args.Handled = true;
                        Dispatch(TodoMessage.Add(new TodoItem(t.Text, false)));
                    }
                };
            })
                       .DoWith(t => t.SetValue(Grid.ColumnProperty, 1))
                       ));
        }
Exemple #2
0
        private UIElement CreateTodoItem(TodoItem todo)
        {
            Panel view = null;

            view =
                new StackPanel()
            {
                Orientation = Orientation.Horizontal
            }
            .Containing(
                new CheckBox()
            {
                Margin    = new Thickness(5, 5, 5, 5),
                IsChecked = todo.Completed
            }
                .DoWith(c =>
                        c.Click += (sender, args) => Dispatch(TodoMessage.ToggleCompleted(todo))),

                new TextBlock()
            {
                Margin          = new Thickness(5, 5, 5, 5),
                Text            = todo.Text,
                TextDecorations = todo.Completed ? TextDecorations.Strikethrough
                            : null
            },

                new Button()
            {
                Margin = new Thickness(5, 5, 5, 5),
                HorizontalContentAlignment = HorizontalAlignment.Center,
                VerticalContentAlignment   = VerticalAlignment.Center,
                Content = new Grid()
                {
                }
                .Containing(
                    new Line()
                {
                    StrokeThickness = 2,
                    Stroke          = Brushes.Red,
                    X1 = 0, Y1 = 0,
                    X2 = 10, Y2 = 10
                },
                    new Line()
                {
                    StrokeThickness = 2,
                    Stroke          = Brushes.Red,
                    X1 = 0, Y1 = 10,
                    X2 = 10, Y2 = 0
                })
            }
                .DoWith(b =>
                        b.Click += (s, a) =>
            {
                var fade = new DoubleAnimation(0.0, TimeSpan.FromSeconds(0.25));
                Storyboard.SetTarget(fade, view);
                Storyboard.SetTargetProperty(fade, new PropertyPath(UIElement.OpacityProperty));
                var story = new Storyboard();
                story.Children.Add(fade);
                story.Completed += (s2, a2) => Dispatch(TodoMessage.Remove(todo));
                story.Begin();
            }
                        )
                );

            return(view);
        }
Exemple #3
0
 private void Dispatch(TodoMessage msg)
 {
     model        = component.Update(msg, model);
     this.Content = component.View(model);
 }