AvaloniaUI / Avalonia.Samples

Avalonia.Samples aims to provide some minimal samples focusing on a particular issue at a time. This should help getting new users started.
https://www.avaloniaui.net
606 stars 103 forks source link

ToDoListApp Compile Error Due to Wrong Parameter #67

Closed tomschrot closed 9 months ago

tomschrot commented 9 months ago

Ref: https://docs.avaloniaui.net/docs/next/tutorials/todo-list-app/process-a-new-item

The given example does not compile!

`

    Observable.Merge
    (
        addItemViewModel.OkCommand,
        addItemViewModel.CancelCommand.Select(_ => (ToDoItem?)null)
    )
    .Take(1)
    .Subscribe(newItem =>
    {
        if (newItem != null)
        {
            ToDoList.ListItems.Add(newItem );
        }
        ContentViewModel = ToDoList;
    });

` where CS1660 error is thrown in line .Subscribe(newItem => ...

The Subscribe function awaits an IObserveable object not a lambda!

I also suggest to rather use C# patterns instead of null checking, e.g.

if (newItem != null) ....

if (newItem is not null)...

maxkatz6 commented 9 months ago

You are missing using System;.