简体   繁体   English

Xamarin Forms IsEnabled MultiTrigger on Entry 不工作

[英]Xamarin Forms IsEnabled MultiTrigger on Entry is not working

I am trying to get an entry IsEnabled property to set based on 2 different boolean values using a MultiTrigger in Xamarin.Forms 4.6.0.726.我正在尝试使用 Xamarin.Forms 4.6.07 中的 MultiTrigger 根据 2 个不同的 boolean 值设置条目 IsEnabled 属性。 I have also tried in the last stable 4.5 version too.我也尝试过上一个稳定的 4.5 版本。

Unfortunately the Entry IsEnabled property seems to remain at whatever the Setter 's value is set to (in the case, true).不幸的是,无论Setter的值设置为什么, Entry IsEnabled属性似乎都保持不变(在这种情况下,为真)。

I have tried the two types of BindingCondition in the below code sample.我在下面的代码示例中尝试了两种类型的 BindingCondition。 The first (uncommented) conditions are bound to the IsVisible properties of two other elements on the page.第一个(未注释的)条件绑定到页面上其他两个元素的 IsVisible 属性。 The StackLayout and the Image will toggle their visibility as expected, however the Entry IsEnabled will not changed. StackLayoutImage将按预期切换其可见性,但Entry IsEnabled不会更改。

The second snip of code binds directly to the values in the ViewModel, implenenting INotifyPropertyChanged but has the exact same result where the IsEnabled value does not change.第二段代码直接绑定到 ViewModel 中的值,实现 INotifyPropertyChanged,但在IsEnabled值不变的情况下具有完全相同的结果。

I have run out of ideas and i'm starting to wonder if this is a bug with Xamarin and MultiTriggers.我已经没有想法了,我开始怀疑这是否是 Xamarin 和 MultiTriggers 的错误。 There doesn't seem to be a huge amount of people using them online, and those that do I have mine set out in what seems to be the most common way in the first set of code.似乎没有大量的人在网上使用它们,而那些我有我的人在第一组代码中似乎是最常见的方式。

<StackLayout x:Name="ButtonsStack" IsVisible="{Binding Invoice.Editable}">
   <!-- Content Here -->    
</StackLayout>

<Image x:Name="InvoiceImage" IsVisible="{Binding IsUploadInvoice}" />

<StackLayout Orientation="Horizontal" HorizontalOptions="End">
    <Entry Text="{Binding Invoice.TotalAmount}">
        <Entry.Triggers>
            <MultiTrigger TargetType="Entry">
                <MultiTrigger.Conditions>

                    <BindingCondition Binding="{Binding Source={x:Reference ButtonsStack}, Path=IsVisible}" Value="True"/>
                    <BindingCondition Binding="{Binding Source={x:Reference InvoiceImage}, Path=IsVisible}" Value="True"/>

                    <!--<BindingCondition Binding="{Binding Invoice.Editable}" Value="True"/>
                    <BindingCondition Binding="{Binding IsUploadInvoice}" Value="True"/>-->

                </MultiTrigger.Conditions>
                <Setter Property="IsEnabled" Value="True"/>
            </MultiTrigger>
        <Entry.Triggers>
    <Entry>
</StackLayout>

As zafar said, you need to set Entry IsEnable="False" by default , when all the conditions are true, the setter makes the Entry's IsEnabled property true.正如zafar所说,您需要默认设置Entry IsEnable="False" ,当所有条件都为真时,setter使Entry的IsEnabled属性为真。

<StackLayout>
            <Entry IsEnabled="False" Text="{Binding Invoice.TotalAmount}">
                <Entry.Triggers>
                    <MultiTrigger TargetType="Entry">
                        <MultiTrigger.Conditions>

                            <BindingCondition Binding="{Binding Source={x:Reference ButtonsStack}, Path=IsVisible}" Value="True" />
                            <BindingCondition Binding="{Binding Source={x:Reference InvoiceImage}, Path=IsVisible}" Value="True" />

                        </MultiTrigger.Conditions>
                        <Setter Property="IsEnabled" Value="True" />
                    </MultiTrigger>
                </Entry.Triggers>
            </Entry>
        </StackLayout>

About Multi triggers, please take a look:关于Multi triggers,请看:

https://docs.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/triggers https://docs.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/triggers

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM