WPF绑定元素-2-多绑定

This commit is contained in:
Bunny 2025-01-09 16:24:27 +08:00
parent fe9bd2343e
commit 22fd309abc
7 changed files with 109 additions and 0 deletions

View File

@ -50,6 +50,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WPF绑定元素-1-代码模
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WPF绑定元素-2-代码检索绑定", "WPF绑定元素-2-代码检索绑定\WPF绑定元素-2-代码检索绑定.csproj", "{5797E06A-32B3-4F16-BC46-D88C8E5A5F48}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WPF绑定元素-2-多绑定", "WPF绑定元素-2-多绑定\WPF绑定元素-2-多绑定.csproj", "{610A264F-5995-4667-8FD9-3494481928FF}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -156,5 +158,9 @@ Global
{5797E06A-32B3-4F16-BC46-D88C8E5A5F48}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5797E06A-32B3-4F16-BC46-D88C8E5A5F48}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5797E06A-32B3-4F16-BC46-D88C8E5A5F48}.Release|Any CPU.Build.0 = Release|Any CPU
{610A264F-5995-4667-8FD9-3494481928FF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{610A264F-5995-4667-8FD9-3494481928FF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{610A264F-5995-4667-8FD9-3494481928FF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{610A264F-5995-4667-8FD9-3494481928FF}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal

View File

@ -0,0 +1,9 @@
<Application x:Class="WPF绑定元素_2_多绑定.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WPF绑定元素_2_多绑定"
StartupUri="MainWindow.xaml">
<Application.Resources>
</Application.Resources>
</Application>

View File

@ -0,0 +1,12 @@
using System.Configuration;
using System.Data;
using System.Windows;
namespace WPF绑定元素_2_多绑定;
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
}

View 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)
)]

View File

@ -0,0 +1,34 @@
<Window x:Class="WPF绑定元素_2_多绑定.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"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<StackPanel>
<Slider Name="TextBlockSlider"
Value="{Binding ElementName=ExactSizeForSlider,Path=Text}"
Maximum="100" Minimum="0" SmallChange="2" LargeChange="5"
TickPlacement="BottomRight" TickFrequency="5" IsSelectionRangeEnabled="True" />
<TextBox Margin="0 8" Name="BunnyTextBox">这是文字内容</TextBox>
<ListBox Margin="0 8" Name="ListBoxColor">
<ListBoxItem Tag="Pink" Foreground="Pink" IsSelected="True">Pink</ListBoxItem>
<ListBoxItem Tag="Red" Foreground="Red">Red</ListBoxItem>
<ListBoxItem Tag="Green" Foreground="Green">Green</ListBoxItem>
</ListBox>
<DockPanel>
<Label> 输入文字大小:</Label>
<TextBox Name="ExactSizeForSlider"
Text="{Binding ElementName=TextBlockSlider,Path=Value}"
VerticalAlignment="Center" />
</DockPanel>
<TextBlock Margin="0 4" Text="{Binding ElementName=BunnyTextBox,Path=Text}"
FontSize="{Binding ElementName=TextBlockSlider,Path=Value}"
Foreground="{Binding ElementName=ListBoxColor,Path=SelectedItem.(ListBox.Tag)}" />
</StackPanel>
</Window>

View File

@ -0,0 +1,26 @@
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
namespace WPF绑定元素_2_多绑定;
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
// 创建一个 Binding 对象
var binding = new Binding("Value")
{
Source = TextBlockSlider,
Delay = 500 // 设置延迟时间
};
// 将 Binding 应用到 TextBox 的 Text 属性上
ExactSizeForSlider.SetBinding(TextBox.TextProperty, binding);
}
}

View File

@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net8.0-windows</TargetFramework>
<RootNamespace>WPF绑定元素_2_多绑定</RootNamespace>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<UseWPF>true</UseWPF>
</PropertyGroup>
</Project>