随笔分类 -  .Net

System.Net.FtpClient改进
摘要:项目用到Ftp,搜了下现有的类库System.Net.FtpClient 貌似比较不错。一开始用着还行,但是有个FtpServer下有8k多内容,列表需要很久(7、8s)才能刷新出来。翻源码吧,有两个地方可以改进FtpClient.cs 中public FtpListItem[] GetListin... 阅读全文

posted @ 2015-09-02 15:23 beastplus 阅读(330) 评论(0) 推荐(0)

using中StreamWriter XmlWriter 区别
摘要:使用StreamWriterusing (var writer = new StreamWriter(File.Create(path))){ writer.WriteLine("sdf");} 跳出using后stream也释放了using (XmlWriter xw = XmlWriter... 阅读全文

posted @ 2015-04-28 11:11 beastplus 阅读(209) 评论(0) 推荐(0)

使用Linq动态排序
摘要:Linq排序很方便,如果能动态创建Expression再排序就更方便了。正序还是倒序排列var order = typeof(Enumerable).GetMember(direction == ListSortDirection.Ascending ? "OrderBy" : "OrderByDe... 阅读全文

posted @ 2015-03-12 10:35 beastplus 阅读(441) 评论(0) 推荐(0)

WebForm、MVC图片加载失败处理
摘要:还是那个该死的WebFrom项目,部分功能替换为MVC后感觉好多了,但是WebForm、MVC都有图片加载失败时显示提示图片的需求,并且统一在js中处理。问题来了,js中图片路径怎么处理呢?现场有可能部署为网站,也有可能为应用,再加上对路径的不了解,决定弄个IHttpHandler一劳永逸解决路径问... 阅读全文

posted @ 2014-11-11 11:25 beastplus 阅读(518) 评论(0) 推荐(0)

ASP.NET WebForm 与 IE10、IE11
摘要:最近维护公司一个烂项目.NET4.0 Asp.Net WebForm(在MVC5泛滥的今天还有用WebForm的(⊙o⊙)…)IE10、IE11下aspx中大表单提交不上去,报_DoPostBack未定义,IE9就没问题,调整了User-Agent,弄成9就没问题了。股沟之,发现股沟还是比百度好使h... 阅读全文

posted @ 2014-06-04 14:06 beastplus 阅读(213) 评论(0) 推荐(0)

Silverlight与Asp.Net MVC 通讯
摘要:最近一周分配了个任务,编辑配置,需要做成web的。要求有拖拽、旋转、选择多边形范围⊙﹏⊙。考虑到自己的烂jq,申请用SilverLight,居然可以用这个没娘的孩儿。Silverlight需要与MVC主项目通讯,无外乎是Get、Post,别的没用到。获取地址WebRequest创建时需要Uri,而且是绝对路径的,需要获取xap所在的地址。var scriptObject = HtmlPage.Window.GetProperty("location") as ScriptObject;var hostUrl = scriptObject.GetProperty(" 阅读全文

posted @ 2013-06-14 13:50 beastplus 阅读(911) 评论(0) 推荐(0)

.net 4.5中的async await
摘要:.net 4.5中新增C#关键字async await长时间操作任务的福音。private async void Button_Click_1(object sender, RoutedEventArgs e){ var str= await this.WaitAsynchronouslyAsync(); MessageBox.Show(str);} public Task<string> WaitAsynchronouslyAsync(){ TaskCompletionSource<string> tcs = new TaskComp... 阅读全文

posted @ 2013-05-24 13:24 beastplus 阅读(454) 评论(0) 推荐(0)

长沙项目关于设备操作遇到的问题及解决
摘要:最近被公司派到现场开发,需要通过第三方SDK操作某些设备,期间遇到一些问题1.某LED走字屏SDK为Com组件,而服务为WCF寄宿在IIS上,由于SDK只支持点阵,需要把字渲染为图片再操作设备。信手写了个用WPF保存图片方法,可WPF需要STA线程,所以还得把设备操作的方法在STA线程里执行,于是 private Thread staThread; //初始化 staThread = new Thread(new ThreadStart(ThreadStart)); staThread.SetApartmentState(ApartmentState.STA); //打开设备 st... 阅读全文

posted @ 2013-03-14 16:41 beastplus 阅读(710) 评论(0) 推荐(0)

VC引用错误
摘要:用2012修改同事编的vcclr的proj,本地好好的,其他同事运行报错,用2010打开项目惊叹号好多以为手动添加引用就好了,可是靠,指定位置好了,可是(万恶的可是)后来想了想我的机器装了2012vc的运行时,会不会和这个有关系,打开vcxproj<PlatformToolset>v110</PlatformToolset>改为v100搞定。 阅读全文

posted @ 2013-01-29 11:37 beastplus 阅读(122) 评论(0) 推荐(0)

ListBoxItem ContextMenu
摘要:今天想把listboxitem加上右键菜单,如下<Style TargetType="{x:Type ListBoxItem}" BasedOn="{StaticResource ListBoxItemLDPStyle}"> <Setter Property="ContextMenu"> <Setter.Value> <ContextMenu> <MenuItem Header="Header" Click="MenuItem_Cli... 阅读全文

posted @ 2013-01-28 17:35 beastplus 阅读(1289) 评论(0) 推荐(0)

自定义附加属性的绑定
摘要:不要忘记()要不就是UnsetValue 悲剧啊 阅读全文

posted @ 2012-12-29 16:36 beastplus 阅读(220) 评论(0) 推荐(0)

WindowsFormsHost 使用注意事项
摘要:窗口的AllowsTransparency不能为true,否则WinForm控件无显示WindowsFormsHost的父元素的父元素。。。。不能有背景,否则无显示。背景只能如下使用<Window> <Grid> <Border Background=""/> <WindowsFormsHost/> </Grid></Window> 阅读全文

posted @ 2012-12-28 08:42 beastplus 阅读(553) 评论(0) 推荐(0)

WPF ScrollViewer ScrollBar高宽
摘要:<sys:Double x:Key="{x:Static SystemParameters.VerticalScrollBarWidthKey}">width</sys:Double> <sys:Double x:Key="{x:Static SystemParameters.HorizontalScrollBarHeightKey}">height</sys:Double>样式字典中加入如上 阅读全文

posted @ 2012-12-19 17:32 beastplus 阅读(745) 评论(0) 推荐(0)

WPF自定义窗口样式小技巧
摘要:1窗口大小的调整,这个应该不算啥技巧,就是头次使用长长记性窗口模板中有ResizeGrip,并在ResizeMode="CanResizeWithGrip"时显示2WindowStyle=None时自定义按钮关闭窗体方法一:在某个cs文件中创建类,把关闭写在cs中,这样代码是很丑方法二:最近项目中用了CaliburnMicro,使得关闭窗口简单起来在自定义的按钮上添加cm:Action.Target="{Binding RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=Window}}&qu 阅读全文

posted @ 2012-11-27 16:00 beastplus 阅读(304) 评论(0) 推荐(0)

编译时生成快捷方式
摘要:某些程序需要启动时添加参数,如何在编译后生成带参数的快捷方式1项目中添加如下bat,原理为生成临时vbs,执行后删除@echo offecho Dim WshShell,Shortcut >> tmp.vbs echo Dim shortCutPath,shortCutTarget,par,fso >> tmp.vbs echo shortCutPath = %1 >> tmp.vbsecho shortCutTarget = %2 >> tmp.vbsecho par = %3 >> tmp.vbsecho Set fso = Cr 阅读全文

posted @ 2012-11-27 08:38 beastplus 阅读(260) 评论(0) 推荐(0)

查找ListBox的ItemsPanel
摘要:ItemsPresenterpresenter = (ItemsPresenter)lb.Template.FindName("PART_Presenter", lb);Panelpanel = (Panel)VisualTreeHelper.GetChild(presenter, 0); 阅读全文

posted @ 2011-10-21 09:26 beastplus 阅读(267) 评论(0) 推荐(0)

如何让ListBoxItem显示序号
摘要:<ListBox ItemsSource="{Binding}" AlternationCount="{Binding Path=Count}"> <ListBox.ItemTemplate> <DataTemplate> <TextBlock Text="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ListBoxItem}, Path=(ItemsControl.AlternationIndex)}&q 阅读全文

posted @ 2011-10-20 13:40 beastplus 阅读(787) 评论(0) 推荐(0)

Xaml映射命名空间
摘要:[assembly: System.Windows.Markup.XmlnsDefinition("http://schemas.microsoft.com/winfx/2006/xaml/presentation", "MyControls")]这段语句的意思就是将MyControls命名空间映射到http://schemas.microsoft.com/winfx/2006/xaml/presentation命名空间中。 阅读全文

posted @ 2011-10-12 17:04 beastplus 阅读(214) 评论(0) 推荐(0)

ItemsControl的Item类型
摘要:protected override bool IsItemItsOwnContainerOverride(object item) { return item is ListBoxItem; } protected override DependencyObject GetContainerForItemOverride() { return newListBoxItem(); } 阅读全文

posted @ 2011-09-29 16:36 beastplus 阅读(234) 评论(0) 推荐(0)

导航