WPF学习(5) -- WPF绑定

一、双向绑定

1.代码示例

XML 复制代码
<Window x:Class="学习.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:学习"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800">

    <Grid>
        <StackPanel>
            <Slider x:Name="slider" Margin="10"/>
            <TextBox Height="30"  Margin="10" Text="{Binding ElementName=slider,Path=Value}"/>
            <TextBox Height="30"  Margin="10" Text="{Binding ElementName=slider,Path=Value}"/>
            <TextBox Height="30"  Margin="10" Text="{Binding ElementName=slider,Path=Value}"/>
        </StackPanel>
    </Grid>
</Window>

2.代码结果

二、单向绑定

1.代码示例

XML 复制代码
<Window x:Class="学习.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:学习"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800">

    <Grid>
        <StackPanel>
            <Slider x:Name="slider" Margin="10"/>
            <TextBox Height="30"  Margin="10" Text="{Binding ElementName=slider,Path=Value,Mode=OneWay}"/> <!--单向绑定-->
            <TextBox Height="30"  Margin="10" Text="{Binding ElementName=slider,Path=Value,Mode=OneTime}"/><!--绑定第一个数值-->
            <TextBox Height="30"  Margin="10" Text="{Binding ElementName=slider,Path=Value,Mode=TwoWay}"/><!--双向绑定-->
            <TextBox Height="30"  Margin="10" Text="{Binding ElementName=slider,Path=Value,Mode=OneWayToSource}"/><!--单向绑定-->
        </StackPanel>
    </Grid>
</Window>

2.代码结果

相关推荐
calvinpaean13 分钟前
VGGT 论文学习
学习
毕设源码-邱学长17 分钟前
【开题答辩全过程】以 基于Java的公职备考在线学习系统的设计与实现为例,包含答辩的问题和答案
java·开发语言·学习
wdfk_prog34 分钟前
[Linux]学习笔记系列 -- [block][mq-deadline]
linux·笔记·学习
('-')1 小时前
《从根上理解MySQL是怎样运行的》第二十二章学习笔记
笔记·学习·mysql
人邮异步社区2 小时前
想要系统地学习扩散模型,应该怎么去做?
人工智能·学习·程序员·扩散模型
光头程序员2 小时前
vue学习笔记
vue.js·笔记·学习
点亮一颗LED(从入门到放弃)3 小时前
C语言学习笔记
笔记·学习
找了一圈尾巴3 小时前
Python 学习-深入理解 Python 进程、线程与协程(下)
开发语言·python·学习
活跃的煤矿打工人4 小时前
【星海随笔】标准学习
学习
张人玉4 小时前
Prism 框架笔记及实例
c#·wpf·prism