郎溪做网站,专门做微信小程序的公司,闸北企业网站制作,wordpress二维码插件2016-10-11 依赖属性demo小样#xff1a; 要求#xff1a;在窗口中点击按钮#xff0c;利用设置“依赖属性”把Label和TextBox控件里的属性值进行改变。 MainWindow.xaml代码#xff1a; Window x:Class依赖属性1.MainWindow xmlnshttp://schemas.m…2016-10-11 依赖属性demo小样 要求在窗口中点击按钮利用设置“依赖属性”把Label和TextBox控件里的属性值进行改变。 MainWindow.xaml代码 Window x:Class依赖属性1.MainWindow xmlnshttp://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:xhttp://schemas.microsoft.com/winfx/2006/xaml TitleMainWindow Height350 Width525 Canvas Width1024 Height768 Label x:Namelabel ContentLabel HorizontalAlignmentCenter VerticalAlignmentCenter Canvas.Left71 Canvas.Top77 BackgroundYellow/ Button x:Namebutton Content点击转换 BackgroundSkyBlue Canvas.Left83 Canvas.Top188 Width68 Clickbutton_Click / TextBox x:Nametextbox1 Width120 Height30 Canvas.Left180 Canvas.Top70 Text12345678/ TextBox x:Nametextbox2 Width120 Height30 Canvas.Left180 Canvas.Top180 / /Canvas/Window MainWindow.xaml.cs代码 //设置依赖属性public static DependencyProperty TextProperty DependencyProperty.Register( Text, typeof(string), typeof(MainWindow), new PropertyMetadata(,PropertyChanged) ); public string Text { get { return (string)GetValue(TextProperty); } set { SetValue(TextProperty, value); } } private static void PropertyChanged(DependencyObject dobj,DependencyPropertyChangedEventArgs e) { MainWindow control (MainWindow)dobj; if (control ! null) { if (control.Text 1) { control.label.Content YNWA!; control.label.FontSize 10; control.textbox1.Text This is anfield!; } else if(control.Text 2) { control.label.Content Make The Dream!; control.label.FontSize 10; control.textbox1.Text This is tianjin anfield!; } } } private void button_Click(object sender, RoutedEventArgs e) { this.Text this.textbox2.Text; }转载于:https://www.cnblogs.com/Owen-ET/p/5949523.html