binding sample
This commit is contained in:
@@ -2,6 +2,6 @@
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:local="clr-namespace:MVVMwithWPF"
|
||||
StartupUri="/Views/MainWindow.xaml">
|
||||
StartupUri="/Views/BindingSampleWindow.xaml">
|
||||
<Application.Resources />
|
||||
</Application>
|
||||
|
16
MVVMwithWPF/MVVMwithWPF/Models/Person.cs
Normal file
16
MVVMwithWPF/MVVMwithWPF/Models/Person.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MVVMwithWPF.Models
|
||||
{
|
||||
public class Person
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
public bool Sex { get; set; }
|
||||
}
|
||||
}
|
40
MVVMwithWPF/MVVMwithWPF/ViewModels/BindindSampleViewModel.cs
Normal file
40
MVVMwithWPF/MVVMwithWPF/ViewModels/BindindSampleViewModel.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using MVVMwithWPF.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MVVMwithWPF.ViewModels
|
||||
{
|
||||
internal partial class BindindSampleViewModel : ViewModelBase
|
||||
{
|
||||
[ObservableProperty]
|
||||
private ObservableCollection<Person> _persons;
|
||||
[ObservableProperty]
|
||||
private int _id;
|
||||
[ObservableProperty]
|
||||
private string _name;
|
||||
[ObservableProperty]
|
||||
private bool _sex;
|
||||
[ObservableProperty]
|
||||
private ObservableCollection<bool> _sexes;
|
||||
|
||||
public BindindSampleViewModel()
|
||||
{
|
||||
Persons = new ObservableCollection<Person>()
|
||||
{
|
||||
new Person() { Id = 11, Name = "person001", Sex = true },
|
||||
new Person() { Id = 22, Name = "person002", Sex = false },
|
||||
};
|
||||
|
||||
Sexes = new ObservableCollection<bool>() { true, false };
|
||||
|
||||
Id = 99;
|
||||
Name = "person000";
|
||||
Sex = false;
|
||||
}
|
||||
}
|
||||
}
|
38
MVVMwithWPF/MVVMwithWPF/Views/BindingSampleWindow.xaml
Normal file
38
MVVMwithWPF/MVVMwithWPF/Views/BindingSampleWindow.xaml
Normal file
@@ -0,0 +1,38 @@
|
||||
<Window x:Class="MVVMwithWPF.Views.BindingSampleWindow"
|
||||
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:local="clr-namespace:MVVMwithWPF.Views"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:viewModels="clr-namespace:MVVMwithWPF.ViewModels"
|
||||
Title="BindingSampleWindow"
|
||||
Width="800"
|
||||
Height="450"
|
||||
mc:Ignorable="d">
|
||||
<Window.DataContext>
|
||||
<viewModels:BindindSampleViewModel />
|
||||
</Window.DataContext>
|
||||
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="6*" />
|
||||
<ColumnDefinition Width="4*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<DataGrid AutoGenerateColumns="False" IsReadOnly="True"
|
||||
ItemsSource="{Binding Persons}">
|
||||
<DataGrid.Columns>
|
||||
<DataGridTextColumn Binding="{Binding Id}" Header="Id" />
|
||||
<DataGridTextColumn Binding="{Binding Name}" Header="Name" />
|
||||
<DataGridTextColumn Binding="{Binding Sex}" Header="Sex" />
|
||||
</DataGrid.Columns>
|
||||
</DataGrid>
|
||||
<StackPanel Grid.Column="1" Margin="5">
|
||||
<TextBlock Text="Id" />
|
||||
<TextBox Text="{Binding Id}" />
|
||||
<TextBlock Text="Name" />
|
||||
<TextBox Text="{Binding Name}" />
|
||||
<TextBlock Text="Sex" />
|
||||
<ComboBox ItemsSource="{Binding Sexes}" SelectedItem="{Binding Sex, Mode=TwoWay}" />
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</Window>
|
27
MVVMwithWPF/MVVMwithWPF/Views/BindingSampleWindow.xaml.cs
Normal file
27
MVVMwithWPF/MVVMwithWPF/Views/BindingSampleWindow.xaml.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
namespace MVVMwithWPF.Views
|
||||
{
|
||||
/// <summary>
|
||||
/// BindingSampleWindow.xaml에 대한 상호 작용 논리
|
||||
/// </summary>
|
||||
public partial class BindingSampleWindow : Window
|
||||
{
|
||||
public BindingSampleWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user