簡體   English   中英

IsEnabled綁定屬性不禁用輸入字段

[英]IsEnabled bound property not disabling entry field

我已經使用事件命令輸入字段上的行為來觸發一個命令,該命令在用戶開始在當前輸入字段中鍵入內容時會禁用另一個屏幕輸入字段。 為了清楚起見,命令行為的事件可以正常工作,綁定也可以正常工作,這意味着我在兩者上都放置了調試點,並且在執行代碼時會命中它們。 問題在於,即使它們被命中,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}"/>

ViewModel:

這些命令和屬性設置在正確的位置,為了簡潔起見,我將它們放在此處。

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,但它不會禁用第二個輸入字段。

我環顧四周,但似乎找不到一個簡單的答案,只有一個句子的答案,卻沒有正確的代碼答案。

有任何想法嗎?

您是否嘗試過使用來自

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

它使用2個Entry控件。 第一個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>
<Entry Text="{Binding PropertyValue, Mode=TwoWay}"
       IsEnabled="False"/>

更改屬性的順序,這可能是一個問題。 當將IsEnabled與按鈕一起使用時,發生在我身上。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM