English 中文(简体)
“你肯定了吗?”的推动。 部分观点或纯粹观点?
原标题:"Are you sure?" prompts. Part of the ViewModel or purely the view?
  • 时间:2012-04-19 11:25:38
  •  标签:
  • c#
  • wpf
  • mvvm

我正在与什么地方做“你们肯定吗?” 我的MSV WPF照相。

我倾向于认为这些只是观点的一部分。 如果《观点》暴露了<代码>DeleteCommand,那么我将期望该指挥部立即删除。

为了将这些催复函纳入《观点》中,它必须披露一个单独的<代码>RequestDeleteCommand,一个DeletePromptItem 财产,以便及时对它具有约束力,而且这也可以是显示其迅速性的一个触发因素。

Even with this, there s nothing stopping a unit test calling DeleteCommand directly, unless I put specific logic in the ViewModel to require DeletePromptItem to match the item supplied as an argument to DeleteCommand.

However, this all just seems like noise in the ViewModel to me. The prompt is more a user interface issue to guard against misclicks etc. To me this suggests it should be in the view with a confirmed prompt calling the DeleteCommand.

任何想法?

最佳回答
问题回答

然而,这似乎都像在我面前的《观点》中那样明智。 警示更是一个用户界面问题,以防出现故障等。 对我来说,这建议应当得到确认,即立即要求删除《公约》。

我同意这一看法,认为应如此处理,因为最终看法是用户所看到、与而不是观点模式互动。 您的意见一旦得到用户的确认,即应当援引<代码>DeleteCommand,然后在您看来采用该代码。

我认为,除非你重新测试这种观点,否则单位测试不会真正与用户互动有任何关系。

我认为这取决于迅速,但一般而言,需要促使用户使用的密码逻辑往往在任何方面都看上去,例如,用户要求一个子公司删除一个清单项目,在证书中发出指令,逻辑是正确的,而且显然这可能会影响到另一个实体,因此使用者必须选择他们希望做什么,此时,你不应要求让用户看到任何其他选择,而是在证书中处理。 这是我一直不满意的事,但我只是在我的基层考试和测验台上写了“公司”方法,称“方言服务” prompt误迅速,真实或虚假:

    /// <summary>
    /// A method to ask a confirmation question.
    /// </summary>
    /// <param name="messageText">The text to you the user.</param>
    /// <param name="showAreYouSureText">Optional Parameter which determines whether to prefix the message 
    /// text with "Are you sure you want to {0}?".</param>
    /// <returns>True if the user selected "Yes", otherwise false.</returns>
    public Boolean Confirm(String messageText, Boolean? showAreYouSureText = false)
    {
        String message;
        if (showAreYouSureText.HasValue && showAreYouSureText.Value)
            message = String.Format(Resources.AreYouSureMessage, messageText);
        else
            message = messageText;

        return DialogService.ShowMessageBox(this, message, MessageBoxType.Question) == MessageBoxResult.Yes;
    }

对于我来说,这是这些灰色交叉地区之一,我有时无法在多国机器设备中找到一个坚定的答案,因此对其他les器方法感兴趣。

Have a look at this:

http://andrewtokeley.net/archive/07/25/mvm-and-confirmation-dialogs.aspx” rel=“nofollow”>MVVER 和 确认 Dialogs

I use a similar technique in my view models because I believe that it is part of the view model to ask if it will proceed with the deletion or not and not of any visual object or view. With the described technique your model does not refer to any visual references which I don t like but to some kind of service that call a confirmation dialog or a message box or whatever else.

我过去处理此事的方式是在Gis Model举行活动,在需要展示方言时发射。 The View hooks into the event and Hands showing the accreditation dialog, and得通过Args将结果退回给打电话者。

在个人方面,我认为它只是观点的一部分,因为没有数据。

我通过使用<代码>EventAggregator的模式来解决这类问题。

可查阅http://www.wintellect.com/CS/blogs/jlikness/archive/2009/09/29/decoupled-childwindow-dialogs-with-prism-in-silverlight-3.aspx”rel=“nofollow”>。

在把旧的温树 app带给世界森林基金时,兰经。 我认为,必须牢记的是,世界森林论坛通过在观点模式与对事件的看法之间发出信号(即:< 守则> 指明了PropertyChanged.PropertyChanged、 INotificationDataErrorInfo.ErrorsChanged等)。 我解决这一问题的办法就是采取这一榜样,并以此为榜样。 我认为模式:

/// <summary>
/// Occurs before the record is deleted
/// </summary>
public event CancelEventHandler DeletingRecord;

/// <summary>
/// Occurs before record changes are discarded (i.e. by a New or Close operation)
/// </summary>
public event DiscardingChangesEvent DiscardingChanges;

然后可以听取这些活动的意见,如有必要,则促使用户参加,如果主动取消活动。

请注意,<代码>CancelEventHandler按框架界定。 但是,关于<代码>丢弃Changes,你需要一个三州的成果,表明你想如何操作(即,除改动、抛弃改动或取消你正在做的工作)。 为此,我刚刚发言:

public delegate void DiscardingChangesEvent(object sender, DiscardingChangesEventArgs e);

public class DiscardingChangesEventArgs
    {
        public DiscardingChangesOperation Operation { get; set; } = DiscardingChangesOperation.Cancel;
    }

public enum DiscardingChangesOperation
    {
        Save,
        Discard,
        Cancel
    }

I tried to come up with a better naming convention, but this was the best I could think of.

因此,将其付诸行动,就象:

ViewModel (this is actually a base class for my CRUD-based view models):

protected virtual void New()
{
    // handle case when model is dirty
    if (ModelIsDirty)
    {
        var args = new DiscardingChangesEventArgs();    // defaults to cancel, so someone will need to handle the event to signal discard/save
        DiscardingChanges?.Invoke(this, args);
        switch (args.Operation)
        {
            case DiscardingChangesOperation.Save:
                if (!SaveInternal()) 
                    return;
                break;
            case DiscardingChangesOperation.Cancel:
                return;
        }
    }

    // continue with New operation
}

protected virtual void Delete()
{
    var args = new CancelEventArgs();
    DeletingRecord?.Invoke(this, args);
    if (args.Cancel)
        return;

    // continue delete operation
}

View:

<UserControl.DataContext>
    <vm:CompanyViewModel DeletingRecord="CompanyViewModel_DeletingRecord" DiscardingChanges="CompanyViewModel_DiscardingChanges"></vm:CompanyViewModel>
</UserControl.DataContext>

观点:

private void CompanyViewModel_DeletingRecord(object sender, System.ComponentModel.CancelEventArgs e)
{
    App.HandleRecordDeleting(sender, e);
}

private void CompanyViewModel_DiscardingChanges(object sender, DiscardingChangesEventArgs e)
{
    App.HandleDiscardingChanges(sender, e);
}

两种固定方法属于上诉类别,每个观点都可以使用:

public static void HandleDiscardingChanges(object sender, DiscardingChangesEventArgs e)
{
    switch (MessageBox.Show("Save changes?", "Save", MessageBoxButton.YesNoCancel))
    {
        case MessageBoxResult.Yes:
            e.Operation = DiscardingChangesOperation.Save;
            break;
        case MessageBoxResult.No:
            e.Operation = DiscardingChangesOperation.Discard;
            break;
        case MessageBoxResult.Cancel:
            e.Operation = DiscardingChangesOperation.Cancel;
            break;
        default:
            throw new InvalidEnumArgumentException("Invalid MessageBoxResult returned from MessageBox.Show");
    }
}

public static void HandleRecordDeleting(object sender, CancelEventArgs e)
{
    e.Cancel = MessageBox.Show("Delete current record?", "Delete", MessageBoxButton.YesNo) == MessageBoxResult.No;
}

在这些静态方法中集中使用方言箱,让我们能够轻易地为后来的习俗方言交换。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...