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.代码结果
原文地址:https://blog.csdn.net/Fourglsl/article/details/140401696
免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!