background preloader

Contrôles et binding

Facebook Twitter

Custom popup and windows in WPF the MVVM way. In WPF, using the regular window control to launch child windows makes MVVM and separating a View concern from the ViewModel very difficult. The problem: The window control works nicely as a shell for your application, however, launching child windows is problematic because the window control cannot be defined in xaml unless as the root element. So, if you wanted to launch child windows inside a parent window, you lose the ability to declare these in xaml. This loss means you will not be able to bind to properties in your ViewModel from the view for the purpose of opening/closing a window. Instead you end up doing this imperatively in code which means more code, more thought, more work. Following is what you end up doing in the most minimalistic cases.

MyWindow window = new MyWindow(); window.ShowDialog(); Adding code such as the above means you are forced to make your ViewModel create instances of your Window and launch them when needed. <ResourceDictionary The main window : That's it. Why must WPF so cruefully complicated.... Download source code - 35.7 KB Introduction This is actually a pretty simple article, and to be honest, I ummed and ahhed about even making this an article at all. I thought it might make a 1/2 decent blog post, but in the end, I thought that it would benefit more people as a published article, so I decided to publish this dead simple article as an article and not a blog post; sorry for its shortness. I know it's not my normal style article, but hope that is OK; I just felt it was useful is all. So what does the attached code actually do? Well, it is dead simple; it shows you how to modify the standard .NET 4.0 WPF DatePicker control to allow the user to use the keyboard up/down keys to skip days/months/years when the mouse is in the correct portions of the DatePicker text, which is something the standard control does not actually do.

So that is what we are trying to do. What Does It Look Like So what does it all look like then? Here is the Calendar when it is open: How Does It All Work. Foundations: Using Templates to Customize WPF Controls. Foundations Using Templates to Customize WPF Controls Charles Petzold Code download available at:Foundations2007_01.exe(158 KB) With the release of Windows Vista™ and the Microsoft® .NET Framework 3.0 come a host of new technologies for developers to learn about, discuss, and use. New tools, libraries, and paradigms will change how you build managed apps, offering powerful possibilities.

We're introducing this new monthly column to cover the underlying technologies you will use for developing your applications. Traditionally, customizing an existing control in Windows has been a four-step process. The pain of control customization has evidently been felt by the developers of the Windows Presentation Foundation, available as part of the .NET Framework 3.0. The Windows Presentation Foundation template is at the same time so simple and so powerful that it actually took me a while to wrap my head around the concept. Writing templates in code is rather awkward. Dumping the Defaults Figure 6. Making the slider slide with one click anywhere on the slider?

Rating Control for WPF 4.0. Thanks but one question [modified] Link is broken. Download source code - 8.52 KB Introduction Earlier today, I was working on a new form for my Silverlight application, and I realized that I needed to bind an enum to a group of RadioButtons. Being a highly skilled, advanced software engineer, I rolled up my sleeves, put on my thinking hat, and.... attempted to Google the solution. I knew what the basic solution should look like in that I was sure a creative converter solution would be involved, but I was looking to save some time and effort.

What I found online however, was very disappointing. I wasn't the first person to face this situation and ask about it, but the messages I read on the forums all seemed to follow a common theme... Background I just want to take a quick moment to overstate the obvious for those new to Silverlight. Using the code Every good demo requires a made-up company example (at least, according to Microsoft it does), so here we go. Now let's get to those CheckBoxes.

For the most part, we are done. Wrap up.