如何在代码中获取ListBox ItemsPanel

我有一个带有ItemsPanel的ListBox 我想使用后面的代码中的TranslateTransform沿X轴移动堆栈面板。 问题是,我找不到Stack Panel。 ThumbListBox.FindName(“ThumbListStack”) 什么都不返回 我想用它: Storyboard.SetTarget(x, ThumbListBox.FindName(“ThumbListStack”)) 如何获取堆栈面板,以便我可以将其与TranslateTransform一起使用 谢谢

命令窗口和立即窗口之间的实际区别是什么?

只是好奇。

结束BeginInvoke的正确方法是什么?

我最近在MSDN上阅读了这个post 。 所以我想使用lambda表达式作为一种调用EndInvoke的方式,只是为了确保一切都很好和整洁。 哪个更正确? 例1: Action method = DoSomething; method.BeginInvoke(5, (a)=>{method.EndInvoke(a);}, null); 例2: Action method = DoSomething; method.BeginInvoke(5, (a)=> { Action m = a.AsyncState as Action; m.EndInvoke(a); }, method);

从数据库中读取SQL Varbinary Blob

我正在努力将文件保存到sql blob到varbinary(max)列,并且现在有了保存方面的工作(我相信)。 我无法弄清楚如何读取数据,因为我正在使用存储过程检索我的数据库值我应该能够访问列数据,如ds.Tables [0] .Rows [0] [ “blobData”]; 所以我有必要像我在下面的例子中看到的那样有一个SQLCommand等: private void OpenFile(string selectedValue) { String connStr = “…connStr”; fileName = ddlFiles.GetItemText(ddlFiles.SelectedItem); using (SqlConnection conn = new SqlConnection(connStr)) { conn.Open(); using (SqlCommand cmd = conn.CreateCommand()) { cmd.CommandText = “SELECT BLOBData FROM BLOBTest WHERE testid = ” + selectedValue; using (SqlDataReader dr = cmd.ExecuteReader()) { while (dr.Read()) […]

在与前一个相同的线程中继续执行任务

我有一个WebService,可以创建任务和继续任务。 在第一个任务中我们设置Thread.CurrentPrincipal 因此,当ContinuationTask启动时,它不再具有Thread.CurrentPrincipal。 我想在ContinuationTask中指定它应该在与其前提相同的线程中运行 。 我搜索过网络,但我只发现线程要在SynchronizationContext中运行,因此我开始认为我缺少一些基本规则,特别是关于Thread.Principal应该如何工作。

如何在C#.NET中创建控件数组?

我有一个包含几个标准控件(文本框,按钮等)的表单。 我想在集合中对某些控件进行分组,以便我可以在任何给定时间启用和禁用它们,而无需显式设置每个控件。 这样做的语法是什么? 这是一些伪代码,以显示我想做什么…. Control[] ControlCollection = new Control[]; ControlCollection.add(Button1); ControlCollection.add(TextBox1); … … foreach( Control x in ControlCollection) { x.Enabled = false; } 我知道我可以将控件放在一个组框中并完成此操作,但控件不会以方便的方式放在表单上。

我如何从Linq的TakeWhile中再拿一件物品?

(感兴趣的代码行是最后一行,其余的只是完整的代表) 使用下面的代码,我想采取VOTERS,直到我超过所需的最大票数,但它在达到最大投票数之前就停止了,所以我的投票人数比我想要的少了1个。 在LINQ中是否有一个干净的方式,我可以在它达到最大票数之前获得投票? 我知道我可以添加一个选民或者在循环中执行此操作但我很好奇是否有一个很好的方法来使用LINQ。 var voters = new List { new Person(“Alice”, Vote.Yes ), new Person(“Bob”, Vote.Yes), new Person(“Catherine”, Vote.No), new Person(“Denzel”, Vote.Yes), new Person(“Einrich”, Vote.Abstain), new Person(“Frederica”, Vote.Abstain), new Person(“Goeffried”, Vote.Abstain), }; voters.Single(c => c.Name == “Alice”).Voices = 100; voters.Single(c => c.Name == “Bob”).Voices = 150; voters.Single(c => c.Name == “Catherine”).Voices = 99; voters.Single(c […]

如何创建白色的1024×1024 RGB位图图像?

提出这个问题令人尴尬,却无法找到答案。 我徒劳地试了这个。 Image resultImage = new Bitmap(image1.Width, image1.Height, PixelFormat.Format24bppRgb); using (Graphics grp = Graphics.FromImage(resultImage)) { grp.FillRectangle( Brushes.White, 0, 0, image1.Width, image1.Height); resultImage = new Bitmap(image1.Width, image1.Height, grp); } 我基本上想用C#中的白色填充1024×1024 RGB位图图像。 我怎样才能做到这一点?

从属性getter或setter方法创建委托

要从方法创建委托,您可以使用compile type-safe语法: private int Method() { … } // and create the delegate to Method… Func d = Method; 属性是getter和setter方法的包装器,我想创建一个属性getter方法的委托。 就像是 public int Prop { get; set; } Func d = Prop; // or… Func d = Prop_get; 不幸的是,这不起作用。 我必须创建一个单独的lambda方法,当getter方法匹配委托签名时,这似乎是不必要的: Func d = () => Prop; 为了直接使用委托方法,我必须使用讨厌的reflection,这不是编译类型安全的: // something like this, not tested… MethodInfo m […]

如何使用DI在Class Constructor中获取Microsoft.AspNet.Http.HttpContext实例

我正在MVC 6中构建一个一次性应用程序,并尝试使用不同的依赖架构。 我面临的问题是如何创建特定于应用程序的自定义“ MyAppContext ”对象。 这将需要来自HttpContext一些信息和来自数据库的一些信息,并且将是针对应用程序特定属性的请求范围的存储库。 我想将HttpContext的实例传递给’ MyAppContext ‘的构造函数。 我已经使用DI成功创建了一个带有IDataService接口的’ DataService ‘对象,这IDataService用。 与’MyAppContext’类的不同之处在于它在构造函数中有两个参数–‘ DataService ‘和Microsoft.AspNet.Http.HttpContext 。 这是MyAppContext类: public class MyAppContext : IMyAppContext { public MyAppContext(IDataService dataService, HttpContext httpContext) { //do stuff here with the httpContext } } 在启动代码中,我注册了DataService实例和MyAppContext实例: public void ConfigureServices(IServiceCollection services) { services.AddMvc(); //adds a singleton instance of the DataService using DI services.AddSingleton(); services.AddScoped(); […]