Xamarin.Forms之Button


為什么要講Button,不管是何種UI系統,Button始終是一種很最常見的控件,但是Forms中得Button在使用的過程是出現了一些問題,特此記錄一下

1.IsEnabled屬性

 即使設置了Button得背景色,當IsEnabled="false"的時候,背景色會變成灰色,文字也是會變成灰色

 

2.IsEnable屬性無效的問題

的確有人遇到過這個問題,直接設置IsEnabled="false",Button居然該是可以點擊,這就是一個BUG,截止到v2.2版本,Forms依舊沒有解決

改問題的原因是Command與IsEnabled沖突導致的,如果在Xaml中Command放在IsEnabled的后面,則會出現上面的問題

<Button  Grid.Column="2" Text="點我" IsEnabled="{Binding signIsEnabled}"  Command="{Binding SignMessage}"  Style="{StaticResource DialogButtonStyle}"/>

 

目前有兩種解決方法:

1).在Command中,設置CanExecute直接返回綁定的signIsEnabled,

new Command(()=>{},()=>isSignEnabled);

這樣在isSignEnabled直接設置為false的時候,也是有效的

2).在XAML中,將IsEnabled放在Command的后面,就一切OK了

<Button  Grid.Column="2" Text="點我"   Command="{Binding SignMessage}"   IsEnabled="{Binding signIsEnabled}"   Style="{StaticResource DialogButtonStyle}"/>

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM