我已经将问题缩小到以下具有三列DataGrid的示例.
XAML:
<Window x:Class="DataGridColumnTemplate_NotFiringAddingNewItem.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<DataGrid x:Name="dg" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" Height="299" AutoGenerateColumns="False" Width="497" AddingNewItem="dg_AddingNewItem" CanUserAddRows="True">
<DataGrid.Columns>
<DataGridTemplateColumn Header="DateWorks">
<DataGridTemplateColumn.CellEditingTemplate>
<DataTemplate>
<DatePicker SelectedDate="{Binding InvoiceDate}" />
</DataTemplate>
</DataGridTemplateColumn.CellEditingTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn Header="DateDoesn'tWork">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<DatePicker SelectedDate="{Binding InvoiceDate}" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
<DataGridTemplateColumn.CellEditingTemplate>
<DataTemplate>
<DatePicker SelectedDate="{Binding InvoiceDate}" />
</DataTemplate>
</DataGridTemplateColumn.CellEditingTemplate>
</DataGridTemplateColumn>
<DataGridTextColumn Header="Text" Binding="{Binding Description}"/>
</DataGrid.Columns>
</DataGrid>
</Grid>
</Window>
Run Code Online (Sandbox Code Playgroud)
C#:
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
List<JobCostEntity> l = new List<JobCostEntity>()
{
new JobCostEntity() { …Run Code Online (Sandbox Code Playgroud) 如果我改变了......
EventSource(Name="BasicLogger")
public class BasicLogger : EventSource { ... }
Run Code Online (Sandbox Code Playgroud)
对...
EventSource(Name="HardymanDatabaseLog")
public class BasicLogger : EventSource { ... }
Run Code Online (Sandbox Code Playgroud)
...我仍然收到日志消息,但它们已损坏.
消息没有到达,或者它们是由当前项目中甚至不存在的缺失/删除/删除方法格式化的!
由于某些未知原因,特定字符串'HardymanDatabaseLog'存在问题
我认为这可能归结为一个在某个地方表现出来的腐败仪器清单.
请继续阅读以了解更多信息 ...!(谢谢:o))
我有一个简单的控制台应用程序,EnterpriseLibrary.SemanticLogging通过nuget包引用.
使用这里的示例代码,我添加了一个BasicLogger类.
当我运行我的简单应用程序时......
using System.ComponentModel;
using System.Diagnostics.Tracing;
namespace Etw
{
class Program
{
static void Main(string[] args)
{
BasicLogger.Log.Error("Hello1");
BasicLogger.Log.Critical("Hello2");
}
}
[EventSource(Name = "BasicLogger")]
public class BasicLogger : EventSource
{
public static readonly BasicLogger Log = new BasicLogger();
[Event(1, Message = "{0}", Level = EventLevel.Critical)] …Run Code Online (Sandbox Code Playgroud) 我正在尝试在C#.NET 4.6.1 WPF项目中添加对"Microsoft Outlook 16.0对象库"的引用,因为我已经安装了Office 2016.以前版本的对象库与2016版本的办公室不兼容.
如果我使用Excel的VBA编辑器,则会列出"Microsoft Outlook 16.0对象库"并存在C:\Program Files\WindowsApps\Microsoft.Office.Desktop_16010.9126.2116.0_x86_8wekyb3d8bbwe\VFS\ProgramFilesCommonX86\Microsoft Shared\OFFICE16\MSOUTL.OLB,如下所示:
但是,当我使用Visual Studio时,COM选项卡不会列出"Microsoft Office 16.0对象库",当我尝试浏览时C:\Program Files\WindowsApps,我得到"您目前没有权限访问此文件夹",然后单击"继续"(获取访问权限导致"您被拒绝访问此文件夹的权限".
基本上,Office 2016 dll似乎隐藏在人,狗和本地管理员无法访问的文件夹中.
我要做的就是连接到打开的Outlook应用程序,然后发送带有附件的电子邮件,所以或许还有一个问题是,是否有一些新的方式与Outlook 2016进行通信而未出现我的Googleathon?
另外值得注意的是,我的办公室版本是作为"Windows应用商店应用程序"安装的,因此没有出现在通常的"添加/删除程序"列表中,因此我找不到任何"修复"选项进行安装.
谢谢.
进一步调查显示我正在做正确的事情 - 尝试添加COM引用到'Microsoft Outlook 16.0对象库'现在是目标Outlook的正确方法... /sf/answers/1471289291/.
我检查了GAC,并且没有注册程序集.我已经通过"应用和功能"右键单击开始菜单选项进行了修复,但它们仍然没有出现 - 就好像Windows应用商店应用只是将他们的dll推入Program Files\WindowsApps\*文件夹,并且不打扰注册他们在GAC.
在回答非常感谢的评论!
使用以下代码
Outlook.Application application = (Outlook.Application)Marshal.GetActiveObject("Outlook.Application");
Run Code Online (Sandbox Code Playgroud)
如果我使用nuget Microsoft.Office.Interop.Outlook包,我会得到一个System.Runtime.InteropServices.COMException: 'Invalid class string (Exception from HRESULT: 0x800401F3 (CO_E_CLASSSTRING))'例外.
如果我尝试通过"添加引用"的"程序集/扩展"选项卡使用Microsoft Outlook 15.0 Object Library或Microsoft Outlook 14.0 Object Library引用,则会出现System.Runtime.InteropServices.COMException: 'Invalid class string (Exception from HRESULT: 0x800401F3 …
使用 ReactiveUI 时,可以在 xaml 中设置绑定...
<TextBox x:Name="SomeProperty" Text="{Binding SomeProperty}" />
Run Code Online (Sandbox Code Playgroud)
或在后面的代码中
this.Bind(ViewModel, vm.SomeProperty, v => v.SomeProperty.Text);
Run Code Online (Sandbox Code Playgroud)
似乎在某些情况下(例如绑定到 ListBox 中的子对象),使用该.xaml选项似乎是唯一的方法
例如
<ListView>
<ListView.ItemTemplate>
<DataTemplate DataType="ListViewItem">
<TextBox Text="{Binding ChildViewModelProperty}" />
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
Run Code Online (Sandbox Code Playgroud)
我用错了{Binding }还是我可以混合搭配.xaml,code behind我认为合适?!
当您查找值时,Scripting.Dictionary喜欢无缘无故地添加值!以30秒的示例演示:
创建一个新的工作表,并填写 A1:A4 = {1,2,3,4}
插入一个新的vba模块并添加此代码
Public Sub test()
Dim rowIndex As Integer
'
Dim dict As Scripting.Dictionary
Set dict = New Scripting.Dictionary
For rowIndex = 1 To 4
dict.Add Trim(Sheet1.Cells(rowIndex, 1).Value), rowIndex
Dim notEvenAddingSoWhyAreYouAdding As Variant
notEvenAddingSoWhyAreYouAdding = dict(Sheet1.Cells(rowIndex, 1).Value)
Next rowIndex
End Sub
Run Code Online (Sandbox Code Playgroud)
设置断点 Next rowIndex
运行子并检查的值dict。现在,它具有两个值"1"和1,如下图所示:
什么。的。地狱?!
我意识到我已经Trim(...)在该dict.Add()行中使用了该函数,这意味着正在使用两个不同的键,但是为什么在执行查找时为什么要添加一个额外的值呢?那毫无意义-现在dict.Count无法提供我所期望的价值。
感谢 @GlennWatson 指出ReactiveUI.WPF除了ReactiveUI包之外,我还需要添加对 Nuget Package 的引用。
我有一个ReactiveObject视图模型,我想在其中使用 anOpenFileDialog来设置我的一个视图模型属性 ( PdfFilePath) 的值。我尝试过的一切都会导致The calling thread cannot access this object because a different thread owns it错误。
我意识到下面的代码不符合 MVVM,因为我在视图模型中使用了“显式引用/实例化视图的类型”的代码,但我只是在寻找一个可以工作的最小示例,以便我可以向后工作,将视图和视图模型代码分开,并最终将服务传递给我的视图模型,该服务处理整个“选择文件路径”部分。
public class ImportPdfViewModel : ReactiveObject
{
public ImportPdfViewModel()
{
SelectFilePathCommand = ReactiveCommand.Create(() =>
{
OpenFileDialog ofd = new OpenFileDialog() { };
//
if (ofd.ShowDialog() == DialogResult.OK)
PdfFilePath = ofd.FileName;
});
}
private string _PdfFilePath;
public string PdfFilePath
{
get => _PdfFilePath;
set => this.RaiseAndSetIfChanged(ref …Run Code Online (Sandbox Code Playgroud) c# ×5
excel ×2
reactiveui ×2
wpf ×2
.net ×1
combobox ×1
datepicker ×1
dictionary ×1
excel-vba ×1
mvvm ×1
outlook ×1
vba ×1
xaml ×1