深入淺出WPF 第一部分(3)

來源:互聯網
上載者:User

標籤:http   ar   io   color   os   使用   sp   on   檔案   

3.2.3 屬性元素

    <Grid HorizontalAlignment="Center" VerticalAlignment="Center">        <Rectangle x:Name="rectangle" Width="200" Height="120">            <Rectangle.Fill>                <SolidColorBrush Color="Blue" />            </Rectangle.Fill>        </Rectangle>    </Grid>
3.2.4 標記延伸(Markup Extensions)

<Window x:Class="FirstWpfApplication.MainWindow"        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"        Title="Anders" Height="120" Width="296">    <Grid>        <Grid.ColumnDefinitions>            <ColumnDefinition Width="10*"/>        </Grid.ColumnDefinitions>        <Grid.RowDefinitions>            <RowDefinition Height="33"/>            <RowDefinition Height="33"/>        </Grid.RowDefinitions>        <TextBox Name="textBox1" Grid.Row="0" Grid.Column="0" Margin="5"/>        <TextBox Name="textBox2" Grid.Row="1" Grid.Column="0" Margin="5" Text="{Binding ElementName=textBox1, Path=Text, Mode=TwoWay}"/>        <!--textBox2的Text屬性雙向繫結到textBox1的Text屬性-->    </Grid></Window>

3.3 事件處理器與代碼後置

這樣的將邏輯代碼與UI代碼分離、隱藏在UI代碼後面的形式叫做代碼後置.(code behind)

VS IDE提供了一個事件的IDE feature,在xaml中右鍵點擊事件名稱,能夠“Navigate to Event Hander”

x:Code,使用它能夠把本來應該呆在後置代碼裡的C#代碼搬到XAML檔案中來。x:Code的內容一定要使用XML語言的<![[CDATA[...]]>轉義標籤。

 <Grid>        <Button Name="button1" Margin="5" Click="button1_Click"/>    </Grid>    <x:Code>        <![CDATA[            private void button1_Click(object sender, RoutedEventArgs e)            {                MessageBox.Show("button1 clicked...");            }        ]]>    </x:Code>

3.4 匯入程式集和引用當中的名稱空間

在XAML中引用名稱空間的文法是:

xmlns:映射名=“clr-namespace:類庫中名稱空間的名字;assembly=類庫檔案名稱”

xmlns:my="clr-namespace:MyNamespace;assembly=ClassLibrary1"


深入淺出WPF 第一部分(3)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.