1. <Window x:Class="WpfApplication1.Window1"
    2. xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    3. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    4. xmlns:UC="clr-namespace:WpfApplication1"
    5. xmlns:UC1="clr-namespace:WpfControlLibrary1;assembly=WpfControlLibrary1"
    6. Title="Window1" Height="300" Width="300">
    7. <!--
    8. x:Class="WpfApplication1.Window1" 与后台对应 public partial class Window1 : Window
    9. -->
    10. <!--
    11. xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    12. 默认命名空间的控件不用使用前缀
    13. -->
    14. <StackPanel x:Name="stackpanel">
    15. <!--
    16. xmlns:UC="clr-namespace:WpfApplication1"命名空间
    17. 本程序集
    18. -->
    19. <UC:UserControl1></UC:UserControl1>
    20. <!--
    21. xmlns:UC="clr-namespace:WpfControlLibrary1;assembly=WpfControlLibrary1" 命名空间;程序集
    22. 引用程序集
    23. -->
    24. <UC1:UserControl1></UC1:UserControl1>
    25. </StackPanel >
    26. </Window>
    1. <Window x:Class="WpfApplication1.Window1"
    2. xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    3. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    4. xmlns:UC="clr-namespace:WpfApplication1"
    5. xmlns:UC1="clr-namespace:WpfControlLibrary1;assembly=WpfControlLibrary1"
    6. xmlns:sys="clr-namespace:System;assembly=mscorlib"
    7. Title="Window1" Height="300" Width="300">
    8. <Window.Resources>
    9. <sys:String x:Key="name">TEST</sys:String>
    10. <!--
    11. x:Type 将模板或者样式指定在哪一种对象上时需要用type指定。
    12. -->
    13. <Style TargetType="{x:Type TextBox}">
    14. <Setter Property="Background" Value="Red"/>
    15. </Style>
    16. <x:ArrayExtension x:Key="arr" Type="{x:Type sys:Int32}">
    17. <sys:Int32>1</sys:Int32>
    18. <sys:Int32>2</sys:Int32>
    19. <sys:Int32>3</sys:Int32>
    20. </x:ArrayExtension>
    21. </Window.Resources>
    22. <StackPanel x:Name="stackpanel">
    23. <!--
    24. StaticResource用于获取资源的值,值获取在xaml编译的时候完成 xaml里的全局变量
    25. -->
    26. <TextBlock Text="{StaticResource ResourceKey=name}"></TextBlock>
    27. <!--
    28. DynamicResource跟StaticResource唯一不同的是,它是在运行时获取的
    29. -->
    30. <TextBlock Text="{DynamicResource ResourceKey=name}"></TextBlock>
    31. <!--
    32. Binding
    33. -->
    34. <TextBox Height="23" Name="textBox1" Width="120" />
    35. <TextBox Height="23" Name="textBox2" Width="120"
    36. Text="{Binding ElementName=textBox1, Path=Text}" />
    37. <!--
    38. x:Static 主要用于在xaml中获取某个对象的静态值,上代码说话。
    39. 后台 public static string name = "staticTest";
    40. -->
    41. <TextBox Height="23" Text="{x:Static UC:Window1.name}"
    42. Name="textBox3" Width="120" />
    43. <!--
    44. x:null这个就比较简单了,xaml中某某控件设为null就靠它了。
    45. -->
    46. <TextBox Height="23" Text="{x:Null}"
    47. Name="textBox4" Width="120" />
    48. <!--
    49. x:Array 这个主要就是在xaml中创建数组,还是举个例子。
    50. -->
    51. <ListBox ItemsSource="{StaticResource ResourceKey=arr}"></ListBox>
    52. </StackPanel >
    53. </Window>