我使用Brian Noyes的Pluralsight课程,"WPF MVVM In Depth"作为我的主要来源,他所展示的作品非常出色.
但是,我没有根据在UtilitiesView上单击的按钮切换视图,而是希望根据工具栏按钮(构成VS 2015扩展包的一部分)切换视图,用户可以在其中选择特定实例.
UtilitiesView是由包扩展打开的窗口上的用户控件.所以这是UtilitiesView中的xaml:`
<UserControl.Resources>
<DataTemplate DataType="{x:Type engines:CalcEngineViewModel}">
<engines:CalcEngineView/>
</DataTemplate>
<DataTemplate DataType="{x:Type engines:TAEngineViewModel}">
<engines:TAEngineView/>
</DataTemplate>
</UserControl.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid x:Name="NavContent">
<Grid.ColumnDefinitions>
<ColumnDefinition Width ="*"/>
<ColumnDefinition Width ="*"/>
<ColumnDefinition Width ="*"/>
</Grid.ColumnDefinitions>
<Button Content="Calc"
Command ="{Binding ChangeViewModelCommand}"
CommandParameter="CalculationEngine"
Grid.Column="0"/>
<Button Content="TA"
Command ="{Binding ChangeViewModelCommand}"
CommandParameter="TAEngine"
Grid.Column="1"/>
</Grid>
<Grid x:Name="MainContent"
Grid.Row="1">
<ContentControl Content="{Binding CurrentEngineViewModel}"/>
</Grid>
</Grid>
</UserControl>`
Run Code Online (Sandbox Code Playgroud)
可以看出,有两个按钮通过绑定到ChangeViewModelCommand并传递字符串值("CalculationEngine"或"TAEngine")来切换View.
这是UtilitiesViewModel.cs类:
public class UtilitiesViewModel : BindableBase
{
#region Fields
public RelayCommand<string> ChangeViewModelCommand { …Run Code Online (Sandbox Code Playgroud) 我被要求在我的工作中为系统开发审计.该系统已经完成.我认为EF 6的命令拦截应该适合我的目的.
但是,在这种情况下我们想要知道谁发送了请假,我们希望能够拦截这个插入查询.
using (DataContext context = new DataContext())
{
var result = context.CreateLeavePrerequest(
leaveRequest.LeaveType,
leaveRequest.StartDate,
leaveRequest.EndDate,
leaveRequest.NumberOfDays,
leaveRequest.EmployeeComment,
leaveRequest.HasSupportingDocumentation,
leaveRequest.ResourceTag,
leaveRequest.RemainingBalance,
leaveRequest.ApproverResourceTag,
leaveRequest.CapturerResourceTag,
leaveRequest.SupportingDocumentID,
ref id
);
Run Code Online (Sandbox Code Playgroud)
那么存储过程是:
CREATE PROCEDURE [dbo].[CreateLeavePrerequest]
(
@LeaveType VARCHAR(50) ,
@StartDate DATETIME ,
@EndDate DATETIME ,
@NumberOfDays DECIMAL(18, 5) ,
@EmployeeComment VARCHAR(512) ,
@SickNoteIndicator BIT ,
@ResourceTag INT,
@RemainingBalance DECIMAL,
@ApproverResourceTag INT,
@CapturerResourceTag INT,
@SupportingDocumentID INT,
@id INT = 0 OUT
)
AS
BEGIN
INSERT INTO [ESS PER LVE PreRequest]
( [Resource Tag] , …Run Code Online (Sandbox Code Playgroud) 我正在创建一个类似功能的扩展,我们作为插件.
当我调试扩展,并打开VS的实验实例时,我得到这个:
发生ContextSwitchDeadlock消息:托管调试助手'ContextSwitchDeadlock'在'C:\ Program Files(x86)\ Microsoft Visual Studio 14.0\Common7\IDE\devenv.exe'中检测到问题.附加信息:CLR无法从COM上下文0x1272878转换到COM上下文0x12727c0 60秒.拥有目标上下文/公寓的线程很可能是在非抽空等待或处理非常长时间运行的操作而不抽取Windows消息.这种情况通常会对性能产生负面影响,甚至可能导致应用程序变得无响应或内存使用量随时间不断累积.为了避免这个问题,所有单线程单元(STA)线程都应该使用抽取等待原语(例如CoWaitForMultipleHandles)并在长时间运行操作期间定期泵送消息.
我看过这篇文章: 类似的问题
并从"异常设置"中取消选中ContextSwitchDeadlock,但我对此感到不舒服.
然后我发现这篇文章(特别是Scott Munro的答案): 类似的问题2
并使用步骤进入Thread窗口,但在检查主线程时我只看到这个:
Main Thread Microsoft.VisualStudio.CommonIDE.dll!Microsoft.VisualStudio.CommonIDE.ResourceLoader.FindResource.AnonymousMethod__0
[External Code]
Run Code Online (Sandbox Code Playgroud)
所以这对我没什么帮助.
如何解决ContextSwitchDeadlock?除了在MDA中简单地取消选中它.我还尝试在我的计算机上安装已发布的vsix(未上传到图库),但它使得VS挂在启动画面上.我认为这与整个问题有关.
这是主线程显示的内容(行列转换):
主线程
主线程Microsoft.VisualStudio.CommonIDE.dll!Microsoft.VisualStudio.CommonIDE.ResourceLoader.OpenAssemblyResourceManifest4
Normal
这就是抱怨的Worker线程显示的内容:
工作者线程clr.dll!Thread :: intermediateThreadProc()
ntdll.dll!_NtWaitForSingleObject@12正常
我在callstack中看不到任何内容,或者找不到我的代码忙碌的内容.
我有一个VSTO Excel 2007加载项,应该从app.config文件读取连接字符串,然后让用户决定连接到哪个数据库.这在调试时工作正常,但是当我运行已部署的版本(使用Windows Installer完成)时,根本不读取连接字符串.我已将所有项目的主要输出添加到安装项目中.app.config文件位于ExcelAddIn项目中,但不在Excel标题下.管理连接字符串的类在另一个项目中.
这是我的app.config文件:
<?xml version="1.0"?>
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"/>
</configSections>
<connectionStrings>
<clear/>
<add name="MyEntities" connectionString="metadata=res://*/MyModel.csdl|res://*/MyModel.ssdl|res://*/SymModel.msl;provider=System.Data.SqlClient;provider connection string="data source=myServer;initial catalog=myDB;persist security info=True;user id=myUser;password=myPassword;multipleactiveresultsets=True;App=EntityFramework"" providerName="System.Data.EntityClient"/>
</connectionStrings>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="v11.0"/>
</parameters>
</defaultConnectionFactory>
</entityFramework>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>
Run Code Online (Sandbox Code Playgroud)
我使用以下内容来获取连接字符串:
System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
ConnectionStringsSection csSection = config.ConnectionStrings;
Run Code Online (Sandbox Code Playgroud)
我试图将ExcelAddin.dll.config文件添加到安装文件夹和.proj文件所在的安装项目文件夹中.我已将app.config文件的'Copy to Output Directory'属性设置为'Copy always',将Build Action属性设置为'Content'.
我的app.config文件有什么问题,或者为什么在我运行安装程序后它没有被拾取(连接字符串没有加载到csSection中)?