MvxSpinner未绑定 [英] MvxSpinner not binding

查看:63
本文介绍了MvxSpinner未绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我需要更改MvxSpinner的文本颜色.我看到您无法通过xaml代码更改颜色,因此我不得不为微调框使用模板.但是,在我将模板用于微调器之前,所有内容都可以与viewModel正确绑定,现在看来,当我使用模板时,无法在viewmodel中找到我的属性.有没有办法将当前视图模型公开给模板?

So I needed to change the text color of my MvxSpinner. I see you can't change the color from the xaml code so I had to do use templates for the spinner. But before I used templates for the spinner everything would bind correctly with the viewModel, now it seems it can't find my properties in the viewmodel when I use templates. Is there a way to expose the current viewmodel to the templates?

下面是我的代码段,如果有帮助的话

Below is my code segments if it helps

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:local="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#FFFFFF">
    <ImageView
        android:src="@drawable/synchramed_trans_300"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/imageView1" />
    <TextView
        android:text="Select Practice"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/textView1"
        android:textColor="#000000" />
    <MvxSpinner
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:textSize="40dp"
        android:textColor="#000000"
        local:MvxItemTemplate="@layout/item_spinner"
        local:MvxDropDownItemTemplate="@layout/item_spinnerdropdown"
        local:MvxBind="ItemsSource PracticeItems; SelectedItem SelectedPracticeItem" />
    <Button
        android:text="Generate Report"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/button1"
        local:MvxBind="Click ReportCommand"
        style="@style/DefaultButtonText"
        android:background="@drawable/button_default_bg" />
</LinearLayout>

Item_Spinner

Item_Spinner

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:local="http://schemas.android.com/apk/res-auto"
    android:background="#fff000"
    android:foreground="#ffffff"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    local:MvxBind="Text Caption" />

Item_SpinnerDropDown

Item_SpinnerDropDown

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:local="http://schemas.android.com/apk/res-auto"
    android:background="#fff000"
    android:foreground="#ffffff"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    local:MvxBind="Text Caption" />

ViewModel

ViewModel

public class HomeViewModel
        : MvxViewModel
    {
        string PracticeName = string.Empty;

        private readonly IMvxMessenger _messenger;
        private readonly IHomeService _homeService;
        public HomeViewModel(IHomeService homeService, IMvxMessenger messenger)
        {
            _homeService = homeService;
            _messenger = messenger;
            _homeService.GetReportList(this);
        }

        public HomeViewModel()
        {

        }

        public async Task InitializeViewModel()
        {
            await GetPractice ();
        }

        private async Task GetPractice()
        {
            try 
            {
                PracticeItems = new ObservableCollection<string>(await _homeService.GetPracticeList(this));
            } 
            catch (Exception ex) 
            {
                //return null;
            }
        }

        private string _selectedItem;
        public string SelectedItem
        {
            get { return _selectedItem; }
            set { _selectedItem = value; RaisePropertyChanged(() => SelectedItem); }
        }

        private string _caption = "sjdfsfkldj";
        public string Caption
        {
            get { return _caption; }
            set { _caption = value; RaisePropertyChanged(() => Caption); }
        }


        public ICommand ReportCommand
        {
            get { return new MvxCommand(() => ShowViewModel<OverviewViewModel>(new { param = SelectedPracticeItem })); }
        }

        public class Practices
        {
            public string ErrorMessage { get; set; }

            public List<string> Practice { get; set; }
        }

        #region Report List Properties

        private List<string> _reportItems;
        public List<string> ReportItems
        {
            get { return _reportItems; }
            set { _reportItems = value; RaisePropertyChanged(() => ReportItems); }
        }

        private string _selectedReportItem;
        public string SelectedReportItem
        {
            get { return _selectedReportItem; }
            set { _selectedReportItem = value; RaisePropertyChanged(() => SelectedReportItem); }
        }

        private ObservableCollection<string> _practiceItems;
        public ObservableCollection<string> PracticeItems
        {
            get { return _practiceItems; }
            set { _practiceItems = value; RaisePropertyChanged(() => PracticeItems); }
        }

        private string _selectedPracticeItem;
        public string SelectedPracticeItem
        {
            get { return _selectedPracticeItem; }
            set { _selectedPracticeItem = value; RaisePropertyChanged(() => SelectedPracticeItem); }
        }
    }

我遇到以下错误-

MvxBind:警告:17.62无法绑定:源属性源不 找到属性:字符串标题

MvxBind:Warning: 17.62 Unable to bind: source property source not found Property:Caption on String

推荐答案

您无需执行任何其他操作即可将VM暴露给模板.我前面有一些Andorid代码,可以完全按照您使用微调器的方式进行操作,一切都很好.

You should not need to do anything extra to expose the VM to the templates. I have some Andorid code in front of me that is doing exactly what you are doing with a spinner and it is all fine.

MvxBind:警告:17.62无法绑定:源属性源未 在String上找到Property:PracticeItems

MvxBind:Warning: 17.62 Unable to bind: source property source not found Property:PracticeItems on String

该MvxBind警告表示您的视图上的ViewModel出了点问题.检查视图的ViewModel设置为

That MvxBind warning is saying something is wrong with the ViewModel on your view. Check what the view's ViewModel is set to

这篇关于MvxSpinner未绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆