Category: code
ChildWindow Positioning
Silverlight ChildWindow is centered over the parent control. I have extended ChildWindow to open it at a specific position.
Here is a live demo : childwindow-positioning-demo
And here is the code :
public partial class ChildWindowEx : ChildWindow { Point _pt = new Point(0,0); public ChildWindowEx() { InitializeComponent(); } public ChildWindowEx(Point pt) : this() { _pt = pt; } protected override Size ArrangeOverride(Size finalSize) { Grid grid = Utils.FindChild(this, "ContentRoot"); if (grid != null) { grid.Arrange(new Rect(_pt.X, _pt.Y, grid.DesiredSize.Width, grid.DesiredSize.Height)); return finalSize; } return base.ArrangeOverride(finalSize); } }
Visual Studio 2010 Solution : download
Using Model-View-ViewModel in WPF Applications
Agenda :
Resources :
ReSharper vs CodeRush + Refactor Pro
I have been playing with JetBrains ReSharper (version 4.1) and DevExpress CodeRush + Refactor! Pro (version 3.2.2) lately. I wanted to decide on which one to go with. Here are some notes –
R# = ReSharper
CodeRush = CodeRush + Refactor! Pro
- R# seems to be better for refactoring, because it does not assume that I follow a rigid work flow when writing code. For example, I don’t always decide on the class hierarchies upfront. I do discover them as I write code. So, when I discover that I need to extract a base class from the class I am working on, I can do so with R#. I couldn’t find a way to do extract a base/super class with CodeRush.
- In R#, I can create an overloaded constructor using “Change Signature” refactoring (Ctrl+R, S). I couldn’t find a way to do this in CodeRush. CodeRush does allow me to create overloaded methods.
However, comparisons that only focus on how many refactorings each tool can do are not very important to me. After all, it should be easy for the individual missing refactorings to be implemented in the subsequent releases of these tools. I want to know which one is a better investment in the long run. The investment is not just a couple of hundred dollars, it is going to be an investment of time too.
- R# “finds” Types as you try to use them and adds references and “using” directives from other projects in your solution. You will not believe how useful this is! You don’t have to interrupt your train of thought to go add references and “using” directives. CodeRush doesn’t do that.
- I found R# “Create From Usage” feature incredibly useful with TDD. This feature will be available in Visual Studio 2010. They are calling it “Consume-First Development”.
- R# has keyboard shortcuts for individual refactorings. All refactorings are accessible from ALT+ENTER or ALT+R. Again, R# helps you keep focused on the code you are writing. In CodeRush, individual refactorings don’t have keyboard shortcuts.
- R# allows me to specify exactly what to include when doing ExtractXXX refactorings. CodeRush doesn’t.
- R# seems to know what I want to do. For example, when I discover that an existing class would be a good starting point to write the class I am thinking about and copy-paste the class and attempt to rename it, CodeRush renames both classes. R# renames the one you intend to rename.
- R# introduces much less friction when running unit tests. It is possible to add unit-testing add-ins to Visual Studio and access similar functionality, but the way unit-testing is integrated into R#, it is much more conducive to TDD.
- Collapse a class region. Now try to do a refactoring on this class, like “Rename file to match type” etc. In CodeRush, you will not be able to do it because the three-dot glyph will not be displayed when the class is collapsed.
- CodeRush keeps getting in my way by automatically writing over as I type. It expands its “smart templates” when you press space. Guess what! That is how I separate words in my sentences – by pressing space. It gets quite annoying. I wish I could turn it off.
As you have probably guessed by now, I think ReSharper is a better fit for me.
Here is a list of some other comparisons, covering aspects and features of these products I haven’t mentioned here that might be important to you. Some of these concluded in favor of CodeRush. Keep in mind that some of the following articles are a couple of years old.
- Derik Whittaker is keeping CodeRush but uninstalled Refactor Pro.
- David Hayden is keeping an open mind.
- Scott Hanselman likes CodeRush better.
- Ryan Garagay went with R#.
- StackOverflow.com has some useful comments and more links.
- There is some discussion on JoelOnSoftware.com.
- Ian decided to stick with ReSharper.
Using NHibernate With SQLite in DbUpdater
DbUpdater (version 1.3 onwards) can be used with sqlite3.
Review the files included in DbUpdater-sqlite3.zip
1. DbUpdater.exe.config must be modified. Note changes to the following keys – exe-file, exe-args, dialect, driver_class, connetion_string.
2. SchemaVersion.hbm.xml must be modified. The ‘class’ attributes value for the ‘generator’ of ‘id’ must be changed to ‘identity’. No other changes are needed here.
3. \SqlScripts\schema-version-table.sql is modified. Note that the datatypes of all columns are changed to TEXT, except for SchemaChangeId, which is changed to integer primary key. integer primary key is used for auto-incremented columns in sqlite.
4. \SqlScripts\baseline.sql is modified. Note the use of current_timestamp function. The actual sql syntax in this file must conform to sqlite dialect.
5. All other .sql scripts in \SqlScripts directory are also modified to conform to sqlite dialect.
The following files are expected to be in DbUpdater.exe directory (as configured in the DbUpdater.exe.config file) –
1. sqlite3.exe : download.
2. System.Data.SQLite.dll : download.
3. createdb.bat file : This file is included. This batch script will call sqlite3.exe to execute sql queries.
Another very useful tool for working with sqlite database files is SQLite Database Browzer.
Dial Gauge is a ProgressBar
I am not just being philosophical here. In WPF, ControlTemplates allow you to transform a control’s appearance. This is not the same as applying stylesheets. This is an entirely new level of customization. What you see in the screenshot below looks like a Dial but is actually a simple ProgressBar control wearing a “Dial” template. The Dial template was created using Microsoft Expression Blend .
Include the ControlTemplate as a Window.Resource and then assign it to ProgressBar element’s Template attribute :
Of course that is not all. The ControlTemplate must define some named elements of FrameworkElement type. Charles Petzold has explained it in detail : MSDN Magazine Article. So, I will not repeat it here.
The sample code can be downloaded here : DialTest.zip
License : Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License.