WPF学习(5) -- WPF绑定

一、双向绑定

1.代码示例

<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.代码示例

<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.代码结果

相关推荐

  1. WPF数据

    2024-07-14 05:26:04       35 阅读
  2. WPF.NET开发】

    2024-07-14 05:26:04       58 阅读
  3. wpf ListView 列表demo

    2024-07-14 05:26:04       40 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-14 05:26:04       70 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-14 05:26:04       74 阅读
  3. 在Django里面运行非项目文件

    2024-07-14 05:26:04       62 阅读
  4. Python语言-面向对象

    2024-07-14 05:26:04       72 阅读

热门阅读

  1. 大语言模型系列-Transformer

    2024-07-14 05:26:04       25 阅读
  2. Layer2是什么?为什么需要Layer2?

    2024-07-14 05:26:04       26 阅读
  3. SpinalHDL之实用工具(上篇)

    2024-07-14 05:26:04       25 阅读
  4. 自监督学习和对比学习举例讲解(附代码)

    2024-07-14 05:26:04       23 阅读
  5. web黑马课总结笔记(持续更新)

    2024-07-14 05:26:04       26 阅读
  6. 天童教育:要增强孩子的自理能力

    2024-07-14 05:26:04       25 阅读
  7. 测试工程师面试热门问题(六)

    2024-07-14 05:26:04       22 阅读
  8. JVM:自动垃圾回收

    2024-07-14 05:26:04       25 阅读
  9. 使用openssl生成自签名证书

    2024-07-14 05:26:04       26 阅读
  10. 【TS】如何使用联合类型和交叉类型

    2024-07-14 05:26:04       31 阅读