2017-10-05 76 views
0

我有2個條目。可以用作輸入,也可以用作計算的輸出。當輸入一個值時,另一個被禁用,因此用戶不能輸入值。我的問題是,當禁用條目時,佔位符文本和文本都變成深灰色。儘管已經設置了禁用狀態的文本和佔位符顏色。我嘗試了各種方法來設置顏色,但沒有運氣。它總是被覆蓋。禁用條目時更改背景的顏色沒有問題,但文本不會更改。如何禁用條目的佔位符文本顏色

我已經嘗試使用自定義Entry控件並設置IsEnabled屬性更改時的屬性。此外,我已經嘗試應用包含觸發器的樣式,並且我嘗試在XAML中設置觸發器,沒有任何工作。

有什麼建議嗎?

<Entry 
    HorizontalTextAlignment="Center" 
    Keyboard="Numeric" 
    Placeholder="0" 
    HorizontalOptions="FillAndExpand" 
    IsEnabled="{Binding MinuteEnabled}" 
    Text="{Binding MinuteString, Mode=TwoWay}"> 


    <Entry.Triggers> 
     <Trigger TargetType="Entry" 
      Property="IsEnabled" Value="False"> 
     <Setter Property="BackgroundColor" Value="Yellow" /> 
     <Setter Property="PlaceholderColor" Value="Green" /> 
     <Setter Property="TextColor" Value="Green" /> 

     </Trigger> 
    </Entry.Triggers> 

回答

0

其實這是很難存檔,但更多鈔票的解決方案是有一些隱藏的ENTRA標籤綁定到您的輸出。

這裏有一些示例代碼,您可以使用查看模型進行存檔。

XAML

<Label x:Name="Output1" 
     TextColor="Green" 
     BackgroundColor="Yellow" 
     HorizontalOptions="FillAndExpand" 
     FontSize="Medium" 
     HeightRequest="35" 
     IsVisible="False" /> 
<Entry x:Name="entry1" 
     Keyboard="Numeric" 
     Placeholder="0" 
     HorizontalOptions="FillAndExpand"/> 
<Entry x:Name="entry2" 
     Keyboard="Numeric" 
     Placeholder="0" 
     HorizontalOptions="FillAndExpand"/> 
<Label x:Name="Output2" 
     TextColor="Green" 
     BackgroundColor="Yellow" 
     HorizontalOptions="FillAndExpand" 
     FontSize="Medium" 
     HeightRequest="35" 
     IsVisible="False" /> 

和代碼背後

public partial class MainPage : ContentPage 
{ 
    public MainPage() 
    { 
     InitializeComponent(); 

     entry1.Completed += (s, e) => 
     { 
      // All your logic here or do it on view model 
      entry2.IsVisible = false; 
      Output2.IsVisible = true; 
      Output2.Text = entry1.Text; 
     }; 

     entry2.Completed += (s, e) => 
     { 
      // All your logic here or do it on view model 
      entry1.IsVisible = false; 
      Output1.IsVisible = true; 
      Output1.Text = entry2.Text; 
     }; 
    } 
} 

,你可以添加它清除按鈕,以恢復這兩個條目和標籤。

+0

該死的,我怕這是一種形式的限制。謝謝。 – Sevren

+0

@Sevren您的自定義渲染不起作用?你如何實現它? – FabriBertani