發表文章

目前顯示的是 5月, 2013的文章

WPF - 性能優化

  WPF性能優化一 - Rendering Tier  根据硬件配置的不同,WPF采用不同的Rendering Tier做渲染。下列情況請特別注意,因為在這些情況下,即使是處于Rendering Tier 2的情況下也不會硬件加速。(不全,其余請查閱SDK)  WPF性能優化二 - 布局和設計  盡量多使用Canvas等簡單的布局元素,少使用Grid或者StackPanel等復雜的,越復雜性能開銷越大。  建立邏輯樹或者視覺樹的時候,遵循Top-Down的原則。  WPF性能優化三 - 圖像  對Image做動畫處理的時候(如調整大小等),可以使用這條語句RenderOptions.SetBitmapScalingMode(MyImage,BitmapScalingMode.LowQuality),以改善性能。 用TileBrush的時候,可以CachingHint。  WPF性能優化四 - 對象行為  訪問CLR對象和CLR屬性的效率會比訪問DependencyObject/DependencyProperty高。注意這里指的是訪問,不要和前面的綁定混淆了。但是,把屬性注冊為DependencyProperty會有很多的優點:比如繼承、數据綁定和Style。 WPF性能優化五 - 應用程序資源  在自定義控件,盡量不要在控件的ResourceDictionary定義資源,而應該放在Window或者Application級。因為放在控件中會使每個實例都保留一份資源的拷貝。 盡量使用Static Resources,但不能盲目使用。  WPF性能優化六 - 文本  文字少的時候用TextBlock或者label,長的時候用FlowDocument.  使用元素TextFlow和TextBlock時,如果不需要TextFlow的某些特性,就應該考慮使用TextBlock,因為它的效率更高。  在TextFlow中使用UIElement(比如TextBlock)所需的代价要比使用TextElement(比如Run)的代价高.在FlowDocument中盡量避免使用TextBlock,要用Run替代。 在TextBlock中顯式的使用Run命令比不使用Run命名的代碼要高。 把Label(標簽)元素的

C# - NHibernate Queries Examples (轉貼)

圖片
Today was the first day of my NHibernate course, and I think that it might be good to point out a few of the samples that we worked with. Those are pretty basic NHibernate queries, but they are probably going to be useful for beginners. Let us take my usual Blog model, and see what kind of queries (and results) we can come up with: Let us find a blog by its identifier: var blog = s.Get<Blog>(1); Which results in: We can also try: var blog = s.Load<Blog>(1); Which would result in… absolutely no SQL queries. You can look at a more deep discussion of that here . Now, let us try to search by a property: var blogs = s.CreateCriteria<Blog>() .Add(Restrictions.Eq("Title", "Ayende @ Rahien")) .List<Blog>(); Which results in: If we try to make the same with HQL, it would look: var blogs = s.CreateQuery("from Blog b where b.Title = :title") .SetParameter("title","Ayende @ Rahien") .List<Blog>(); Whic