星期二, 8月 08, 2017

[X.Form] Multi Trigger - 任一輸入

根據這篇官方文章 Triggers 的練習,該範例和筆記
都很類似,該範例是任一個 Entry 內有輸入,Button 就可以啟用

Xaml
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:local="clr-namespace:MVVMPractice"
             x:Class="MVVMPractice.XF3_MultiTrigger">
 
    <ContentPage.Content>
        <StackLayout HorizontalOptions="Center" VerticalOptions="Center">
            <Entry x:Name="email" Placeholder="請輸入Email" Text="" WidthRequest="150"></Entry>
            <Entry x:Name="phone" Placeholder="請輸入電話" Text="" WidthRequest="150"></Entry>
            <Button Text="OK" IsEnabled="True">
                <Button.Triggers>
                    <MultiTrigger TargetType="Button">
                        <MultiTrigger.Conditions>
                            <BindingCondition Binding="{Binding Source={x:Reference email} , Path=Text.Length}" Value="0"></BindingCondition>
                            <BindingCondition Binding="{Binding Source={x:Reference phone} , Path=Text.Length}" Value="0"></BindingCondition>
                        </MultiTrigger.Conditions>
                        <Setter Property="IsEnabled" Value="False"></Setter>
                    </MultiTrigger>
                </Button.Triggers>
            </Button>
        </StackLayout>
    </ContentPage.Content>
</ContentPage>

執行結果-1

[X.Form] Multi Trigger -1

執行結果-2

[X.Form] Multi Trigger -2

執行結果-3

[X.Form] Multi Trigger -3

沒有留言:

張貼留言