diff --git a/WPF控件.sln b/WPF控件.sln index 5f41ee6..7c5543e 100644 --- a/WPF控件.sln +++ b/WPF控件.sln @@ -46,6 +46,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WPF控件-17-日期控件", EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WPF绑定元素-1-示例", "WPF绑定元素-1-示例\WPF绑定元素-1-示例.csproj", "{4AC0C9A3-D0F3-458C-AB1F-A71027447202}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WPF绑定元素-1-代码模式的绑定", "WPF绑定元素-1-代码模式的绑定\WPF绑定元素-1-代码模式的绑定.csproj", "{715FDA75-3236-4011-B1DA-46BD3EAFBA37}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -144,5 +146,9 @@ Global {4AC0C9A3-D0F3-458C-AB1F-A71027447202}.Debug|Any CPU.Build.0 = Debug|Any CPU {4AC0C9A3-D0F3-458C-AB1F-A71027447202}.Release|Any CPU.ActiveCfg = Release|Any CPU {4AC0C9A3-D0F3-458C-AB1F-A71027447202}.Release|Any CPU.Build.0 = Release|Any CPU + {715FDA75-3236-4011-B1DA-46BD3EAFBA37}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {715FDA75-3236-4011-B1DA-46BD3EAFBA37}.Debug|Any CPU.Build.0 = Debug|Any CPU + {715FDA75-3236-4011-B1DA-46BD3EAFBA37}.Release|Any CPU.ActiveCfg = Release|Any CPU + {715FDA75-3236-4011-B1DA-46BD3EAFBA37}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection EndGlobal diff --git a/WPF绑定元素-1-代码模式的绑定/App.xaml b/WPF绑定元素-1-代码模式的绑定/App.xaml new file mode 100644 index 0000000..a8dc945 --- /dev/null +++ b/WPF绑定元素-1-代码模式的绑定/App.xaml @@ -0,0 +1,9 @@ + + + + + diff --git a/WPF绑定元素-1-代码模式的绑定/App.xaml.cs b/WPF绑定元素-1-代码模式的绑定/App.xaml.cs new file mode 100644 index 0000000..5a90f1d --- /dev/null +++ b/WPF绑定元素-1-代码模式的绑定/App.xaml.cs @@ -0,0 +1,12 @@ +using System.Configuration; +using System.Data; +using System.Windows; + +namespace WPF绑定元素_1_代码模式的绑定; + +/// +/// Interaction logic for App.xaml +/// +public partial class App : Application +{ +} \ No newline at end of file diff --git a/WPF绑定元素-1-代码模式的绑定/AssemblyInfo.cs b/WPF绑定元素-1-代码模式的绑定/AssemblyInfo.cs new file mode 100644 index 0000000..4a05c7d --- /dev/null +++ b/WPF绑定元素-1-代码模式的绑定/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) +)] \ No newline at end of file diff --git a/WPF绑定元素-1-代码模式的绑定/MainWindow.xaml b/WPF绑定元素-1-代码模式的绑定/MainWindow.xaml new file mode 100644 index 0000000..1db7293 --- /dev/null +++ b/WPF绑定元素-1-代码模式的绑定/MainWindow.xaml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/WPF绑定元素-1-代码模式的绑定/MainWindow.xaml.cs b/WPF绑定元素-1-代码模式的绑定/MainWindow.xaml.cs new file mode 100644 index 0000000..752995a --- /dev/null +++ b/WPF绑定元素-1-代码模式的绑定/MainWindow.xaml.cs @@ -0,0 +1,45 @@ +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; + +namespace WPF绑定元素_1_代码模式的绑定; + +/// +/// Interaction logic for MainWindow.xaml +/// +public partial class MainWindow : Window +{ + public MainWindow() + { + InitializeComponent(); + Console.WriteLine("使用代码模式的绑定"); + + var binding = new Binding + { + Source = SliderFontSize, + Path = new PropertyPath("Value"), + Mode = BindingMode.TwoWay + }; + TextBlockShow.SetBinding(TextBlock.FontSizeProperty, binding); + } + + private void SetLarge_OnClick(object sender, RoutedEventArgs e) + { + SliderFontSize.Value = 100; + } + + private void SetNormal_OnClick(object sender, RoutedEventArgs e) + { + SliderFontSize.Value = 40; + } + + private void SetSmall_OnClick(object sender, RoutedEventArgs e) + { + SliderFontSize.Value = 10; + } + + private void ClearBinding_OnClick(object sender, RoutedEventArgs e) + { + BindingOperations.ClearAllBindings(TextBlockShow); + } +} \ No newline at end of file diff --git a/WPF绑定元素-1-代码模式的绑定/WPF绑定元素-1-代码模式的绑定.csproj b/WPF绑定元素-1-代码模式的绑定/WPF绑定元素-1-代码模式的绑定.csproj new file mode 100644 index 0000000..f7f6990 --- /dev/null +++ b/WPF绑定元素-1-代码模式的绑定/WPF绑定元素-1-代码模式的绑定.csproj @@ -0,0 +1,18 @@ + + + + WinExe + net8.0-windows + WPF绑定元素_1_代码模式的绑定 + enable + enable + true + + + + + Always + + + + diff --git a/WPF绑定元素-1-代码模式的绑定/public/003540AH4M72.jpg b/WPF绑定元素-1-代码模式的绑定/public/003540AH4M72.jpg new file mode 100644 index 0000000..4aa96ac Binary files /dev/null and b/WPF绑定元素-1-代码模式的绑定/public/003540AH4M72.jpg differ