You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I follow the SimpleToDoList tutorial and encounter an error at "second run". I added code below into my MainWindow.axaml file:
<ItemsControl ItemsSource="{Binding ToDoItems}">
<ItemsControl.ItemTemplate>
<!-- The ItemTemplate defines how each item should be represented -->
<!-- Our Item will be represented by a CheckBox and a Delete-Button -->
<DataTemplate DataType="vm:ToDoItemViewModel">
<Grid ColumnDefinitions="*, Auto">
<CheckBox Content="{Binding Content}"
IsChecked="{Binding IsChecked}" />
<!-- Note how we use the Root-Grid to get the MainViewModel here. As we use compiled bindings we have to cast the DataContext -->
<Button Command="{Binding #Root.((vm:MainViewModel)DataContext).RemoveItemCommand}"
CommandParameter="{Binding .}"
Grid.Column="1">
Delete
</Button>
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
Then, full MainWindow.axaml file is:
<Window xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:vm="using:AvaloniaTodo.ViewModels"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:views="clr-namespace:AvaloniaTodo.Views"
mc:Ignorable="d" d:DesignWidth="200" d:DesignHeight="450"
x:Class="AvaloniaTodo.Views.MainWindow"
Icon="/Assets/avalonia-logo.ico"
Title="AvaloniaTodo">
<!-- We give a name to the root grid in order to access it later -->
<Grid RowDefinitions="Auto, *, Auto"
x:Name="Root">
<!-- This is our title text block. -->
<TextBlock Text="ToDo List App" />
<ScrollViewer Grid.Row="1">
<!-- This ItemsControl show all added ToDoItems. -->
<!-- It needs to be placed inside a ScrollViewer because other than a ListBox it has not its own -->
<ItemsControl ItemsSource="{Binding ToDoItems}">
<ItemsControl.ItemTemplate>
<!-- The ItemTemplate defines how each item should be represented -->
<!-- Our Item will be represented by a CheckBox and a Delete-Button -->
<DataTemplate DataType="vm:ToDoItemViewModel">
<Grid ColumnDefinitions="*, Auto">
<CheckBox Content="{Binding Content}"
IsChecked="{Binding IsChecked}" />
<!-- Note how we use the Root-Grid to get the MainViewModel here. As we use compiled bindings we have to cast the DataContext -->
<Button Command="{Binding #Root.((vm:MainViewModel)DataContext).RemoveItemCommand}"
CommandParameter="{Binding .}"
Grid.Column="1">
Delete
</Button>
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</ScrollViewer>
<!-- This TextBox can be used to add new ToDoItems -->
<TextBox Grid.Row="2"
Text="{Binding NewItemContent}"
Watermark="Add a new Item">
<TextBox.InnerRightContent>
<Button Command="{Binding AddItemCommand}" >
Add
<!-- <PathIcon Data="{DynamicResource AcceptIconData}" Foreground="Green" /> -->
</Button>
</TextBox.InnerRightContent>
<!-- KeyBindings allow us to define keyboard gestures -->
<TextBox.KeyBindings>
<KeyBinding Command="{Binding AddItemCommand}" Gesture="Enter" />
</TextBox.KeyBindings>
</TextBox>
</Grid>
</Window>
When I click button "add", there's an error:
Unable to resolve type vm:MainViewModel from any of the following locations:
Hey @spinningwatt depending on the IDE and template used to create your project, the name of the MainViewModel may be MainViewModel or MainWindowViewModel. Make sure it matches on your side.
Please delete bin and obj folders and upload the code to GitHub. Preferably to a new repo and share the link or if that's not working for you via zip file here. Will take a look latest in January.
Describe the bug
I follow the SimpleToDoList tutorial and encounter an error at "second run". I added code below into my MainWindow.axaml file:
Then, full MainWindow.axaml file is:
When I click button "add", there's an error:
Sample affected
https://github.com/AvaloniaUI/Avalonia.Samples/tree/main/src/Avalonia.Samples/CompleteApps/SimpleToDoList
Proposed solution
It should be able to add a new todo item into the list.
Screenshots
The text was updated successfully, but these errors were encountered: