Wpf 笔记

本文详细介绍了WPF应用的生命周期,包括OnStartup、OnSessionEnding、OnExit等关键事件,以及如何在XAML中全局捕获异常。同时展示了如何在控件中设置为null的技巧,并通过XAML与C#结合实现数据触发器和样式应用。

http://www.cnblogs.com/huangxincheng/archive/2012/06/17/2552322.html


Wpf中Application的生命周期

1:OnStartup方法    =>   Startup 事件

2: OnSessionEnding方法 => SessionEnding 事件

     系统关机前调用。

3:OnExit方法 => Exit事件

     应用程序关闭前调用。

4:OnActivated方法 =>  Activated 事件

     应用程序获得焦点的时候触发。

5:OnDeactivated方法 => DeActivated事件

     应用程序失去焦点的时候触发。

全局异常获取

this.DispatcherUnhandledException += new DispatcherUnhandledExceptionEventHandler(...);

x:Static

xmal:

<TextBox Height="23"  Text="{x:Static local:MainWindow.name}"
                 Margin="87,75,0,0" Name="textBox1"  Width="120" />
cs:

public static string name = "名字";

x:null

xaml中某某控件设为null就靠它了。

1     <Grid>
2         <TextBox Height="23"  Text="{x:Null}"
3                  Margin="87,75,0,0" Name="textBox1"  Width="120" />
4     </Grid>


x:Array



DataTrigger,MultiDataTrigger

 6     <Window.Resources>
 7         <Style x:Key="childStyle" TargetType="Control">
 8             <Setter  Property="Background" Value="BurlyWood"/>
 9             <Style.Triggers>
10                 <!-- 绑定当前的radio单选框,如果按钮选中,触发字体设置 -->
11                 <DataTrigger Binding="{Binding ElementName=radio, Path=IsChecked}" Value="True">
12                     <Setter Property="FontSize" Value="20"/>
13                 </DataTrigger>
14             </Style.Triggers>
15         </Style>
16     </Window.Resources>
17     <Grid>
18         <RadioButton Style="{StaticResource ResourceKey=childStyle}" 
19                      Name="radio" Content="我要变成20号字"></RadioButton>
20     </Grid>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值