zoukankan      html  css  js  c++  java
  • [转] WPF – Editing Mode with Save and Cancel Capability

    A common scenario that is required by applications is the ability to show an entity in a view mode, and when the user wishes to edit that entity, another view is loaded in edit mode.   In most cases, you would allow the user to save or cancel his changes.

    To illustrate the concept, consider the following interface -

    image When a user clicks ‘Edit’:        
    image

    Usually, in a MVVM application, you would have a view model for each list item on the left screenshot.   When the user clicks ‘Edit’ and the editable view is shown as modal dialog, you may want to use the same view model.

    However, if it is the same instance, how would you support cancelling the save operation. Additionally, how would you prevent that changes in the edit mode won’t be reflected in the view mode until the user chooses to save the changes. (If you use bindings, the change would reflect in the view mode as well, as long as the binding is active and the source is updated).

    Well, there are numerous ways to go about it.

      1. Use the same instance: To use the same actual instance, a common approach is to define all the bindings in the editable view with update source trigger set to ‘Explicit’.      This gives you the ability to save state explicitly when the user chooses to save his changes.      This method isn’t suitable for all the cases. If you have more than a plain simple view model where properties may set other properties or commands can be invoked from the edit view – you’re in a dead end. Plus, you can’t use the IDataErrorInfo validation model since the bindings don’t update the source nor calls its validation methods.     
      2. Use a separate instance using some sort of cloning and merging methods: To support more advanced scenarios, or simply provide a complete solution, you would generally prefer binding the editable view to a new instance.      Obviously, you would need to construct the new instance, either imperative instantiation/cloning or use serialization which is quite a common technique in this scenario.      Finally, if the user chooses to save his changes, you would need to merge back the changes to the instance in the view mode or simply replace it with the new instance.
  • 相关阅读:
    官方示例之地球模块十:拔高GeoPolygon
    全景虚拟漫游技术实现(three.js vs ThingJS) Javascript 3D开发 前端 物联网 webgl 三维建模 3D模型 虚拟 全景
    一个3D城市地图应用工具,等你获取 3D 全景 可视化
    H5动画优化之路
    CSS3实现气泡效果
    清除浮动方法总结
    静态页面参数传递&回调函数写法&快速排序的实现方法
    使用SeaJS实现模块化JavaScript开发(新)
    《无懈可击的Web设计》_灵活的文字
    深入探究JavaScript中的比较问题
  • 原文地址:https://www.cnblogs.com/CSharpSPF/p/2872738.html
Copyright © 2011-2022 走看看