data template

main
syneffort 2 years ago
parent 72ebcd8353
commit 1df85fe35b
  1. 9
      PacticeSolution/DataTemplateSample/App.xaml
  2. 17
      PacticeSolution/DataTemplateSample/App.xaml.cs
  3. 10
      PacticeSolution/DataTemplateSample/AssemblyInfo.cs
  4. 15
      PacticeSolution/DataTemplateSample/Custom/Test.xaml
  5. 28
      PacticeSolution/DataTemplateSample/Custom/Test.xaml.cs
  6. 10
      PacticeSolution/DataTemplateSample/DataTemplateSample.csproj
  7. 28
      PacticeSolution/DataTemplateSample/MainWindow.xaml
  8. 28
      PacticeSolution/DataTemplateSample/MainWindow.xaml.cs
  9. 25
      PacticeSolution/DataTemplateSample/Person.cs
  10. 9
      PacticeSolution/ObervableCollectionSample/MainWindow.xaml
  11. 8
      PacticeSolution/ObervableCollectionSample/MainWindow.xaml.cs
  12. 2
      PacticeSolution/ObervableCollectionSample/Person.cs
  13. 8
      PacticeSolution/PacticeSolution.sln

@ -0,0 +1,9 @@
<Application x:Class="DataTemplateSample.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:DataTemplateSample"
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 DataTemplateSample
{
/// <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,15 @@
<UserControl x:Class="DataTemplateSample.Custom.Test"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:DataTemplateSample.Custom"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<Grid>
<StackPanel>
<TextBlock Text="Hello!"/>
<TextBlock Text="This is testing."/>
</StackPanel>
</Grid>
</UserControl>

@ -0,0 +1,28 @@
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.Navigation;
using System.Windows.Shapes;
namespace DataTemplateSample.Custom
{
/// <summary>
/// Test.xaml에 대한 상호 작용 논리
/// </summary>
public partial class Test : UserControl
{
public Test()
{
InitializeComponent();
}
}
}

@ -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,28 @@
<Window x:Class="DataTemplateSample.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:DataTemplateSample"
xmlns:custom="clr-namespace:DataTemplateSample.Custom"
mc:Ignorable="d"
Title="MainWindow" Height="200" Width="200">
<Window.Resources>
<local:Person x:Key="person"/>
<DataTemplate DataType="{x:Type local:Person}">
<StackPanel Orientation="Vertical">
<TextBlock>Hello,</TextBlock>
<TextBlock Text="{Binding Name}" FontWeight="Bold"/>
<TextBlock>Your age is </TextBlock>
<TextBlock Text="{Binding Age}" FontWeight="Bold"/>
<TextBlock>Right?</TextBlock>
<custom:Test/>
</StackPanel>
</DataTemplate>
</Window.Resources>
<ContentControl Content="{StaticResource person}">
</ContentControl>
</Window>

@ -0,0 +1,28 @@
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.Navigation;
using System.Windows.Shapes;
namespace DataTemplateSample
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
}
}

@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DataTemplateSample
{
class Person
{
public string Name { get; set; }
public int Age { get; set; }
public Person()
{
this.Name = "Richard";
this.Age = 39;
}
//public override string ToString()
//{
// return $"{Name} ({Age})";
//}
}
}

@ -21,5 +21,14 @@
</ListView.ItemTemplate> </ListView.ItemTemplate>
</ListView> </ListView>
<Button Content="Add" Click="Button_Click"/> <Button Content="Add" Click="Button_Click"/>
<ComboBox x:Name="cboMain" ItemsSource="{Binding}" SelectedValuePath="Age">
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Name}"/>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
<Button Content="Check" Click="Button_Click_1"/>
</StackPanel> </StackPanel>
</Window> </Window>

@ -34,5 +34,13 @@ namespace ObervableCollectionSample
context.Add(new Person("New person")); context.Add(new Person("New person"));
} }
private void Button_Click_1(object sender, RoutedEventArgs e)
{
MessageBox.Show(@$"
SelectedItem: {cboMain.SelectedItem}
SelectedValuePath: {cboMain.SelectedValuePath}
SelectedValue: {cboMain.SelectedValue}");
}
} }
} }

@ -9,10 +9,12 @@ namespace ObervableCollectionSample
public class Person public class Person
{ {
public string Name { get; set; } public string Name { get; set; }
public int Age { get; set; }
public Person(string name) public Person(string name)
{ {
this.Name = name; this.Name = name;
this.Age = new Random().Next(20, 60);
} }
} }
} }

@ -115,7 +115,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ClassInitInXaml", "ClassIni
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "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 EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ObervableCollectionSample", "ObervableCollectionSample\ObervableCollectionSample.csproj", "{0C2F6C56-5CAB-44BB-9890-7512C944CE1D}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ObervableCollectionSample", "ObervableCollectionSample\ObervableCollectionSample.csproj", "{0C2F6C56-5CAB-44BB-9890-7512C944CE1D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DataTemplateSample", "DataTemplateSample\DataTemplateSample.csproj", "{D6507C41-143B-45D2-9A45-F822A9E22B7E}"
EndProject EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -351,6 +353,10 @@ Global
{0C2F6C56-5CAB-44BB-9890-7512C944CE1D}.Debug|Any CPU.Build.0 = 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.ActiveCfg = Release|Any CPU
{0C2F6C56-5CAB-44BB-9890-7512C944CE1D}.Release|Any CPU.Build.0 = Release|Any CPU {0C2F6C56-5CAB-44BB-9890-7512C944CE1D}.Release|Any CPU.Build.0 = Release|Any CPU
{D6507C41-143B-45D2-9A45-F822A9E22B7E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D6507C41-143B-45D2-9A45-F822A9E22B7E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D6507C41-143B-45D2-9A45-F822A9E22B7E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D6507C41-143B-45D2-9A45-F822A9E22B7E}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE

Loading…
Cancel
Save