2017-06-01 51 views
0

如何在B條目中輸入條目文本中輸入的文本,反之亦然?Xamarin格式:如何渲染相同的輸入B條目中的條目文本,反之亦然

我對Xamarin表單開發很新。

ViewModal:下面是Entry字段可綁定對象,這裏每個字段都有其十進制驗證。 要求:如果條目文本更改,則B條目文本應根據輸入的文本進行更改,反之亦然。

在這裏,我面臨着處理OnPropertyChanged問題。

private string _inputValues_PercentTimer; 
    public string InputValues_PercentTimer 
    { 
     get { return _inputValues_PercentTimer; } 
     set 
     { 
      _inputValues_PercentTimer = CalculationActions.DecimalValidation(value, _inputValues_PercentTimer, 1, 0.0, 100.0, ""); 
      OnPropertyChanged("InputValues_PercentTimer"); 
     } 
    } 


    private string _inputValues_AppDepth; 
    public string InputValues_AppDepth 
    { 
     get { return _inputValues_AppDepth; } 
     set 
     { 

      _inputValues_AppDepth = CalculationActions.DecimalValidation(value, _inputValues_AppDepth, 3, 0.000, 100.00, ""); 
      OnPropertyChanged("InputValues_AppDepth"); 
     } 
    } 
+0

我在處理十進制驗證和OnPropertyChanged時遇到問題。 –

+0

而不是說「面臨的問題」,爲什麼你不描述你正在遇到的*具體*問題? – Jason

+0

肯定傑森。 一個條目,B條目文本應該根據A或B中輸入的值同時更改,反之亦然。如果您需要更多信息,請建議您遵循以下步驟並讓我知道 –

回答

0

對不起的英語太差

使用與您的視圖模型,並在B項綁定,交叉引用綁定(我不知道這是正確的項A項)。

This link是關於綁定基礎,它可以幫助你。

下面是一些與此XAML代碼片段: ...

<Slider x:Name="sdrMediumBattery" 
    HorizontalOptions="FillAndExpand" 
    Value="{Binding MediumBattery}"` 
    Maximum="100" 
    Margin="0,0,0,10"/> 

...

<Label x:Name="lblMediumBattery" 
    BindingContext="{x:Reference sdrMediumBattery}" 
    FontSize="Large" 
    HorizontalTextAlignment="Center" 
    WidthRequest="50" 
    Text="{Binding Value, StringFormat='{0:#00}'}"/> 

我使用屬性 '值' 從 'sdrMediumBattery' 視圖(滑塊)並綁定到Label的'Text'屬性。滑塊綁定到我的viewmodel。

+0

謝謝souza。這甚至工作! –

0

我已解決此問題,防止相關屬性之間的死鎖。感謝所有的支持。

private string _inputValues_PercentTimer; 
public string InputValues_PercentTimer 
{ 
    get { return _inputValues_PercentTimer; } 
    set 
    { 
     if (_inputValues_PercentTimer != value && !string.IsNullOrEmpty(value)) 
     { 
      _inputValues_PercentTimer = CalculationActions.DecimalValidation(value, _inputValues_PercentTimer, 1, 0.0, 100.0, ""); 
      double calRes = 5 + double.Parse(_inputValues_PercentTimer); 
      _inputValues_AppDepth = calRes.ToString(); 
      OnPropertyChanged("InputValues_AppDepth"); 
      OnPropertyChanged("InputValues_PercentTimer"); 
     } 
    } 
} 

private string _inputValues_AppDepth; 
public string InputValues_AppDepth 
{ 
    get { return _inputValues_AppDepth; } 
    set 
    { 
     if (_inputValues_AppDepth != value && !string.IsNullOrEmpty(value)) 
     { 
      _inputValues_AppDepth = CalculationActions.DecimalValidation(value, _inputValues_AppDepth, 3, 0.000, 100.00, ""); 
      double calRes = 5 + double.Parse(_inputValues_AppDepth); 
      _inputValues_PercentTimer = calRes.ToString(); 
      OnPropertyChanged("InputValues_PercentTimer"); 
      OnPropertyChanged("InputValues_AppDepth"); 
     } 
    } 
} 
+0

只是一個提示:我建議用諸如nameof(InputValues_PercentTimer)之類的字符串替換像「InputValues_PercentTimer」這樣的字符串,以避免意外地破壞未來的重構 – Slepz

相關問題