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

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.

主站蜘蛛池模板: 邢台市| 漠河县| 开原市| 益阳市| 定结县| 炉霍县| 太白县| 秦安县| 甘谷县| 遂平县| 高安市| 介休市| 黄石市| 罗山县| 翁源县| 博野县| 抚州市| 鄱阳县| 南涧| 确山县| 正宁县| 仁布县| 杭锦旗| 紫金县| 岳普湖县| 祁门县| 杭锦后旗| 离岛区| 洛南县| 民县| 天长市| 成安县| 龙里县| 乳源| 马尔康县| 长寿区| 新民市| 错那县| 宁晋县| 新竹县| 鞍山市|