Ejemplo n.º 1
0
        private UIElement CreateBody(Todos todos)
        {
            // Disconnect the ScrollViewer from it's previous ContentControl parent
            if (bodyContainer != null)
            {
                bodyContainer.Content = null;
            }

            bodyScroller.Content =
                new StackPanel()
            {
                Orientation = Orientation.Vertical
            }
            .Containing(todos.TodoItems.Select(CreateTodoItem));

            return(bodyContainer = new ContentControl()
            {
                Content = bodyScroller
            });
        }
Ejemplo n.º 2
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))
                       ));
        }
Ejemplo n.º 3
0
        public MainWindow()
        {
            InitializeComponent();

            component = Component.Create <Todos, TodoMessage, UIElement>(
                new Todos(ImmutableList <TodoItem> .Empty, false),

                (msg, todos) => msg.Map(
                    toggleFilter: filter => new Todos(todos.TodoItems, filter),

                    add: todo => new Todos(todos.TodoItems.Add(todo), todos.Filter),

                    remove: todo => new Todos(todos.TodoItems.Remove(todo), todos.Filter),

                    toggleCompleted: todo => new Todos(
                        todos.TodoItems.Replace(todo, new TodoItem(todo.Text, !todo.Completed)),
                        todos.Filter)),

                (todos) =>
                new Grid()
            {
                Margin = new Thickness(5, 5, 5, 5)
            }
                .WithRow(Height: GridLength.Auto)
                .WithRow()
                .WithRow(Height: GridLength.Auto)
                .Containing(
                    CreateHeader(todos).DoWith(t => t.SetValue(Grid.RowProperty, 0)),
                    CreateBody(todos).DoWith(s => s.SetValue(Grid.RowProperty, 1)),
                    new TextBlock()
            {
                Text = "Show Completed"
            }.DoWith(t => t.SetValue(Grid.RowProperty, 2)))
                );

            this.model   = component.InitialModel;
            this.Content = component.View(model);
        }
Ejemplo n.º 4
0
 private void Dispatch(TodoMessage msg)
 {
     model        = component.Update(msg, model);
     this.Content = component.View(model);
 }