WPF点滴
1、x:Code将后置代码搬到XAML文件里,需要使用XML语言的<![CDATA[…]>转义标签:
<x:Code> <![CDATA[ private void button1_Click(object sender, RoutedEventArgs e) { MessageBox.Show("Bye! Code-Behind!"); } ]]> </x:Code>
2、xmlns:映射名=”clr-namespace:类库中名称空间的名字;assembly=类库文件名” (xmlns:XML Namespace缩写)
3、string.IsNullOrEmpty()
4、默认情况字段访问级别internal, 使用x:FieldModifier改变访问级别(例如<TextBox x:Name=”textBox1” x:FieldModifier=”public” Margin=”5”/>)
5、检索资源:x:Key
<Window x:Class="WpfApplication1.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:sys="clr-namespace:System;assembly=mscorlib" Title="MainWindow" Height="350" Width="525"> <Window.Resources> <sys:String x:Key="myString">Hello WPF Resource!</sys:String> </Window.Resources> <StackPanel> <TextBox Text="{StaticResource ResourceKey=myString}" Margin="5"/> <TextBox x:Name="textBox1" Margin="5"/> <Button Content="Show" Click="Button_Click"/> </StackPanel> </Window> private void Button_Click(object sender, RoutedEventArgs e) { string str = this.FindResource("myString") as string; this.textBox1.Text = str; }
6、x:Shared -与x:Key配合使用,如果x:Shared为true(默认值)每次检索出的对象都是同一个对象,如果为false每次检索出的对象都是这个对象的一个新副本。
浙公网安备 33010602011771号