官术网_书友最值得收藏!

Working with inline code in XAML pages

You can write inline programming code (C# or VB.NET) within the XAML page, using the x:Code directive and must be surrounded by <![CDATA[...]]> to escape the contents for XML. This can interact within the same XAML page:

<Window x:Class="MyWpfApplication.MainWindow" 
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
  Title="Main Window" Height="350" Width="525"> 
  <Grid> 
    <Button Click="Button_Click" Content="Click Here" /> 
    <x:Code> 
      <![CDATA[ 
        void Button_Click(object sender, RoutedEventArgs e) 
        { 
          // event implementation 
        }  
      ]]> 
    </x:Code> 
  </Grid> 
</Window> 

Try to avoid using the inline code in the XAML page, as it violates the separation between the designer and the code behind. Also, other language-specific programming features are not supported in inline coding.

主站蜘蛛池模板: 镇坪县| 宝山区| 衡水市| 苏州市| 阿克| 紫金县| 克山县| 黎平县| 常宁市| 香港| 泗洪县| 文化| 区。| 永德县| 唐海县| 奉节县| 北宁市| 淄博市| 蓬安县| 内黄县| 南乐县| 靖远县| 泰顺县| 芦山县| 连云港市| 江源县| 吉首市| 衡南县| 锡林郭勒盟| 固阳县| 都兰县| 邻水| 安溪县| 房产| 苍梧县| 龙井市| 剑阁县| 横峰县| 芮城县| 承德市| 博罗县|