C#和WPF的总结(一)

1.附加属性(Attached Properties)
控件放到布局里之后,会附加布局的属性
作用就是将属性与数据类型(宿主)解耦
让数据类型的设计更加合理

2.if(!“true”.Equals(JsonConfigHelper.getConfig(“showTestButton”)))
显示测试按钮

	TimeSpan(int days,int hours,int minutes,int seconds,int millisecond);
	天时分秒毫秒
	时分秒毫秒
	时分秒
	

3.各种组件及其成员

在这里插入图片描述
在这里插入图片描述

在这里插入图片描述
在这里插入图片描述

在这里插入图片描述

在这里插入图片描述
4.binding的用法

Simple Binding.xaml


<Window...
	Title = "Simple Binding">
	<StackPanel>
		<TextBox x:Name="TextBoxName" BorderBrush="Black" Margin="5"/>
		<Button Content="Add Age" Margin="5" Click="Button_Click"/>
	</StackPanel>
</Window>



Simple Binding.cs

public partial class Window1:Window
{
	Student stu;
	public Window1()
	{
		InitialzeComponent();
		
		//准备数据源
		stu = new Student();
		
		//准备Binding
		Binding bingding = new Binding();
		binding.Source = stu;
		binding.Path = new PropertyPath("Name");
		
		//使用Binding连接数据源与Binding目标
		BindingOperations.SetBinding(this.textBoxName,TextBox.TextProperty,binding);
		
	}
	
	private void Button_Click(object sender,RoutedEventArgs e)
	{
		stu.Name += "Name";
	}
	
}

以上步骤可以三合一
public Window1()
{
	InitialzeComponent();
	//三合一操作
	this.textBoxName.SetBinding(TextBox.TextProperty,new Binding("Name"))
	{
	}
}

5.x:code可以在标签内写入C#代码

使用style标签来指定所有Button的样式

<Window.Resources>
	<style x:key = "{x:Type Button}" TargetType = "{x:Type Button}"/>
		<setter Property = "width" Value = "60"/>
		<setter Property = "height" Value = "70"/>
		<setter Property = "color" Value = "black"/>
	</style>
</Window.Resources>

<StackPanel>
	<Button Content = "123"/>
	<Button Content = "1234" style = "{x:Null}"/>
</StackPanel>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值