class Anime
{
public string Name {get; set;}
public double Rating {get; set;}
public string Author {get; set;}
public string Serie {get; set;}
public string Url {get; set;}
}
class AnimeListViewModel
{
public ObservableCollection<Anime> AnimeList {get; set;} = new ObservableCollection<Anime>
{
new Anime { Name = "Наруто", Rating = 5, Author = "Масаси Кисимото"},
new Anime { Name = "Стальной алхимик", Rating = 5, Author = "Хирому Аракава"},
new Anime { Name = "X", Rating = 5, Author = "CLAMP"},
};
}
<Window ...
xmlns:app="clr-namespace:Anime">
<Window.DataContext>
<app:AnimeListViewModel/>
</Window.DataContext>
<Grid>
<ListBox ItemsSource="{Binding AnimeList}"
DisplayMemberPath="Name"/>
x:Name="AnimeListBox"/>
</Grid>
</Window>
public class Person
{
public string FirstName { get; set; }
public string LastName { get; set; }
public string MiddleName { get; set; }
}
public class EditPersonVm : BaseViewModel // который реализует INotifyPropertyChanged
{
private readonly Person _person;
public Person Person => _person;
private string _firstName;
public string FirstName
{
get => _firstName;
set { _firstName = value; RaisePropertyChanged(); }
}
private string _lastName;
public string LastName
{
get => _lastName;
set { _lastName= value; RaisePropertyChanged(); }
}
private string _middleName;
public string MiddleName
{
get => _middleName;
set { _middleName= value; RaisePropertyChanged(); }
}
public string InitFullName => $"{_person.LastName} {_person.FirstName[0]}. {_person.MiddleName[0]}.";
public RelayCommand OkButton { get; set; } = new RelayCommand(Save);
public EditPersonVm(Person person)
{
_person = person;
FirstName = person.FirstName;
LastName = person.LastName;
MiddleName = person.MiddleName;
}
private void Save()
{
//
}
}
<Window ...>
<StackPanel Orientation="Vertical">
<Label Content="Изначальное имя:"/>
<StackPanel>
<TextBlock Text="{Binding Person.LastName}"/>
<TextBlock> </TextBlock>
<TextBlock Text="{Binding Person.FirstName}"/>
<TextBlock> </TextBlock>
<TextBlock Text="{Binding Person.MiddleName}"/>
</StackPanel>
<Label Content="Фамилия:"/>
<TextBox Text="{Binding LastName, UpdateSourceTrigger=PropertyChanged}"/>
<Label Caption="Имя:"/>
<TextBox Text="{Binding FirstName, UpdateSourceTrigger=PropertyChanged}"/>
<Label Caption="Отчество:"/>
<TextBox Text="{Binding MiddleName, UpdateSourceTrigger=PropertyChanged}"/>
<Button Content="OK" Command="{Binding OkCommand}">
</StackPanel>
</Window>
static void Main(string[] args)
{
string[] items = { "Коробка", "Бутылка", "Телефон" };
Console.WriteLine("Введите слово:");
string user_input = Console.ReadLine();
Console.WriteLine(isExist(user_input, items));
Console.ReadKey();
}
static bool isExist(string user_input, string [] arr)
{
foreach(var word in arr)
{
if (word == user_input)
return true;
}
return false;
}