【问题标题】:C#/Xamarin: not able to access override UIPickerViewModel class ParametersC#/Xamarin:无法访问覆盖 UIPickerViewModel 类参数
【发布时间】:2018-07-14 01:45:05
【问题描述】:

我对扩展 UIPickerViewModel 的类有疑问。 我有一个字符串可以从选择器视图中访问选定的值。即public string SelectedValue {get; set;}。然后在我的类中使用 ViewDidLoad() 方法,我将选择器视图上的模型设置为该类的新实例。 当用户选择值并单击完成按钮时,我想访问他们选择的值并关闭选择器视图,如下所示:

    private void GalaxyDoneClicked()
    {
        this.galaxyTextField.Text = this.galaxyPicker.Model.SelectedValue;    
    }

但我收到错误消息:UIPickerViewModel does not contain a definition for 'SelectedValue' and no extension method 'SelectedValue' accepting a first argument of type 'UIPickerViewModel' could be found ( are you missing a using directive or an assembly reference?)

我是 C# 和 Xamarin 的新手,非常欢迎这里的任何帮助。

【问题讨论】:

    标签: c# xamarin xamarin.ios


    【解决方案1】:

    您需要将galaxyPicker 转换为您的自定义类:

    if ( galaxyPicker is MyCustomPickerViewModelClass myCustomPicker )
    {
       this.galaxyTextField.Text = this.galaxyPicker.Model.SelectedValue; 
    }
    

    其中MyCustomPickerViewModelClass 是您从UIPickerViewModel 派生的自定义类

    【讨论】:

      【解决方案2】:

      这对马丁很有帮助。结果是

          if(galaxyPicker.Model is MyCustomPickerViewModelClass myCustomPickerModel)
          {
              this.galaxyTextField.Text = myCustomPickerModel.SelectedValue;
          }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-01-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-02-24
        • 2013-07-21
        • 1970-01-01
        相关资源
        最近更新 更多