简体   繁体   中英

Silverlight Wcf Ria service viewmodel combobox

Ok I'll make this very simple: Here are viewmodels :

public class ObjectsModel
{
    public event PropertyChangedEventHandler PropertyChanged = delegate { };

    private string _objectName;
    public string ObjectName
    {
        get
        {
            return _objectName;
        }
        set
        {
            if (value != _objectName)
            {
                _objectName = value;
                PropertyChanged(this, new PropertyChangedEventArgs("ObjectName"));
            }
        }
    }

    public IEnumerable<Object> Objects {get;set;}

    public ICommand AddCommand { get; private set; }
    public ICommand SaveChangesCommand { get; private set; }

    myDomainContext context = new myDomainContext();
    public ObjectsModel()
    {
        objects = context.Objects;
        context.Load(context.GetObjectsQuery());
    }

}

public class InventoryModel
{
    public event PropertyChangedEventHandler PropertyChanged = delegate { };

    public IEnumerable<Inventory> Inventories {get;set;}

    public ICommand AddCommand { get; private set; }
    public ICommand SaveChangesCommand { get; private set; }

    myDomainContext context = new myDomainContext();

    public ObjectsModel()
    {
        objects = context.Objects;
        context.Load(context.GetObjectsQuery());
    }

}

So what I'm trying to do is in my second form where I want to add an inventory for an object, I have to select the object in a combobox. The question is, how do I fill my combobox? Create another instance of the "ObjectsModel" in the InventoryModel? or use another "context" where I would query the other table? Or is there an easier Xaml approach? If I'm not clear, tell me I'll put more examples/code.

tx a lot!

You want to bind the contents of the combobox to a list of items provided by your ViewModel and bind the selected item to another property on the same ViewModel.

Please get into the habit of naming actual view models to end in "ViewModel", rather than "Model", so they do not clash with your other "real" models. It actually looks like you are binding directly to your business models instead of ViewModels (which is not good).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM