简体   繁体   English

IsEnabled绑定属性不禁用输入字段

[英]IsEnabled bound property not disabling entry field

I have used event to command behaviours on an entry field to trigger a command that disables another on screen entry field when the users starts typing in the current entry field. 我已经使用事件命令输入字段上的行为来触发一个命令,该命令在用户开始在当前输入字段中键入内容时会禁用另一个屏幕输入字段。 To be clear the event to command behaviour is working fine and so is the binding, meaning that I have put debug points on both and they are hit when the code is executed. 为了清楚起见,命令行为的事件可以正常工作,绑定也可以正常工作,这意味着我在两者上都放置了调试点,并且在执行代码时会命中它们。 The problem is that even though they are hit the IsEnabled property does not change on the other entry field. 问题在于,即使它们被命中,IsEnabled属性在其他输入字段上也不会更改。

The code: 编码:

The Xaml: Xaml:

                  <Entry 
                   PlaceholderColor="Black"
                   TextColor="Black"                       
                   Text="{Binding Identity, Mode=OneWayToSource}"
                   Placeholder="Driver ID"
                   Grid.Column="0"
                   Grid.ColumnSpan="2"
                   Grid.Row="1">
                        <Entry.Behaviors>
                            <behaviors:FormEventToCommandBehavior EventName="TextChanged" Command="{Binding TextEntryTrigger}"/>
                        </Entry.Behaviors>
                    </Entry>

                    <Label Text="OR" TextColor="Black"
                   Grid.Column="0"
                   Grid.ColumnSpan="2"
                   Grid.Row="2"
                    VerticalOptions="Center"
                    />

                    <Entry 
                   PlaceholderColor="Black"
                   TextColor="Black"                       
                   Text="{Binding Identity, Mode=OneWayToSource}"
                   Placeholder="Route ID"
                   Grid.Column="0"
                   Grid.ColumnSpan="2"
                   Grid.Row="3"
                    IsEnabled="{Binding RouteIDVis}"/>

The ViewModel: ViewModel:

These command and properties are set in the right place I have just put them here for brevity. 这些命令和属性设置在正确的位置,为了简洁起见,我将它们放在此处。

public ICommand TextEntryTrigger { get; protected set; }

TextEntryTrigger = new Command(() => HandleEntryFieldVisibility());


public bool RouteIDVis
    {
        get { return _routeidvis; }
        set
        {
            _routeidvis = value;
            OnPropertyChanged(nameof(RouteIDVis));
        }
    }

    private void HandleEntryFieldVisibility()
    {
        RouteIDVis = false;
    }

I have left out the code for the event to command because as I stated when putting debug points in all of this they all get hit and I can see the RouteIDVis is being set to false but it does not disable the second entry field. 我已经将事件代码留给命令了,因为正如我在所有调试点中所说的那样,它们都被击中了,而且我可以看到RouteIDVis设置为false,但它不会禁用第二个输入字段。

I have looked around but I cant seem to find a straight answer just some one sentence answers and no proper code answers. 我环顾四周,但似乎找不到一个简单的答案,只有一个句子的答案,却没有正确的代码答案。

Any ideas? 有任何想法吗?

Have you tried using the solution from 您是否尝试过使用来自

https://forums.xamarin.com/discussion/71527/problem-with-binding-isenabled-property-of-an-entry https://forums.xamarin.com/discussion/71527/problem-with-binding-isenabled-property-of-an-entry

It make use of 2 Entry controls. 它使用2个Entry控件。 The first Entry control is disabled while the second Entry control is enabled. 第一个Entry控件被禁用,而第二个Entry控件被启用。 The IsVisible ensures only one control is visible. IsVisible确保只有一个控件可见。

<ContentView Grid.Row="0"
                   Grid.Column="1"
                   IsVisible="{Binding EntryEnabled}">
        <Entry IsEnabled="True"
               Text="{Binding PropertyValue, Mode=TwoWay}"/>
</ContentView>

<ContentView Grid.Row="0"
             Grid.Column="1"
              IsVisible="{Binding EntryEnabled, Converter={StaticResource InverseConverter}}">
        <Entry IsEnabled="False"
               Text="{Binding PropertyValue, Mode=TwoWay}"/>
</ContentView>
<Entry Text="{Binding PropertyValue, Mode=TwoWay}"
       IsEnabled="False"/>

Change order of property, that may be a problem. 更改属性的顺序,这可能是一个问题。 It happened to me when using IsEnabled with button. 当将IsEnabled与按钮一起使用时,发生在我身上。

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

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