Silverlight Wcf Ria 服务视图模型组合框

发布于 2024-11-25 18:27:03 字数 1512 浏览 2 评论 0原文

好吧,我会让这变得非常简单!这里是视图模型:

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());
    }

}

所以我想做的是在第二种形式中,我想为一个对象添加库存,我必须在组合框中选择该对象。问题是,如何填写组合框?在 InventoryModel 中创建“ObjectsModel”的另一个实例?或者使用另一个“上下文”来查询另一个表?或者有更简单的 Xaml 方法吗?如果我不清楚,请告诉我,我将提供更多示例/代码。

发送很多!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦醒灬来后我 2024-12-02 18:27:03

您希望将组合框的内容绑定到 ViewModel 提供的项目列表,并将所选项目绑定到同一 ViewModel 上的另一个属性。

请养成命名实际视图模型以“ViewModel”而不是“Model”结尾的习惯,这样它们就不会与其他“真实”模型发生冲突。实际上看起来您是直接绑定到业务模型而不是 ViewModel(这不好)。

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).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文