new samples

main
syneffort 2 years ago
parent 151f3a5606
commit 392c1c61f3
  1. 9
      PacticeSolution/DependencyProperty/App.xaml
  2. 17
      PacticeSolution/DependencyProperty/App.xaml.cs
  3. 10
      PacticeSolution/DependencyProperty/AssemblyInfo.cs
  4. 10
      PacticeSolution/DependencyProperty/DependencyPropertySample.csproj
  5. 28
      PacticeSolution/DependencyProperty/MainWindow.xaml
  6. 60
      PacticeSolution/DependencyProperty/MainWindow.xaml.cs
  7. 9
      PacticeSolution/MVVMComboBoxSample/App.xaml
  8. 17
      PacticeSolution/MVVMComboBoxSample/App.xaml.cs
  9. 10
      PacticeSolution/MVVMComboBoxSample/AssemblyInfo.cs
  10. 10
      PacticeSolution/MVVMComboBoxSample/MVVMComboBoxSample.csproj
  11. 35
      PacticeSolution/MVVMComboBoxSample/MainWindow.xaml
  12. 28
      PacticeSolution/MVVMComboBoxSample/MainWindow.xaml.cs
  13. 17
      PacticeSolution/MVVMComboBoxSample/Model/Student.cs
  14. 28
      PacticeSolution/MVVMComboBoxSample/ViewModel/StudentViewModel.cs
  15. 12
      PacticeSolution/PacticeSolution.sln

@ -0,0 +1,9 @@
<Application x:Class="DependencyPropertySample.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:DependencyPropertySample"
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 DependencyPropertySample
{
/// <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,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="DependencyPropertySample.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:DependencyPropertySample"
mc:Ignorable="d"
Title="MainWindow" Height="300" Width="400">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<ComboBox x:Name="cboMain" Grid.Column="0" VerticalAlignment="Center" Margin="10"
SelectionChanged="cboMain_SelectionChanged">
<ComboBoxItem Content="Apple"/>
<ComboBoxItem Content="Watermelon"/>
<ComboBoxItem Content="Tangerine"/>
<ComboBoxItem Content="Orange"/>
<ComboBoxItem Content="Strawberry"/>
</ComboBox>
<TextBlock x:Name="txtFruit" Grid.Column="1" VerticalAlignment="Center" Margin="10" TextAlignment="Center" Text="What Fruit?"/>
</Grid>
</Window>

@ -0,0 +1,60 @@
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 DependencyPropertySample
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
// Dependency Property
public static readonly DependencyProperty MyProperty = DependencyProperty.Register(nameof(MyFruit), typeof(string), typeof(MainWindow), new FrameworkPropertyMetadata(new PropertyChangedCallback(OnMyPropertyChanged)));
public MainWindow()
{
InitializeComponent();
}
public string MyFruit
{
get { return (string)GetValue(MyProperty); }
set { SetValue(MyProperty, value); }
}
public static void OnMyPropertyChanged(DependencyObject o, DependencyPropertyChangedEventArgs e)
{
MainWindow win = o as MainWindow;
if (win == null)
return;
win.Title = (e.OldValue == null) ? "Not selected" : $"Old value is {e.OldValue.ToString()}";
win.txtFruit.Text = e.NewValue.ToString();
}
private void cboMain_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
ComboBox cb = sender as ComboBox;
if (cb == null)
return;
ComboBoxItem item = cb.SelectedItem as ComboBoxItem;
if (item == null)
return;
MyFruit = item.Content.ToString();
}
}
}

@ -0,0 +1,9 @@
<Application x:Class="MVVMComboBoxSample.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:MVVMComboBoxSample"
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 MVVMComboBoxSample
{
/// <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,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,35 @@
<Window x:Class="MVVMComboBoxSample.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:MVVMComboBoxSample"
xmlns:vm ="clr-namespace:MVVMComboBoxSample.ViewModel"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="500">
<Window.Resources>
<vm:StudentViewModel x:Key="vm"/>
</Window.Resources>
<StackPanel DataContext="{Binding Source={StaticResource vm}}">
<ComboBox HorizontalAlignment="Center"
Margin="10"
VerticalAlignment="Top"
Width="300"
ItemsSource="{Binding Students}"
SelectedItem="{Binding SelectedStudent}">
<ComboBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding ID}"/>
<TextBlock Text="-"/>
<TextBlock Text="{Binding Name}"/>
<TextBlock Text="-"/>
<TextBlock Text="{Binding Age}"/>
</StackPanel>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
</StackPanel>
</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 MVVMComboBoxSample
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
}
}

@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MVVMComboBoxSample.Model
{
internal class Student
{
public string ID { get; set; }
public string Name { get; set; }
public int Age { get; set; }
}
}

@ -0,0 +1,28 @@
using MVVMComboBoxSample.Model;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MVVMComboBoxSample.ViewModel
{
internal class StudentViewModel
{
public ObservableCollection<Student> Students { get; set; }
public Student SelectedStudent { get; set; }
public StudentViewModel()
{
this.Students = new ObservableCollection<Student>()
{
new Student() { ID = Guid.NewGuid().ToString(), Name = "Joe", Age = 20 },
new Student() { ID = Guid.NewGuid().ToString(), Name = "Jane", Age = 21 },
new Student() { ID = Guid.NewGuid().ToString(), Name = "Rick", Age = 22 },
new Student() { ID = Guid.NewGuid().ToString(), Name = "Paul", Age = 23 },
};
}
}
}

@ -31,6 +31,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ImageLoader", "ImageLoader\
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "XamlUISample", "XamlUISample\XamlUISample.csproj", "{CBB0126E-291E-47F0-82D4-B7D78439BC4C}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "XamlUISample", "XamlUISample\XamlUISample.csproj", "{CBB0126E-291E-47F0-82D4-B7D78439BC4C}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DependencyPropertySample", "DependencyProperty\DependencyPropertySample.csproj", "{7DED7470-62BB-4042-B161-98F9605046B2}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MVVMComboBoxSample", "MVVMComboBoxSample\MVVMComboBoxSample.csproj", "{86DDE4C6-1359-4EB7-BEE6-13EC137F081D}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
@ -93,6 +97,14 @@ Global
{CBB0126E-291E-47F0-82D4-B7D78439BC4C}.Debug|Any CPU.Build.0 = Debug|Any CPU {CBB0126E-291E-47F0-82D4-B7D78439BC4C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CBB0126E-291E-47F0-82D4-B7D78439BC4C}.Release|Any CPU.ActiveCfg = Release|Any CPU {CBB0126E-291E-47F0-82D4-B7D78439BC4C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CBB0126E-291E-47F0-82D4-B7D78439BC4C}.Release|Any CPU.Build.0 = Release|Any CPU {CBB0126E-291E-47F0-82D4-B7D78439BC4C}.Release|Any CPU.Build.0 = Release|Any CPU
{7DED7470-62BB-4042-B161-98F9605046B2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7DED7470-62BB-4042-B161-98F9605046B2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7DED7470-62BB-4042-B161-98F9605046B2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7DED7470-62BB-4042-B161-98F9605046B2}.Release|Any CPU.Build.0 = Release|Any CPU
{86DDE4C6-1359-4EB7-BEE6-13EC137F081D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{86DDE4C6-1359-4EB7-BEE6-13EC137F081D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{86DDE4C6-1359-4EB7-BEE6-13EC137F081D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{86DDE4C6-1359-4EB7-BEE6-13EC137F081D}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE

Loading…
Cancel
Save