From 88bea39b8a5dd3e42bb34a533c6e99593dd8622b Mon Sep 17 00:00:00 2001 From: syneffort Date: Thu, 6 Jul 2023 16:39:01 +0900 Subject: [PATCH] dependency property --- .../DependencyPropertySample2/App.xaml | 9 ++ .../DependencyPropertySample2/App.xaml.cs | 17 ++++ .../DependencyPropertySample2/AssemblyInfo.cs | 10 +++ .../DependencyPropertySample2.csproj | 10 +++ .../DependencyPropertySample2/MainWindow.xaml | 20 +++++ .../MainWindow.xaml.cs | 62 +++++++++++++ .../ListBoxLinqBindingSample/App.xaml | 9 ++ .../ListBoxLinqBindingSample/App.xaml.cs | 17 ++++ .../ListBoxLinqBindingSample/AssemblyInfo.cs | 10 +++ .../ListBoxLinqBindingSample.csproj | 10 +++ .../ListBoxLinqBindingSample/MainWindow.xaml | 61 +++++++++++++ .../MainWindow.xaml.cs | 90 +++++++++++++++++++ .../ListBoxLinqBindingSample/Model/Duty.cs | 31 +++++++ .../SubWindow/SubWindow.xaml | 38 ++++++++ .../SubWindow/SubWindow.xaml.cs | 43 +++++++++ .../ViewModel/Duties.cs | 23 +++++ PacticeSolution/PacticeSolution.sln | 14 ++- 17 files changed, 473 insertions(+), 1 deletion(-) create mode 100644 PacticeSolution/DependencyPropertySample2/App.xaml create mode 100644 PacticeSolution/DependencyPropertySample2/App.xaml.cs create mode 100644 PacticeSolution/DependencyPropertySample2/AssemblyInfo.cs create mode 100644 PacticeSolution/DependencyPropertySample2/DependencyPropertySample2.csproj create mode 100644 PacticeSolution/DependencyPropertySample2/MainWindow.xaml create mode 100644 PacticeSolution/DependencyPropertySample2/MainWindow.xaml.cs create mode 100644 PacticeSolution/ListBoxLinqBindingSample/App.xaml create mode 100644 PacticeSolution/ListBoxLinqBindingSample/App.xaml.cs create mode 100644 PacticeSolution/ListBoxLinqBindingSample/AssemblyInfo.cs create mode 100644 PacticeSolution/ListBoxLinqBindingSample/ListBoxLinqBindingSample.csproj create mode 100644 PacticeSolution/ListBoxLinqBindingSample/MainWindow.xaml create mode 100644 PacticeSolution/ListBoxLinqBindingSample/MainWindow.xaml.cs create mode 100644 PacticeSolution/ListBoxLinqBindingSample/Model/Duty.cs create mode 100644 PacticeSolution/ListBoxLinqBindingSample/SubWindow/SubWindow.xaml create mode 100644 PacticeSolution/ListBoxLinqBindingSample/SubWindow/SubWindow.xaml.cs create mode 100644 PacticeSolution/ListBoxLinqBindingSample/ViewModel/Duties.cs diff --git a/PacticeSolution/DependencyPropertySample2/App.xaml b/PacticeSolution/DependencyPropertySample2/App.xaml new file mode 100644 index 0000000..b4e1438 --- /dev/null +++ b/PacticeSolution/DependencyPropertySample2/App.xaml @@ -0,0 +1,9 @@ + + + + + diff --git a/PacticeSolution/DependencyPropertySample2/App.xaml.cs b/PacticeSolution/DependencyPropertySample2/App.xaml.cs new file mode 100644 index 0000000..9471485 --- /dev/null +++ b/PacticeSolution/DependencyPropertySample2/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 DependencyPropertySample2 +{ + /// + /// Interaction logic for App.xaml + /// + public partial class App : Application + { + } +} diff --git a/PacticeSolution/DependencyPropertySample2/AssemblyInfo.cs b/PacticeSolution/DependencyPropertySample2/AssemblyInfo.cs new file mode 100644 index 0000000..8b5504e --- /dev/null +++ b/PacticeSolution/DependencyPropertySample2/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/DependencyPropertySample2/DependencyPropertySample2.csproj b/PacticeSolution/DependencyPropertySample2/DependencyPropertySample2.csproj new file mode 100644 index 0000000..4106cb0 --- /dev/null +++ b/PacticeSolution/DependencyPropertySample2/DependencyPropertySample2.csproj @@ -0,0 +1,10 @@ + + + + WinExe + net6.0-windows + enable + true + + + diff --git a/PacticeSolution/DependencyPropertySample2/MainWindow.xaml b/PacticeSolution/DependencyPropertySample2/MainWindow.xaml new file mode 100644 index 0000000..3f11ef7 --- /dev/null +++ b/PacticeSolution/DependencyPropertySample2/MainWindow.xaml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + diff --git a/PacticeSolution/DependencyPropertySample2/MainWindow.xaml.cs b/PacticeSolution/DependencyPropertySample2/MainWindow.xaml.cs new file mode 100644 index 0000000..13ea37b --- /dev/null +++ b/PacticeSolution/DependencyPropertySample2/MainWindow.xaml.cs @@ -0,0 +1,62 @@ +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 DependencyPropertySample2 +{ + /// + /// Interaction logic for MainWindow.xaml + /// + public partial class MainWindow : Window + { + // dependency property + public static readonly DependencyProperty MyProperty = DependencyProperty.Register + ("MyColor", typeof(string), typeof(MainWindow), new FrameworkPropertyMetadata(new PropertyChangedCallback(OnMyPropertyChanged))); + + public MainWindow() + { + InitializeComponent(); + } + + public string MyColor + { + get { return (string)GetValue(MyProperty); } + set { SetValue(MyProperty, value); } + } + + private static void OnMyPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) + { + MainWindow win = d as MainWindow; + if (win == null) + return; + + SolidColorBrush brush = new BrushConverter().ConvertFromString(e.NewValue.ToString()) as SolidColorBrush; + if (brush == null) + return; + + win.Background = brush; + win.Title = (e.OldValue == null) ? "Previous: None" : $"Previous: {e.OldValue.ToString()}"; + win.tbMain.Text = e.NewValue.ToString(); + } + + private void ContextMenu_Click(object sender, RoutedEventArgs e) + { + string str = (e.Source as MenuItem).Header as string; + if (string.IsNullOrEmpty(str)) + return; + + this.MyColor = str; + } + } +} diff --git a/PacticeSolution/ListBoxLinqBindingSample/App.xaml b/PacticeSolution/ListBoxLinqBindingSample/App.xaml new file mode 100644 index 0000000..5ca1339 --- /dev/null +++ b/PacticeSolution/ListBoxLinqBindingSample/App.xaml @@ -0,0 +1,9 @@ + + + + + diff --git a/PacticeSolution/ListBoxLinqBindingSample/App.xaml.cs b/PacticeSolution/ListBoxLinqBindingSample/App.xaml.cs new file mode 100644 index 0000000..769bf9c --- /dev/null +++ b/PacticeSolution/ListBoxLinqBindingSample/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 ListBoxLinqBindingSample +{ + /// + /// Interaction logic for App.xaml + /// + public partial class App : Application + { + } +} diff --git a/PacticeSolution/ListBoxLinqBindingSample/AssemblyInfo.cs b/PacticeSolution/ListBoxLinqBindingSample/AssemblyInfo.cs new file mode 100644 index 0000000..8b5504e --- /dev/null +++ b/PacticeSolution/ListBoxLinqBindingSample/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/ListBoxLinqBindingSample/ListBoxLinqBindingSample.csproj b/PacticeSolution/ListBoxLinqBindingSample/ListBoxLinqBindingSample.csproj new file mode 100644 index 0000000..4106cb0 --- /dev/null +++ b/PacticeSolution/ListBoxLinqBindingSample/ListBoxLinqBindingSample.csproj @@ -0,0 +1,10 @@ + + + + WinExe + net6.0-windows + enable + true + + + diff --git a/PacticeSolution/ListBoxLinqBindingSample/MainWindow.xaml b/PacticeSolution/ListBoxLinqBindingSample/MainWindow.xaml new file mode 100644 index 0000000..9bef5c6 --- /dev/null +++ b/PacticeSolution/ListBoxLinqBindingSample/MainWindow.xaml @@ -0,0 +1,61 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +