new samples
This commit is contained in:
9
PacticeSolution/DependencyProperty/App.xaml
Normal file
9
PacticeSolution/DependencyProperty/App.xaml
Normal file
@@ -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>
|
17
PacticeSolution/DependencyProperty/App.xaml.cs
Normal file
17
PacticeSolution/DependencyProperty/App.xaml.cs
Normal file
@@ -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
|
||||
{
|
||||
}
|
||||
}
|
10
PacticeSolution/DependencyProperty/AssemblyInfo.cs
Normal file
10
PacticeSolution/DependencyProperty/AssemblyInfo.cs
Normal file
@@ -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>
|
28
PacticeSolution/DependencyProperty/MainWindow.xaml
Normal file
28
PacticeSolution/DependencyProperty/MainWindow.xaml
Normal file
@@ -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>
|
60
PacticeSolution/DependencyProperty/MainWindow.xaml.cs
Normal file
60
PacticeSolution/DependencyProperty/MainWindow.xaml.cs
Normal file
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
9
PacticeSolution/MVVMComboBoxSample/App.xaml
Normal file
9
PacticeSolution/MVVMComboBoxSample/App.xaml
Normal file
@@ -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>
|
17
PacticeSolution/MVVMComboBoxSample/App.xaml.cs
Normal file
17
PacticeSolution/MVVMComboBoxSample/App.xaml.cs
Normal file
@@ -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
|
||||
{
|
||||
}
|
||||
}
|
10
PacticeSolution/MVVMComboBoxSample/AssemblyInfo.cs
Normal file
10
PacticeSolution/MVVMComboBoxSample/AssemblyInfo.cs
Normal file
@@ -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)
|
||||
)]
|
10
PacticeSolution/MVVMComboBoxSample/MVVMComboBoxSample.csproj
Normal file
10
PacticeSolution/MVVMComboBoxSample/MVVMComboBoxSample.csproj
Normal file
@@ -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>
|
35
PacticeSolution/MVVMComboBoxSample/MainWindow.xaml
Normal file
35
PacticeSolution/MVVMComboBoxSample/MainWindow.xaml
Normal file
@@ -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>
|
28
PacticeSolution/MVVMComboBoxSample/MainWindow.xaml.cs
Normal file
28
PacticeSolution/MVVMComboBoxSample/MainWindow.xaml.cs
Normal file
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
17
PacticeSolution/MVVMComboBoxSample/Model/Student.cs
Normal file
17
PacticeSolution/MVVMComboBoxSample/Model/Student.cs
Normal file
@@ -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
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "XamlUISample", "XamlUISample\XamlUISample.csproj", "{CBB0126E-291E-47F0-82D4-B7D78439BC4C}"
|
||||
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
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
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}.Release|Any CPU.ActiveCfg = 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
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
Reference in New Issue
Block a user