diff --git a/PacticeSolution/DataGridEventTriggerSample/MainWindow.xaml b/PacticeSolution/DataGridEventTriggerSample/MainWindow.xaml
index ecff841..c144930 100644
--- a/PacticeSolution/DataGridEventTriggerSample/MainWindow.xaml
+++ b/PacticeSolution/DataGridEventTriggerSample/MainWindow.xaml
@@ -23,7 +23,7 @@
ScrollViewer.HorizontalScrollBarVisibility="Visible"
ScrollViewer.VerticalScrollBarVisibility="Auto">
-
+
diff --git a/PacticeSolution/DataGridEventTriggerSample/ViewModel/StudentViewModel.cs b/PacticeSolution/DataGridEventTriggerSample/ViewModel/StudentViewModel.cs
index 49d51d3..56d7843 100644
--- a/PacticeSolution/DataGridEventTriggerSample/ViewModel/StudentViewModel.cs
+++ b/PacticeSolution/DataGridEventTriggerSample/ViewModel/StudentViewModel.cs
@@ -16,7 +16,7 @@ namespace DataGridEventTriggerSample.ViewModel
{
internal class StudentViewModel : Behavior, INotifyPropertyChanged
{
- public static readonly DependencyProperty MouseDownProperty = DependencyProperty.Register(nameof(MouseDownCommand), typeof(ICommand), typeof(StudentViewModel), new PropertyMetadata(null));
+ public static readonly DependencyProperty MouseDoubleClickProperty = DependencyProperty.Register(nameof(MouseDoubleClickCommand), typeof(ICommand), typeof(StudentViewModel), new PropertyMetadata(null));
private ObservableCollection _students;
@@ -53,10 +53,10 @@ namespace DataGridEventTriggerSample.ViewModel
}
- public ICommand MouseDownCommand
+ public ICommand MouseDoubleClickCommand
{
- get { return (ICommand)GetValue(MouseDownProperty); }
- set { SetValue(MouseDownProperty, value); }
+ get { return (ICommand)GetValue(MouseDoubleClickProperty); }
+ set { SetValue(MouseDoubleClickProperty, value); }
}
protected virtual void OnPropertyChanged(string propertyName)
@@ -65,7 +65,7 @@ namespace DataGridEventTriggerSample.ViewModel
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
- public void OnDataGridMouseDown(object sender, MouseEventArgs e)
+ public void OnDataGridMouseDoubleClick(object sender, MouseEventArgs e)
{
DataGrid? dataGrid = sender as DataGrid;
if (dataGrid == null)
@@ -91,12 +91,12 @@ namespace DataGridEventTriggerSample.ViewModel
protected override void OnAttached()
{
- this.AssociatedObject.MouseUp += OnDataGridMouseDown;
+ this.AssociatedObject.MouseDoubleClick += OnDataGridMouseDoubleClick;
}
protected override void OnDetaching()
{
- this.AssociatedObject.MouseUp += OnDataGridMouseDown;
+ this.AssociatedObject.MouseDoubleClick += OnDataGridMouseDoubleClick;
}
}
}
diff --git a/PacticeSolution/ImageLoader/App.xaml b/PacticeSolution/ImageLoader/App.xaml
new file mode 100644
index 0000000..b12cf02
--- /dev/null
+++ b/PacticeSolution/ImageLoader/App.xaml
@@ -0,0 +1,9 @@
+
+
+
+
+
diff --git a/PacticeSolution/ImageLoader/App.xaml.cs b/PacticeSolution/ImageLoader/App.xaml.cs
new file mode 100644
index 0000000..485b1f2
--- /dev/null
+++ b/PacticeSolution/ImageLoader/App.xaml.cs
@@ -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 ImageLoader
+{
+ ///
+ /// Interaction logic for App.xaml
+ ///
+ public partial class App : Application
+ {
+ }
+}
diff --git a/PacticeSolution/ImageLoader/AssemblyInfo.cs b/PacticeSolution/ImageLoader/AssemblyInfo.cs
new file mode 100644
index 0000000..8b5504e
--- /dev/null
+++ b/PacticeSolution/ImageLoader/AssemblyInfo.cs
@@ -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)
+)]
diff --git a/PacticeSolution/ImageLoader/ImageLoader.csproj b/PacticeSolution/ImageLoader/ImageLoader.csproj
new file mode 100644
index 0000000..4106cb0
--- /dev/null
+++ b/PacticeSolution/ImageLoader/ImageLoader.csproj
@@ -0,0 +1,10 @@
+
+
+
+ WinExe
+ net6.0-windows
+ enable
+ true
+
+
+
diff --git a/PacticeSolution/ImageLoader/MainWindow.xaml b/PacticeSolution/ImageLoader/MainWindow.xaml
new file mode 100644
index 0000000..211199b
--- /dev/null
+++ b/PacticeSolution/ImageLoader/MainWindow.xaml
@@ -0,0 +1,34 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/PacticeSolution/ImageLoader/MainWindow.xaml.cs b/PacticeSolution/ImageLoader/MainWindow.xaml.cs
new file mode 100644
index 0000000..5108acc
--- /dev/null
+++ b/PacticeSolution/ImageLoader/MainWindow.xaml.cs
@@ -0,0 +1,104 @@
+using Microsoft.Win32;
+using System;
+using System.Collections.Generic;
+using System.IO;
+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 ImageLoader
+{
+ ///
+ /// Interaction logic for MainWindow.xaml
+ ///
+ public partial class MainWindow : Window
+ {
+ private List _imageList;
+ private List _imageControlList;
+
+ public MainWindow()
+ {
+ InitializeComponent();
+ InitInstance();
+ }
+
+ private void InitInstance()
+ {
+ _imageList = new List();
+ _imageControlList = new List();
+ }
+
+ private void btnFolder_Click(object sender, RoutedEventArgs e)
+ {
+ OpenFileDialog dlg = new OpenFileDialog();
+ if (dlg.ShowDialog() == true)
+ {
+ string fullPath = dlg.FileName;
+ string fileName = dlg.SafeFileName;
+ string path = fullPath.Replace(fileName, "");
+
+ txtFolder.Text = path;
+ string[] files = Directory.GetFiles(path);
+ _imageList = files.Where(f => f.IndexOf(".jpg", StringComparison.OrdinalIgnoreCase) >= 0
+ || f.IndexOf(".png", StringComparison.OrdinalIgnoreCase) >= 0)
+ .ToList();
+ }
+
+ CreateImage(_imageList);
+ }
+
+ private void CreateImage(List imageList)
+ {
+ for (int i = 0; i < imageList.Count; i++)
+ {
+ Image image = CreateBitmap(imageList[i]);
+ _imageControlList.Add(image);
+
+ image.MouseDown += Image_MouseDown;
+ pnlImage.Children.Add(image);
+ }
+ }
+
+ private void Image_MouseDown(object sender, MouseButtonEventArgs e)
+ {
+ Image image = sender as Image;
+ if (image == null)
+ return;
+
+ //WrapPanel parent = image.Parent as WrapPanel;
+ //if (parent != null)
+ // parent.Children.Clear();
+
+ Image newImage = CreateBitmap(image.Source.ToString(), 1000);
+ newImage.Stretch = Stretch.UniformToFill;
+ cvsImage.Children.Clear();
+ cvsImage.Children.Add(newImage);
+
+ //CreateImage(_imageList);
+ }
+
+ private Image CreateBitmap(string path, int widthPixel = 300)
+ {
+ BitmapImage bitmap = new BitmapImage();
+ bitmap.BeginInit();
+ bitmap.CacheOption = BitmapCacheOption.OnDemand;
+ bitmap.CreateOptions = BitmapCreateOptions.DelayCreation;
+ bitmap.DecodePixelWidth = widthPixel;
+ bitmap.UriSource = new Uri(path);
+ bitmap.EndInit();
+
+ Image img = new Image();
+ img.Source = bitmap;
+ return img;
+ }
+ }
+}
diff --git a/PacticeSolution/MVVMDataGridBinding/App.xaml b/PacticeSolution/MVVMDataGridBinding/App.xaml
new file mode 100644
index 0000000..3f2c4c6
--- /dev/null
+++ b/PacticeSolution/MVVMDataGridBinding/App.xaml
@@ -0,0 +1,9 @@
+
+
+
+
+
diff --git a/PacticeSolution/MVVMDataGridBinding/App.xaml.cs b/PacticeSolution/MVVMDataGridBinding/App.xaml.cs
new file mode 100644
index 0000000..1b8a99f
--- /dev/null
+++ b/PacticeSolution/MVVMDataGridBinding/App.xaml.cs
@@ -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 MVVMDataGridBinding
+{
+ ///
+ /// Interaction logic for App.xaml
+ ///
+ public partial class App : Application
+ {
+ }
+}
diff --git a/PacticeSolution/MVVMDataGridBinding/AssemblyInfo.cs b/PacticeSolution/MVVMDataGridBinding/AssemblyInfo.cs
new file mode 100644
index 0000000..8b5504e
--- /dev/null
+++ b/PacticeSolution/MVVMDataGridBinding/AssemblyInfo.cs
@@ -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)
+)]
diff --git a/PacticeSolution/MVVMDataGridBinding/Command/DelegateCommand.cs b/PacticeSolution/MVVMDataGridBinding/Command/DelegateCommand.cs
new file mode 100644
index 0000000..6335fc2
--- /dev/null
+++ b/PacticeSolution/MVVMDataGridBinding/Command/DelegateCommand.cs
@@ -0,0 +1,49 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Input;
+
+namespace MVVMDataGridBinding.Command
+{
+ internal class DelegateCommand : ICommand
+ {
+ private readonly Func _canExecute;
+ private readonly Action _execute;
+
+ public event EventHandler? CanExecuteChanged;
+
+ public DelegateCommand(Action execute, Func canExecute)
+ {
+ _execute = execute;
+ _canExecute = canExecute;
+ }
+
+ public DelegateCommand(Action execute) : this(execute, null)
+ {
+
+ }
+
+ public bool CanExecute(object? parameter)
+ {
+ if (_canExecute == null)
+ return true;
+
+ return _canExecute();
+ }
+
+ public void Execute(object? parameter)
+ {
+ _execute();
+ }
+
+ public void RaiseCanExecuteChanged()
+ {
+ if (this.CanExecuteChanged == null)
+ return;
+
+ this.CanExecuteChanged(this, EventArgs.Empty);
+ }
+ }
+}
diff --git a/PacticeSolution/MVVMDataGridBinding/MVVMDataGridBinding.csproj b/PacticeSolution/MVVMDataGridBinding/MVVMDataGridBinding.csproj
new file mode 100644
index 0000000..1e9d1dc
--- /dev/null
+++ b/PacticeSolution/MVVMDataGridBinding/MVVMDataGridBinding.csproj
@@ -0,0 +1,14 @@
+
+
+
+ WinExe
+ net6.0-windows
+ enable
+ true
+
+
+
+
+
+
+
diff --git a/PacticeSolution/MVVMDataGridBinding/MainWindow.xaml b/PacticeSolution/MVVMDataGridBinding/MainWindow.xaml
new file mode 100644
index 0000000..f1a81ae
--- /dev/null
+++ b/PacticeSolution/MVVMDataGridBinding/MainWindow.xaml
@@ -0,0 +1,47 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/PacticeSolution/MVVMDataGridBinding/MainWindow.xaml.cs b/PacticeSolution/MVVMDataGridBinding/MainWindow.xaml.cs
new file mode 100644
index 0000000..1ab412e
--- /dev/null
+++ b/PacticeSolution/MVVMDataGridBinding/MainWindow.xaml.cs
@@ -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 MVVMDataGridBinding
+{
+ ///
+ /// Interaction logic for MainWindow.xaml
+ ///
+ public partial class MainWindow : Window
+ {
+ public MainWindow()
+ {
+ InitializeComponent();
+ }
+ }
+}
diff --git a/PacticeSolution/MVVMDataGridBinding/ViewModel/BaseViewModel.cs b/PacticeSolution/MVVMDataGridBinding/ViewModel/BaseViewModel.cs
new file mode 100644
index 0000000..01ce70b
--- /dev/null
+++ b/PacticeSolution/MVVMDataGridBinding/ViewModel/BaseViewModel.cs
@@ -0,0 +1,22 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace MVVMDataGridBinding.ViewModel
+{
+ internal class BaseViewModel : INotifyPropertyChanged
+ {
+ public event PropertyChangedEventHandler? PropertyChanged;
+
+ protected virtual void OnPropertyChanged(string propertyName)
+ {
+ if (this.PropertyChanged == null)
+ return;
+
+ this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
+ }
+ }
+}
diff --git a/PacticeSolution/MVVMDataGridBinding/ViewModel/MainViewModel.cs b/PacticeSolution/MVVMDataGridBinding/ViewModel/MainViewModel.cs
new file mode 100644
index 0000000..2b28f36
--- /dev/null
+++ b/PacticeSolution/MVVMDataGridBinding/ViewModel/MainViewModel.cs
@@ -0,0 +1,70 @@
+using MVVMDataGridBinding.Command;
+using System;
+using System.Collections.Generic;
+using System.Data;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Input;
+
+namespace MVVMDataGridBinding.ViewModel
+{
+ internal class MainViewModel : BaseViewModel
+ {
+ private DataTable _resultTable;
+
+ private ICommand _updateCommand;
+
+ public DataTable ResultTable
+ {
+ get { return _resultTable; }
+ set
+ {
+ _resultTable = value;
+ OnPropertyChanged(nameof(ResultTable));
+ }
+ }
+
+ public ICommand UpdateCommand
+ {
+ get { return _updateCommand ?? (_updateCommand = new DelegateCommand(UpdateData)); }
+ }
+
+ public MainViewModel()
+ {
+ this.ResultTable = GetSampleData();
+ }
+
+ private DataTable GetSampleData()
+ {
+ DataTable table = new DataTable();
+ table.Columns.Add("Name", typeof(string));
+ table.Columns.Add("Age", typeof(int));
+
+ table.Rows.Add("Agent1", 21);
+ table.Rows.Add("Agent2", 22);
+ table.Rows.Add("Agent3", 23);
+ table.Rows.Add("Agent4", 24);
+
+ return table;
+ }
+
+ private void UpdateData()
+ {
+ this.ResultTable.Columns.Clear();
+ this.ResultTable.Rows.Clear();
+
+ DataTable table = new DataTable();
+ table.Columns.Add("Call Sign", typeof(string));
+ table.Columns.Add("Kill Score", typeof(int));
+
+ table.Rows.Add("Ghost", 2);
+ table.Rows.Add("Holyness", 4);
+ table.Rows.Add("Hyde", 1);
+ table.Rows.Add("Magellan", 5);
+ table.Rows.Add("Inch", 8);
+
+ this.ResultTable = table;
+ }
+ }
+}
diff --git a/PacticeSolution/PacticeSolution.sln b/PacticeSolution/PacticeSolution.sln
index faea40e..a9164f5 100644
--- a/PacticeSolution/PacticeSolution.sln
+++ b/PacticeSolution/PacticeSolution.sln
@@ -23,7 +23,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MVVMCanvasRectangle", "MVVM
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MVVMButtonControl", "MVVMButtonControl\MVVMButtonControl.csproj", "{8FE48C46-5529-4D0D-A96E-01A5A79B0B18}"
EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DataGridEventTriggerSample", "DataGridEventTriggerSample\DataGridEventTriggerSample.csproj", "{48CCBA2F-A583-4DAF-9F64-B9642CDB49FF}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DataGridEventTriggerSample", "DataGridEventTriggerSample\DataGridEventTriggerSample.csproj", "{48CCBA2F-A583-4DAF-9F64-B9642CDB49FF}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MVVMDataGridBinding", "MVVMDataGridBinding\MVVMDataGridBinding.csproj", "{22B968EB-0566-474B-8B1C-105E24727638}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ImageLoader", "ImageLoader\ImageLoader.csproj", "{F65ED213-2F48-4370-B327-FC1F4AFF1E66}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -75,6 +79,14 @@ Global
{48CCBA2F-A583-4DAF-9F64-B9642CDB49FF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{48CCBA2F-A583-4DAF-9F64-B9642CDB49FF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{48CCBA2F-A583-4DAF-9F64-B9642CDB49FF}.Release|Any CPU.Build.0 = Release|Any CPU
+ {22B968EB-0566-474B-8B1C-105E24727638}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {22B968EB-0566-474B-8B1C-105E24727638}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {22B968EB-0566-474B-8B1C-105E24727638}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {22B968EB-0566-474B-8B1C-105E24727638}.Release|Any CPU.Build.0 = Release|Any CPU
+ {F65ED213-2F48-4370-B327-FC1F4AFF1E66}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {F65ED213-2F48-4370-B327-FC1F4AFF1E66}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {F65ED213-2F48-4370-B327-FC1F4AFF1E66}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {F65ED213-2F48-4370-B327-FC1F4AFF1E66}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE