- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这更像是一个评论而不是一个问题,尽管反馈会很好。我的任务是为我们正在做的一个新项目创建用户界面。我们想使用 WPF,我想学习所有可用的现代 UI 设计技术。由于我对 WPF 相当陌生,因此我一直在研究可用的内容。我想我已经决定使用 MVVM Light Toolkit(主要是因为它的“可混合性”和 EventToCommand 行为!),但我也想合并 IoC。所以,这就是我想出的。我已经修改了 MVVM Light 项目中的默认 ViewModelLocator 类,以使用 UnityContainer 来处理依赖项注入(inject)。考虑到 3 个月前我不知道这些术语中的 90% 是什么意思,我认为我走在正确的轨道上。
// Example of MVVM Light Toolkit ViewModelLocator class that implements Microsoft
// Unity 2.0 Inversion of Control container to resolve ViewModel dependencies.
using Microsoft.Practices.Unity;
namespace MVVMLightUnityExample
{
public class ViewModelLocator
{
public static UnityContainer Container { get; set; }
#region Constructors
static ViewModelLocator()
{
if (Container == null)
{
Container = new UnityContainer();
// register all dependencies required by view models
Container
.RegisterType<IDialogService, ModalDialogService>(new ContainerControlledLifetimeManager())
.RegisterType<ILoggerService, LogFileService>(new ContainerControlledLifetimeManager())
;
}
}
/// <summary>
/// Initializes a new instance of the ViewModelLocator class.
/// </summary>
public ViewModelLocator()
{
////if (ViewModelBase.IsInDesignModeStatic)
////{
//// // Create design time view models
////}
////else
////{
//// // Create run time view models
////}
CreateMain();
}
#endregion
#region MainViewModel
private static MainViewModel _main;
/// <summary>
/// Gets the Main property.
/// </summary>
public static MainViewModel MainStatic
{
get
{
if (_main == null)
{
CreateMain();
}
return _main;
}
}
/// <summary>
/// Gets the Main property.
/// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
"CA1822:MarkMembersAsStatic",
Justification = "This non-static member is needed for data binding purposes.")]
public MainViewModel Main
{
get
{
return MainStatic;
}
}
/// <summary>
/// Provides a deterministic way to delete the Main property.
/// </summary>
public static void ClearMain()
{
_main.Cleanup();
_main = null;
}
/// <summary>
/// Provides a deterministic way to create the Main property.
/// </summary>
public static void CreateMain()
{
if (_main == null)
{
// allow Unity to resolve the view model and hold onto reference
_main = Container.Resolve<MainViewModel>();
}
}
#endregion
#region OrderViewModel
// property to hold the order number (injected into OrderViewModel() constructor when resolved)
public static string OrderToView { get; set; }
/// <summary>
/// Gets the OrderViewModel property.
/// </summary>
public static OrderViewModel OrderViewModelStatic
{
get
{
// allow Unity to resolve the view model
// do not keep local reference to the instance resolved because we need a new instance
// each time - the corresponding View is a UserControl that can be used multiple times
// within a single window/view
// pass current value of OrderToView parameter to constructor!
return Container.Resolve<OrderViewModel>(new ParameterOverride("orderNumber", OrderToView));
}
}
/// <summary>
/// Gets the OrderViewModel property.
/// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
"CA1822:MarkMembersAsStatic",
Justification = "This non-static member is needed for data binding purposes.")]
public OrderViewModel Order
{
get
{
return OrderViewModelStatic;
}
}
#endregion
/// <summary>
/// Cleans up all the resources.
/// </summary>
public static void Cleanup()
{
ClearMain();
Container = null;
}
}
}
using GalaSoft.MvvmLight;
using Microsoft.Practices.Unity;
namespace MVVMLightUnityExample
{
public class MainViewModel : ViewModelBase
{
private IDialogService _dialogs;
private ILoggerService _logger;
/// <summary>
/// Initializes a new instance of the MainViewModel class. This default constructor calls the
/// non-default constructor resolving the interfaces used by this view model.
/// </summary>
public MainViewModel()
: this(ViewModelLocator.Container.Resolve<IDialogService>(), ViewModelLocator.Container.Resolve<ILoggerService>())
{
if (IsInDesignMode)
{
// Code runs in Blend --> create design time data.
}
else
{
// Code runs "for real"
}
}
/// <summary>
/// Initializes a new instance of the MainViewModel class.
/// Interfaces are automatically resolved by the IoC container.
/// </summary>
/// <param name="dialogs">Interface to dialog service</param>
/// <param name="logger">Interface to logger service</param>
public MainViewModel(IDialogService dialogs, ILoggerService logger)
{
_dialogs = dialogs;
_logger = logger;
if (IsInDesignMode)
{
// Code runs in Blend --> create design time data.
_dialogs.ShowMessage("Running in design-time mode!", "Injection Constructor", DialogButton.OK, DialogImage.Information);
_logger.WriteLine("Running in design-time mode!");
}
else
{
// Code runs "for real"
_dialogs.ShowMessage("Running in run-time mode!", "Injection Constructor", DialogButton.OK, DialogImage.Information);
_logger.WriteLine("Running in run-time mode!");
}
}
public override void Cleanup()
{
// Clean up if needed
_dialogs = null;
_logger = null;
base.Cleanup();
}
}
}
using GalaSoft.MvvmLight;
using Microsoft.Practices.Unity;
namespace MVVMLightUnityExample
{
/// <summary>
/// This class contains properties that a View can data bind to.
/// <para>
/// Use the <strong>mvvminpc</strong> snippet to add bindable properties to this ViewModel.
/// </para>
/// <para>
/// You can also use Blend to data bind with the tool's support.
/// </para>
/// <para>
/// See http://www.galasoft.ch/mvvm/getstarted
/// </para>
/// </summary>
public class OrderViewModel : ViewModelBase
{
private const string testOrderNumber = "123456";
private Order _order;
/// <summary>
/// Initializes a new instance of the OrderViewModel class.
/// </summary>
public OrderViewModel()
: this(testOrderNumber)
{
}
/// <summary>
/// Initializes a new instance of the OrderViewModel class.
/// </summary>
public OrderViewModel(string orderNumber)
{
if (IsInDesignMode)
{
// Code runs in Blend --> create design time data.
_order = new Order(orderNumber, "My Company", "Our Address");
}
else
{
_order = GetOrder(orderNumber);
}
}
public override void Cleanup()
{
// Clean own resources if needed
_order = null;
base.Cleanup();
}
}
}
public void ShowOrder(string orderNumber)
{
// pass the order number to show to ViewModelLocator to be injected
//into the constructor of the OrderViewModel instance
ViewModelLocator.OrderToShow = orderNumber;
View.OrderView orderView = new View.OrderView();
}
最佳答案
首先,您应该避免服务定位器反模式。
第二,每次要获取OrderView都要设置一个静态变量?这是一个非常丑陋的设计。
关于wpf - 结合 MVVM Light Toolkit 和 Unity 2.0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4512828/
Redux Toolkit 在尝试更新嵌套数组上的状态时给了我突变错误,我认为它是使用 immer 来解决这个问题并简化 reducer。 我的商店看起来像: 状态 -> 表单 -> 部分 我想向现有
DragonRuby Game Toolkit 中好像没有按钮的概念。如何创建按钮等 UI 组件? 最佳答案 按钮(和任何其他 UI 组件)可以解构为 primitives: 按钮有一个点击空间(通常
我正在使用 DragonRuby Game Toolkit 构建游戏。 如何检测一个对象(例如 Sprite)是否与另一个 Sprite 发生碰撞? 这是放置在屏幕上的两个 Sprite 。关于如何检
我正在通过 Template Toolkit 文件为 Template Toolkit 制作一些文档。目标是显示我正在使用的代码以及代码的输出。现在,我正在复制代码并将所有“%”字符替换为“%”字符串
我真的很喜欢 Template Toolkit并且喜欢它如何与 Catalyst 一起使用,但我想要更多“网络高级”工具包。 它可能只是 Web 对象的 *.tt 文件包,例如:Selector、Se
我需要为我正在处理的应用程序使用 Surface 项目模板,但我也想使用 MVVM Light Toolkit。我发现我可以“添加 | 新项目...”并为 View 、 View 模型或定位器选择一个
我们一直在使用 google identity toolkit 在我们的 alpha 和 beta 网站上登录,它非常流畅、简单且易于操作(Alpha 和 beta 用户获得了特定的登录说明)。当我们
已关闭。此问题旨在寻求有关书籍、工具、软件库等的建议。不符合Stack Overflow guidelines .它目前不接受答案。 我们不允许提问寻求书籍、工具、软件库等的推荐。您可以编辑问题,以
我想为 OpenCV 安装 CUDA,但当前的工具包 (7.5) 与 Visual Studio 2015 不兼容。我的问题是 - 安装 VS 2013 Express 是否允许我在 2015 年使用
我在添加 时遇到上述错误extraReducer 到我的 创建切片。 这是一个 react 原生应用程序 这是我的代码: export const login = createAsyncThu
使用 RTK Query , 如何使用获取功能来更新另一个切片的状态? 本质上,我试图让所有相关状态彼此相邻,因此在使用 useLazyGetQuery 查询数据后,我想使用结果并将其存储在现有切片中
我想使用模板工具包获取一个随机数。它不必特别随机。我该怎么做? 最佳答案 嗯,如果您没有(或无法导入)Slash::Test,您可能会遇到问题。 从 TT 的“vanilla”安装,您可以简单地使用
我的计算机上插入了两个屏幕,想知道 JFrame 或 Toolkit 中是否有检测窗口在哪个屏幕上的方法? 我有这个代码: java.awt.Toolkit.getDefaultToolkit().g
我正在使用 java 获取屏幕的尺寸和分辨率。当我运行以下代码时,我得到以下输出。 Toolkit toolkit = Toolkit.getDefaultToolkit (); Dimension
import { createSlice } from '@reduxjs/toolkit' export const countersSlice = createSlice({ name:
我有一个 azure 函数,我想在 IntelliJ IDEA 中本地运行和测试。我按照此处列出的所有步骤进行操作:https://learn.microsoft.com/en-us/azure/az
使用 VBA 我想将当前 word 文档的副本发送到 Web 服务?如何将当前文档作为字节数组获取? 我知道如何使用网络服务只是不确定如何将当前文件作为二进制对象发送? 附言从今天早上开始我一直在使用
如果要通过插件系统添加函数和/或虚拟方法,我想将自己的指令添加到Template Toolkit中。在不深入Template::Grammar的情况下,是否容易做到这一点?还有什么我可以在CPAN上学
如何使用 RTK 将整个数组分配给我的 intialState 对象? 做state = payload或 state = [...state, ...payload]不更新任何东西。 例子: con
我正在为我的网站使用谷歌翻译器。我想隐藏谷歌翻译器的顶部栏让我知道如何隐藏那个? 请在此处查看我的网站链接 http://www.rewords.com让我知道我要隐藏那个酒吧? 谢谢 最佳答案 通过
我是一名优秀的程序员,十分优秀!