【问题标题】:IsEnabled bound property not disabling entry fieldIsEnabled 绑定属性未禁用输入字段
【发布时间】:2018-06-20 18:24:29
【问题描述】:

当用户开始在当前输入字段中输入时,我使用事件来命令输入字段上的行为来触发禁用另一个屏幕输入字段的命令。 需要明确的是,命令行为的事件工作正常,绑定也是如此,这意味着我已经在两者上放置了调试点,并且在执行代码时它们会被命中。问题是即使它们被击中,其他输入字段的 IsEnabled 属性也不会改变。

代码:

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}"/>

视图模型:

这些命令和属性设置在正确的位置,为了简洁起见,我只是把它们放在这里。

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;
    }

我省略了要命令的事件的代码,因为正如我在将调试点放入所有这些时所说的那样,它们都会被命中,我可以看到 RouteIDVis 被设置为 false,但它不会禁用第二个输入字段.

我环顾四周,但似乎找不到一个直接的答案,只有一句话答案,没有正确的代码答案。

有什么想法吗?

【问题讨论】:

    标签: c# xamarin xamarin.forms


    【解决方案1】:

    您是否尝试过使用来自

    的解决方案

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

    它利用了 2 个入口控件。第一个 Entry 控件被禁用,而第二个 Entry 控件被启用。 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>
    

    【讨论】:

      【解决方案2】:
      <Entry Text="{Binding PropertyValue, Mode=TwoWay}"
             IsEnabled="False"/>
      

      更改属性顺序,这可能是个问题。使用 IsEnabled 和按钮时发生在我身上。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-05-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多