为什么Browsable属性使属性不可绑定?

我正在尝试使用System.Windows.Forms.PropertyGrid 。 要使属性在此网格中不可见,应将BrowsableAttribute设置为false 。 但添加此属性会使该属性无法绑定。 示例:创建一个新的Windows窗体项目,并将TextBox和PropertyGrid拖放到Form1 。 使用下面的代码, TextBox的宽度不会绑定到Data.Width : public partial class Form1 : Form { public Form1() { InitializeComponent(); Data data = new Data(); data.Text = “qwe”; data.Width = 500; BindingSource bindingSource = new BindingSource(); bindingSource.Add(data); textBox1.DataBindings.Add(“Text”, bindingSource, “Text”, true, DataSourceUpdateMode.OnPropertyChanged); textBox1.DataBindings.Add(“Width”, bindingSource, “Width”, true, DataSourceUpdateMode.OnPropertyChanged); propertyGrid1.SelectedObject = data; } } 数据类的代码是: public […]

将任务类型保存为String,导致灾难性故障

我正在尝试将我在Canvas上编写的Ink保存在类中,并使用此链接中的这两种方法重新加载它。 private async Task WriteInk() { using (var stream = new InMemoryRandomAccessStream()) { await inkManager.SaveAsync(stream); await stream.FlushAsync(); stream.Seek(0); byte[] bytes = new byte[stream.Size]; IBuffer buffer = bytes.AsBuffer(); await stream.ReadAsync(buffer, (uint)stream.Size, InputStreamOptions.None); return Convert.ToBase64String(bytes); } } private async void ReadInk(string base64) { if (string.IsNullOrEmpty(base64)) return; var bytes = Convert.FromBase64String(base64); using (var stream = new InMemoryRandomAccessStream()) { […]

使用Moq模拟HttpContext.Current.Server.MapPath?

我单位测试我的家庭控制器。 此测试工作正常,直到我添加了一个保存图像的新function。 引起问题的方法如下。 public static void SaveStarCarCAPImage(int capID) { byte[] capBinary = Motorpoint2011Data.RetrieveCapImageData(capID); if (capBinary != null) { MemoryStream ioStream = new MemoryStream(); ioStream = new MemoryStream(capBinary); // save the memory stream as an image // Read in the data but do not close, before using the stream. using (Stream originalBinaryDataStream = ioStream) { var […]

C#:如何将winforms按钮的文本绑定到资源

我们有一个资源文件,其中包含许多已翻译的字符串,在我们的应用程序中使 是否有更好的方法将按钮的文本绑定到某个字符串? 目前我们通常只是在构造函数,Load事件处理程序或其中一个调用的方法中执行类似的操作: someButton.Text = CommonTexts.SomeString; someMenuItem.Text = CommonTexts.SomeOtherString; 有没有更好的方法呢? 也许在设计师? 或者这是推荐的做法吗? 只是为了让您知道我们如何进行实际翻译:我们有一个只包含resx文件的类库项目。 主要的resx文件是用英语写的(当然)。 然后,我们在名为ResEx的应用程序中打开这些基本resx文件,我们(或其他人)将其翻译成其他语言。 编译时,Visual Studio会自动为每种语言创建程序集,这些程序集将根据当前文化集自动使用。 这非常有效,所以我真的不需要关于如何进行翻译的信息(虽然我总是对改进当然感到好奇)。 我要问的是,是否有更好的方法可以从资源程序集中获取所有翻译的字符串,并将其转换为所有各种Text属性。

获取MVC Bundle Querystring

是否可以在ASP.NET MVC中检测bundle查询字符串? 例如,如果我有以下捆绑请求: /css/bundles/mybundle.css?v=4Z9jKRKGzlz-D5dJi5VZtpy4QJep62o6A-xNjSBmKwU1 是否可以提取v查询字符串?: 4Z9jKRKGzlz-D5dJi5VZtpy4QJep62o6A-xNjSBmKwU1 我试过在捆绑转换中做这个,但没有运气。 我发现即使将UseServerCache设置为false ,转换代码也不会始终运行。

无法从UWP引用.NET Core库

我有一个带有以下project.json的.NET Core库 : { “version”: “1.0.0-*”, “dependencies”: { “NETStandard.Library”: “1.6.0” }, “frameworks”: { “netstandard1.6”: { } }, “scripts”: { “postcompile”: [ “dotnet pack –no-build –configuration Release”, “xcopy bin\\Release ..\\..\\lib\\ /Y” ] } } 其中后编译脚本创建了一个nuget包 ,我按照这些说明在VS中添加了自定义Feed。 这是因为我想从Windows通用应用程序中引用它 ,根据这个问题 ,它不能(否)。 但是当我尝试它时,我得到这样的信息: Package AEther 1.0.0 is not compatible with uap10.0 (UAP,Version=v10.0). Package AEther 1.0.0 supports: netstandard1.6 (.NETStandard,Version=v1.6) One […]

WPF FlowDocument – 绝对字符位置

我有一个WPF RichTextBox,我正在键入一些文本,然后解析整个文本进行处理。 在这个解析过程中,我有每个单词开头和结尾的绝对字符位置。 我想使用这些字符位置将格式应用于某些单词。 但是,我发现FlowDocument使用TextPointer实例来标记文档中的位置。 我发现我可以通过使用开始和结束指针构造TextRange来创建它。 一旦我有TextRange,我可以轻松地将格式应用于其中的文本。 我一直在使用GetPositionAtOffset为我的角色偏移量获取TextPointer,但怀疑它的偏移量与我的不同,因为所选文本的位置与我的预期略有不同。 我的问题是,如何准确地将绝对字符位置转换为TextPointer?

究竟谁最后决定什么是通用类型?

我有这个function public static T2 MyFunc( T1 a, T1 b, T2 c) { return c; } 我正在创建2个Persons类实例: class Person { } Person p = new Person(); Person p2 = new Person(); 我正在调用函数: MyClass.MyFunc(p, p2, 5); 我的问题是: 谁真正决定T1类型? (p?p2?) 因为如果左边是Apple,那么他会检查第二个是Apple也是苹果 如果第二个是橙色 – 他应该检查第一个是橙色。 在编译时问它是否会失败,如果不一样的话,这似乎很奇怪。 仍然 – 谁决定类型? 第二 – 如果我将其更改为动态 – 在运行时 – 谁将决定T1类型应该是什么?

如何抑制列表属性的XML标记

序列化时是否可以避免列表属性标记? //[Serializable()] – removed, unnecessary public class Foo { protected List fooBars = new List(); public virtual List FooBars { get { return fooBars; } set { fooBars = value; } } } // [Serializable()] – removed, unnecessary public class FooBar { public int MyProperty { get; set; } } 序列化Foo给出(评论除外): 7 9 通缉输出: 7 […]

C#使用Dynamic关键字通过字符串访问属性而不进行reflection

我想写类似以下内容: // I will pass in a number of “properties” specified as strings that I want modified string[] properties = new [] { “AllowEdit”, “AllowDelete” }; // Casting the component I’m using to a dynamic object of some sort ? dynamic d = myGridComponent; // Iterate over the strings and set the properties foreach(var s […]