WPF Binding表达式
生活随笔
收集整理的這篇文章主要介紹了
WPF Binding表达式
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
前言:
WPF BindingBinding表達(dá)式的使用,可以很方便的綁定參數(shù)和更新界面數(shù)據(jù)。
1.界面添加控件,并設(shè)置對應(yīng)屬性的Binding表達(dá)式,例如:
<Window x:Class="WpfApp1.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:WpfApp1"mc:Ignorable="d"Title="MainWindow" Height="450" Width="800"><Grid><StackPanel><TextBlock FontSize="18">請掃碼:</TextBlock><TextBox MinWidth="200" Height="252" Margin="2" Text ="{Binding BarID}"></TextBox></StackPanel></Grid> </Window>2.編寫B(tài)inding類,例如:
public class MainUI : INotifyPropertyChanged{private string _BarID;public string BarID{get { return _BarID; }set{_BarID = value;if (PropertyChanged != null){this.PropertyChanged.Invoke(this, new PropertyChangedEventArgs("BarID"));}}}public event PropertyChangedEventHandler PropertyChanged;}3.當(dāng)前界面賦值給這個(gè)Binding類:
3.1實(shí)例化Binding類:
MainUI mainUI = new MainUI();3.2,界面賦值:
this.DataContext = mainUI;3.3 調(diào)用:
mainUI.BarID = "123";此時(shí)界面上的TextBox 同樣顯示“123”。
總結(jié)
以上是生活随笔為你收集整理的WPF Binding表达式的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 技能高考计算机专业考什么,2016年技能
- 下一篇: Hulu校招补录已开始,1年内工作经验也