observable collection

main
syneffort 2 years ago
parent 5ceff2083d
commit 72ebcd8353
  1. 9
      PacticeSolution/ObervableCollectionSample/App.xaml
  2. 17
      PacticeSolution/ObervableCollectionSample/App.xaml.cs
  3. 10
      PacticeSolution/ObervableCollectionSample/AssemblyInfo.cs
  4. 25
      PacticeSolution/ObervableCollectionSample/MainWindow.xaml
  5. 38
      PacticeSolution/ObervableCollectionSample/MainWindow.xaml.cs
  6. 10
      PacticeSolution/ObervableCollectionSample/ObervableCollectionSample.csproj
  7. 18
      PacticeSolution/ObervableCollectionSample/Person.cs
  8. 26
      PacticeSolution/ObervableCollectionSample/PersonCollection.cs
  9. 14
      PacticeSolution/PacticeSolution.sln

@ -0,0 +1,9 @@
<Application x:Class="ObervableCollectionSample.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:ObervableCollectionSample"
StartupUri="MainWindow.xaml">
<Application.Resources>
</Application.Resources>
</Application>

@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
namespace ObervableCollectionSample
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
}
}

@ -0,0 +1,10 @@
using System.Windows;
[assembly: ThemeInfo(
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
//(used if a resource is not found in the page,
// or application resource dictionaries)
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
//(used if a resource is not found in the page,
// app, or any theme specific resource dictionaries)
)]

@ -0,0 +1,25 @@
<Window x:Class="ObervableCollectionSample.MainWindow"
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:ObervableCollectionSample"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Window.DataContext>
<local:PersonCollection/>
</Window.DataContext>
<StackPanel>
<ListView ItemsSource="{Binding}">
<ListView.ItemTemplate>
<DataTemplate>
<StackPanel>
<TextBlock Text="{Binding Name}"/>
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
<Button Content="Add" Click="Button_Click"/>
</StackPanel>
</Window>

@ -0,0 +1,38 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
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.Navigation;
using System.Windows.Shapes;
namespace ObervableCollectionSample
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
ObservableCollection<Person> context = this.DataContext as ObservableCollection<Person>;
if (context == null)
return;
context.Add(new Person("New person"));
}
}
}

@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net6.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWPF>true</UseWPF>
</PropertyGroup>
</Project>

@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ObervableCollectionSample
{
public class Person
{
public string Name { get; set; }
public Person(string name)
{
this.Name = name;
}
}
}

@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ObervableCollectionSample
{
public class PersonCollection : ObservableCollection<Person>
{
public PersonCollection()
{
InitInstance();
}
private void InitInstance()
{
this.Add(new Person("neymar"));
this.Add(new Person("messi"));
this.Add(new Person("ronaldo"));
this.Add(new Person("park"));
this.Add(new Person("sonny"));
}
}
}

@ -107,13 +107,15 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StaticResourceSample", "Sta
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HowToUseStyle", "HowToUseStyle\HowToUseStyle.csproj", "{6E182894-D2F1-4D2C-B991-51B01A2E3223}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HowToUseStyle", "HowToUseStyle\HowToUseStyle.csproj", "{6E182894-D2F1-4D2C-B991-51B01A2E3223}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ListViewEditSample", "ListViewEditSample\ListViewEditSample.csproj", "{87E66D9A-4E6C-43E8-B23A-AB2A2E9F67D5}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ListViewEditSample", "ListViewEditSample\ListViewEditSample.csproj", "{87E66D9A-4E6C-43E8-B23A-AB2A2E9F67D5}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DelegateEventFuncAction", "DelegateEventFuncAction\DelegateEventFuncAction.csproj", "{52E7C139-F78C-4947-BB09-58D4BFF72435}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DelegateEventFuncAction", "DelegateEventFuncAction\DelegateEventFuncAction.csproj", "{52E7C139-F78C-4947-BB09-58D4BFF72435}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ClassInitInXaml", "ClassInitInXaml\ClassInitInXaml.csproj", "{4D5438AC-CDD0-4975-8D0A-F1BBF49F4EE5}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ClassInitInXaml", "ClassInitInXaml\ClassInitInXaml.csproj", "{4D5438AC-CDD0-4975-8D0A-F1BBF49F4EE5}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ComboBoxSample", "ComboBoxSample\ComboBoxSample.csproj", "{0A10867D-797C-4477-A584-6CB72B1DE97A}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ComboBoxSample", "ComboBoxSample\ComboBoxSample.csproj", "{0A10867D-797C-4477-A584-6CB72B1DE97A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ObervableCollectionSample", "ObervableCollectionSample\ObervableCollectionSample.csproj", "{0C2F6C56-5CAB-44BB-9890-7512C944CE1D}"
EndProject EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -345,6 +347,10 @@ Global
{0A10867D-797C-4477-A584-6CB72B1DE97A}.Debug|Any CPU.Build.0 = Debug|Any CPU {0A10867D-797C-4477-A584-6CB72B1DE97A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0A10867D-797C-4477-A584-6CB72B1DE97A}.Release|Any CPU.ActiveCfg = Release|Any CPU {0A10867D-797C-4477-A584-6CB72B1DE97A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0A10867D-797C-4477-A584-6CB72B1DE97A}.Release|Any CPU.Build.0 = Release|Any CPU {0A10867D-797C-4477-A584-6CB72B1DE97A}.Release|Any CPU.Build.0 = Release|Any CPU
{0C2F6C56-5CAB-44BB-9890-7512C944CE1D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0C2F6C56-5CAB-44BB-9890-7512C944CE1D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0C2F6C56-5CAB-44BB-9890-7512C944CE1D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0C2F6C56-5CAB-44BB-9890-7512C944CE1D}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE

Loading…
Cancel
Save