使用外部控件自定义 Silverlight Dataform 的命令

发布于 2024-09-14 17:04:56 字数 1247 浏览 5 评论 0原文

我正在尝试处理 datafrom 外部 datafrom 的内部添加/删除/编辑命令表单按钮控件。我正在使用MVVMLight。例如:要在删除按钮 EventToCommand 中删除,我 Bind Command="{Binding DeleteCurrentItemInDataform, Mode=TwoWay}" CommandParameter="{Binding CurrentItem, ElementName=Dataform1}"

在 ViewModel 代码中:

   DeleteCurrentItemInDataform=new RelayCommand<DataForm>(e=>{ e.DeletingItem+=new EventHandler<CancelEventArgs>(DeletingCurrentItem); });

private void DeletingCurrentItem(object sender, CancelEventArgs e){ 
Cash cd = sender as Cash;
_DataContext.CashDrawers.Remove(cd);
_DataContext.SubmitChanges((op) => {  if (op.HasError)  {MssageBox.Show(op.Error.Message); } else{ MessageBox.Show(cd.CashName + " is deleted."); }    }, null); }

private RelayCommand<DataForm> _deleteCurrentItemInDataform;
    public RelayCommand<DataForm> DeleteCurrentItemInDataform
    {
        get { return _deleteCurrentItemInDataform; }
        set
        {
            if (_deleteCurrentItemInDataform != value)
            {
                _deleteCurrentItemInDataform = value;
                RaisePropertyChanged("DeleteCurrentItemInDataform");
            } 
        }

}

I am trying to handling datafrom's internal Add/Delete/Edit command form button control outside datafrom. I am using MVVMLight so. For example : To have Delete in delete button EventToCommand i Bind Command="{Binding DeleteCurrentItemInDataform, Mode=TwoWay}"
CommandParameter="{Binding CurrentItem, ElementName=Dataform1}"

In ViewModel code:

   DeleteCurrentItemInDataform=new RelayCommand<DataForm>(e=>{ e.DeletingItem+=new EventHandler<CancelEventArgs>(DeletingCurrentItem); });

private void DeletingCurrentItem(object sender, CancelEventArgs e){ 
Cash cd = sender as Cash;
_DataContext.CashDrawers.Remove(cd);
_DataContext.SubmitChanges((op) => {  if (op.HasError)  {MssageBox.Show(op.Error.Message); } else{ MessageBox.Show(cd.CashName + " is deleted."); }    }, null); }

private RelayCommand<DataForm> _deleteCurrentItemInDataform;
    public RelayCommand<DataForm> DeleteCurrentItemInDataform
    {
        get { return _deleteCurrentItemInDataform; }
        set
        {
            if (_deleteCurrentItemInDataform != value)
            {
                _deleteCurrentItemInDataform = value;
                RaisePropertyChanged("DeleteCurrentItemInDataform");
            } 
        }

}

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

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

发布评论

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

评论(1

此生挚爱伱 2024-09-21 17:04:56

我发现使用后面的代码非常简单:
例如对于编辑,只需要做 > Datafrom1.BeginEdit();

I found it is quite simple while using code behind:
for example for edit, just need to do > Datafrom1.BeginEdit();

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