Windows 8 Store Apps學習(52) 綁定

來源:互聯網
上載者:User

綁定: 與 Element Model Indexer Style RelativeSource 綁定, 以及綁定中的資料轉換

介紹

重新想象 Windows 8 Store Apps 之 綁定

與 Element 綁定

與 Model 綁定

與 Indexer 綁定

對 Style 中的 Setter 進行綁定(綁定靜態資源)

Binding 的一個擴充標記 RelativeSource 的應用

綁定中的資料轉換

樣本

1、示範如何與 Element 綁定,以及 OneTime, OneWay, TwoWay 的區別

Binding/BindingElement.xaml

<Page    x:Class="XamlDemo.Binding.BindingElement"    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"    xmlns:local="using:XamlDemo.Binding"    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"    mc:Ignorable="d">        <Grid Background="Transparent">        <StackPanel Margin="120 0 0 0">                           <!--                本例用於示範如何與 Element 綁定,以及 OneTime, OneWay, TwoWay 的區別            -->                            <!--                OneTime 方式繫結元素            -->            <Slider Name="sliderOneTime" Minimum="1" Maximum="100" Value="10" Width="180" HorizontalAlignment="Left" />            <TextBox Text="{Binding ElementName=sliderOneTime, Path=Value, Mode=OneTime}" Width="150" HorizontalAlignment="Left" />                <!--                OneWay 方式繫結元素(OneWay 是預設)            -->            <Slider Name="sliderOneWay" Minimum="1" Maximum="100" Value="10" Width="180" HorizontalAlignment="Left" Margin="0 50 0 0" />            <TextBox Text="{Binding ElementName=sliderOneWay, Path=Value, Mode=OneWay}" Width="150" HorizontalAlignment="Left" />                <!--                TwoWay 方式繫結元素            -->            <Slider Name="sliderTwoWay" Minimum="1" Maximum="100" Value="10" Width="180" HorizontalAlignment="Left" Margin="0 50 0 0" />            <TextBox Text="{Binding ElementName=sliderTwoWay, Path=Value, Mode=TwoWay}" Width="150" HorizontalAlignment="Left" />            </StackPanel>    </Grid></Page>

2、示範如何與 Model 進行雙向繫結

Binding/BindingModel.xaml

<Page    x:Class="XamlDemo.Binding.BindingModel"    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"    xmlns:local="using:XamlDemo.Binding"    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"    mc:Ignorable="d">        <Grid Background="Transparent">        <StackPanel Margin="120 0 0 0" Name="root">                            <TextBlock Name="lblMsg" FontSize="14.667" />                            <TextBox FontSize="14.667" Text="{Binding Path=Name, Mode=TwoWay}" Margin="0 10 10 0" />            <TextBox FontSize="14.667" Text="{Binding Age, Mode=TwoWay}" Margin="0 10 10 0" />            <ToggleSwitch OffContent="女" OnContent="男" Header="性別" Margin="0 10 10 0">                <ToggleSwitch.IsOn>                    <Binding Path="IsMale" Mode="TwoWay" />                </ToggleSwitch.IsOn>            </ToggleSwitch>                        </StackPanel>    </Grid></Page>

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.