simsenVejle
Well-known member
- Joined
- Feb 14, 2021
- Messages
- 46
- Programming Experience
- Beginner
The result should be; When click on a firstname in the combobox it should display the lastname in a textblock.
When running the code I get an error : SelectedPerson Property not found on object of type ShellViewModel. I have checked it about 50 times. I have a property in PersonModel with the name LastName. Im not sure but I think is it possible I have to use another character than underscore?
I'm starting to learn about Caliburn.
My view (ShellView)
If you want the files Let me know. Hope You can help me.
Best regards
SimsenVejle
When running the code I get an error : SelectedPerson Property not found on object of type ShellViewModel. I have checked it about 50 times. I have a property in PersonModel with the name LastName. Im not sure but I think is it possible I have to use another character than underscore?
I'm starting to learn about Caliburn.
My view (ShellView)
C#:
<Window x:Class="Part03.Views.ShellView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Part03.Views"
mc:Ignorable="d" FontSize="18"
Title="ShellView" Height="450" Width="800" WindowStartupLocation="CenterScreen">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="5.959" />
<ColumnDefinition Width="15.041"/>
<ColumnDefinition Width="auto" />
<ColumnDefinition Width="auto" />
<ColumnDefinition Width="auto" />
<ColumnDefinition Width="auto" />
<ColumnDefinition Width="auto" />
<ColumnDefinition Width="20" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="20" />
<RowDefinition Height="auto" />
<RowDefinition Height="auto" />
<RowDefinition Height="auto" />
<RowDefinition Height="auto" />
<RowDefinition Height="20" />
</Grid.RowDefinitions>
<!--Row 1-->
<TextBlock Text="{Binding Path=FullName, Mode=OneWay}"
Grid.Row="1" Grid.Column="2"
Grid.ColumnSpan="2"></TextBlock>
<!--Row 2-->
<TextBox MinWidth="100" Grid.Row="2" Grid.Column="2" x:Name="FirstName"></TextBox>
<TextBox MinWidth="100" Grid.Row="2" Grid.Column="3" x:Name="LastName"></TextBox>
<!--Row 3-->
<ComboBox Grid.Row="3" Grid.Column="2" x:Name="People"
SelectedItem="{Binding Path=SelectedPerson, Mode=OneWayToSource}"
DisplayMemberPath="FirstName" />
<TextBlock Grid.Row="3" Grid.Column="2" x:Name="SelectedPerson_LastName" />
</Grid>
</Window>
PersonModel:
namespace Part03.Models
{
public class PersonModel
{
public string FirstName { get; set; }
public string LastName { get; set; }
}
}
ShellViewModel:
namespace Part03.ViewModels
{
public class ShellViewModel : Screen
{
public string _firstName = "Charlotte";
public string _lastName;
public BindableCollection<PersonModel> _people = new BindableCollection<PersonModel>();
private PersonModel _selectedPerson;
public ShellViewModel()
{
People.Add(new PersonModel { FirstName = "Tina", LastName = "Iversen" });
People.Add(new PersonModel { FirstName = "Sophia", LastName = "AhrenKiel Simonsen" });
People.Add(new PersonModel { FirstName = "Michelle", LastName = "Meier" });
}
public string FirstName
{
get => _firstName;
set
{
_firstName = value;
NotifyOfPropertyChange(() => FirstName);
NotifyOfPropertyChange(() => FullName);
}
}
public string LastName
{
get => _lastName;
set
{
_lastName = value;
NotifyOfPropertyChange(() => LastName);
NotifyOfPropertyChange(() => FullName);
}
}
public string FullName => $"{ FirstName } {LastName}";
//BindableCollection = list
public BindableCollection<PersonModel> People
{
get => _people;
set => _people = value;
}
private PersonModel SelectedPerson
{
get => _selectedPerson;
set
{
_selectedPerson = value;
NotifyOfPropertyChange(() => SelectedPerson);
}
}
}
}
If you want the files Let me know. Hope You can help me.
Best regards
SimsenVejle
Last edited by a moderator: