随笔分类 - WPF MVVM(Prism、Cinch)
WPF Silverlight相关
摘要:"Consistency in a user interface is an important trait; there are many facets of consistency, one of which is the consistent look and feel of controls. For example, all buttons should look roughly the same – similar colors, the same margins, and so on."UI的风格一致性是应用程序应当关注的重要特性。“Styles provid
阅读全文
摘要:在.NET中,我们使用try-catch-finally来处理异常。但,当一个Exception抛出,抛出Exception的代码又没有被try包围时,程序就崩溃了。这些异常往往是你没有注意到的。在WPF中,提供了一种处理这些个异常的方式。举例来说明。1.先抛出个异常,不用try包围它。在MainW...
阅读全文
摘要:有时我们不希望我们的WPF应用程序可以同时运行有多个实例,当我们试图运行第二个实例的时候,已经运行的实例也应该弹出来。我们可以用Mutex来实现打开App.xaml.cs,在App类中添加如下内容 public partial class App : Application { [DllImport("user32", CharSet = CharSet.Unicode)] static extern IntPtr FindWindow(string cls, string win); [DllImport("user32")] ...
阅读全文
摘要:“Logical resources may be of various types, such as brushes, geometries, styles, and templates.Placing all those resources in a single file such as App.xaml hinders maintainability. A betterapproach would be to separate resources of different types (or based on some other criteria) totheir own files
阅读全文
摘要:“Sometimes binary resources are defined in one assembly (typically a class library), but areneeded in another assembly (another class library or an executable). WPF provides a uniformand consistent way of accessing these resources using the pack URI scheme.”假如我们定义一个WPF User Control Library,并在其中添加一张图
阅读全文
摘要:WPF中的Binary Resource(二进制资源)是相对于前面所说的Logical resource(逻辑资源)而说的,一般指Image、XML文件等。注意:这里说的是Resource"资源",和Content"内容"是不同的。1.Content VS Resource一般我们向工程中添加一个二进制的资源,如图片。我们设置它的属性,设置成资源和内容是不同的!简单的说下两者的区别:“When the Build Action is set to Content (as in the jellyfish example), the resource is
阅读全文
摘要:这篇博文分享下保龄球计分算法。计分规则描述如下:A game of tenpins bowling lasts ten frames, in each of which the bowler makes one or two attempts to knock down ten pins arran...
阅读全文
摘要:“Sometimes it's useful to use one of the selected colors or fonts the user has chosen in theWindows Control Panel Personalization applet (or the older Display Settings in Windows XP),such as Window caption, Desktop color, and Selection color. Furthermore, an applicationmay want to react dynamica
阅读全文
摘要:“What happens if we replace aspecific resource? Would that be reflected in all objects using the resource? And if not, can webind to the resource dynamically?”接上篇博文,如果我们需要在C#代码中动态替换某个logical resource,我们该如何做呢?如,Window的Resources属性赋值如下: ...
阅读全文
摘要:"Traditional application resources consist of binary chunks of data, typically representing things such as icons, bitmaps, strings, and XML. In fact, the .NET framework providesgeneric support for these through the ResourceManager class.WPF is no different—binary resources play an important rol
阅读全文
摘要:"Markup extensions are used to extend the capabilities of XAML, by providing declarativeoperations that need more than just setting some properties. These can be used to do prettymuch anything, so caution is advised – these extensions must preserve the declarative natureof XAML, so that non-dec
阅读全文
摘要:"XAML provides an easy way to set values of properties—type converters and the extended property syntax allow for flexible setting of values. However, some things cannot be expressed as a simple value, such as setting a property to the value of some static property."这个相对比较简单,知道就行,Code Snip
阅读全文
摘要:附加属性附加属性,大家都不陌生,最常见的是Canvas.Left/Canvas.Top,类似的也有Grid.Row/Grid.Column等附加属性。举个最常见的例子 需要说明的是并不是所有的附加属性都是元素放进去后才会有附加效果,上面的例子只是刚好是这种错觉的巧合情况,Grid.Row也属于这...
阅读全文
摘要:依赖属性".NET properties are nothing more than syntactic sugar over set and get methods."我们知道.NET的属性只不过是get/set方法的语法糖衣。"Dependency properties are the workhorse of WPF. This infrastructure provides for many of WPF's features, such as data binding, animations, and visual inheritance. In
阅读全文
摘要:1.XAML接触WPF的第一眼就是XAML---XAML是用来描绘界面的。其实不然!"Actually, XAML has nothing to do with UI. It's merely a declarative way of constructing objects and setting their properties.”XAML和UI一点关系也没有,它仅仅是一种以声明方式来构建对象,设置对象属性的一种方式而已,和code behind file作用差不多。XAML这种声明方式构建对象的好处是,程序员只管声明自己要什么,至于如何构建则不需要考虑。XAML对WPF
阅读全文
摘要:WPF实现不规则窗体,方法很多很多多....本文总结DebugLZQ认为简洁高效的几种方法实现WPF不规则窗体的几种常用的方法如下: 1.使用Blend等工具绘制一想要的窗体。这个可以参考xiaowei0705的这篇博文:WPF制作不规则的窗体。 2.给window的Clip属性赋Path值。这个可以参考DebugLZQ前面的博文:WPF Effect Clip以及Transform。 3.使用透明背景的PNG图像。 4.为Window主容器添加Border 5.使用Blender制作想要的Path的说明。 6.其他本文将要讲述的第一种方法,可以说一点技术含量都没有,基本不用动手编...
阅读全文
摘要:前面的博文:WPF拖动总结中DebugLZQ遇到的问题是:DebugLZQ给容器中所有UI控件注册一个MouseLeftButton事件,Button控件无法捕获这儿事件的问题,加个断点看下,程序根本不到达这个地方。当时只是简短的提了一下,觉得不够,因此决定再发一篇博文来说一下。foreach (UIElement uiEle in LayoutRoot.Children){ uiEle.MouseMove += new MouseEventHandler(Element_MouseMove); uiEle.MouseLeftButtonDown += new MouseButtonE...
阅读全文
摘要:这篇博文总结下WPF中的拖动,文章内容主要包括:1.拖动窗口2.拖动控件 Using Visual Studio 2.1thumb控件 2.2Drag、Drop(不连续,没有中间动画) 2.3拖动一个控件 2.4让一个窗口内的所有(指定的)控件可拖动3.Expression Blend X实现拖动(Best Practice)Update: Move and resize controls on a form at runtime (with drag and drop)小结1.拖动窗口 我们知道,鼠标放在窗口的标题栏上按下就可以拖动窗体。我们要实现在窗口的全部地方或特定地方按下鼠标左...
阅读全文
摘要:今天DebugLZQ在做WPF拖动总结的时候,遇到了这个问题。baidu了下,貌似没有解决这个问题的权威答案,遂写下这篇博文。我想做的事情是:拖动一个窗体内的控件(Rectangle)到另一个容器控件内,而保留原来的控件。为了更好地把问题说清楚,请看如下代码片段:void canvas1_Drop(object sender, DragEventArgs e){ IDataObject data = new DataObject(); data = e.Data; if (data.GetDataPresent(typeof(Rectangle))) { Rectan...
阅读全文
摘要:最近在Academy做了一个练习TaskVision,用WPF+SQL Server 2008完成。主要的功能是,实现一个任务分配管理。具体如下: 系统登录,登录完成后,在MainWindow中用DataGrid显示任务的信息,可根据指定条件进行过滤;单击列表,页面下显示详细信息;双击则可对该...
阅读全文