Wednesday, April 16, 2008

Cider vs VS2008's builder. Just for fun

I wrote little test sample with using WPF. I added a custom class (inherit from Button) in sample's namespace. I needed to add control in application.

Taking into account my previous work experience with the implement controls, I wrote like next xmlns:local="clr-namespace:WpfApplication1;assembly=WpfApplication1" ,

I confused.

Project didn't build. It saw that couldn't find my custom class in adjusted XML namespace. In this case to my great surprise Cider parsed all correct and show Button in my case (my custom class was inherit from Button) even add correct a method for event handler.

I miss when added full type describe of namespace. In this case I had to write next: xmlns:local="clr-namespace:WpfApplication1"

Note:

If namespace of application set to use XmlnsDefinition (for example: [assembly: XmlnsDefinition( "http://www.mySite.com", "WpfApplication1" )] in AssemblyInfo.cs) and accordingly we must to write xmlns:local="http://www.mySite.com" in app. This sample isn't built and Cider doesn't parse it. We should use like code in an external dll only.

Sunday, April 13, 2008

ItemsSource tips & tricks

Describe problem.

When we wish to implement the mechanism Drag&Drop of Children for our control in WPF, particularly that our control contains children in its logical tree (in other case attached and inherit properties work incorrect sometimes). Let that control template contains some other controls inherit from ItemControl. We wish add some children to this inherit from ItemControl controls. What can we do?

If we use Items that we have a disagreeable surprise - we should add items to logical tree of internal control (previous to remove from our control's logical tree - it is the problem described above). But we can create collection inherit of IEnumerable and it is bound to ItemsSource of internal controls - all will be worked nice.

Note:

If property ItemsSource isn't equal 'null' that we can work with Items in read-only mode. If ItemsSource equal 'null' that we can full use Items (It is empty after those actions). If we need dynamic change of items we can implement INotifyPropertyChanged interface. The better solution is to use ObservableCollection for this purpose.

Tuesday, April 8, 2008

Deployment SVN (Subversion) for Windows as Home Version Control System.

I need to use Version Control System in home. It is have requirement: should be free and for Windows XP. I selected the SVN (http://subversion.tigris.org/) version at 1.4.8.12137 (It’s latest in this moment).

After installation in InstalataionFolder (default: “C:\Program Files\Subversion” you can select another) you should added repository folder and start server of SVN.

You can register repository folder to use svnadmin. First off all you should create repository folder – RepositoryFolder (I used “D:\Programming\svn”)

You do start command window (cmd.exe) in InstalataionFolder\bin and do type next command: svnadmin create "RepositoryFolder" (for example in my case: svnadmin create "D:\Programming\svn").

Note: Pay attention, we use some slash of Windows (“\”).

Now you should create service for automatic start the svn server. We use “sc.exe” for this target. “sc.exe” is located in system folder (It’s “C:\Windows\Sytstem32” in my PC). Create service: sc create svn binpath= "InstalataionFolder\bin\svnserve --service -r
"RepositoryFolder
" displayname= "SVN Server" depend= Tcpip start= auto

(In my case “sc create svn binpath= "C:\Program Files\Subversion\bin\svnserve --service -r "D:\Programming\svn" displayname= "SVN Server" depend= Tcpip start= auto”).

Note: Pay attention, we use two symbols of minuses before “service” and set space after each equals sign.

After we should uncomment “password-db = passwd” section in configure file – RepositoryFolder\conf\svnserve.conf (D:\Programming\conf\svnserve.conf in my case) and configure access to svn. We uncomment “auth-access” and uncomment and change value to “none” for “anon-access” (I deny anonymous access to svn).

You should create pair login-password in section [users] of file “RepositoryFolder\conf\passwd” (D:\Programming\conf\passwd in my case)

Now, you can start “SVN Server” service (Press Win+R and type in Run window the “services.msc” and start “SVN Server” or other with name that you have set).

And the end of article, I use a TortoiseSVN (http://tortoisesvn.tigris.org/) as client.

Monday, September 3, 2007

Correct use DataTemplateSelector.

In the many inherited from FrameworkElement in WPF contain a useful dependency property *TemplateSelector type of DataTemplateSelector. It can set our inherit from DataTemplateSelector class and override the method SelectTemplate(). This allow dynamic generate template for a content. Content-data we can get a elementary binding. And now feature: we can use all binding (even that what refet to ElementName), except TemplateBinding, therefore RelativSourceMode doesn't equal TemplatedParent.

Wednesday, July 25, 2007

My Vista sidebar gadget :)

I create Vista sidebar gadget for UA gadget competitions. It was adds to follow page iTV Watcher.
I had wanted to use SilverLight 1.0 (version 2.0 wasn't accessible in this time) for this purpose but I can't overcome a problem with event if to use Silverlight in sidebar of Vista. So I must was to use a simple JavaScript (It was missed some WPF-like animations feature, but it work correct).
Enjoy!

"Cruel" colors substitution.

Sometime we need custom one or more brush of control in WPF. If template is not available and in base template used system brush, we can use this workaround (example for ListBox):
<ListBox>
<ListBox.Resources>
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Maroon" />
<SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="Maroon" />
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightTextBrushKey}" Color="White" />
<SolidColorBrush x:Key="{x:Static SystemColors.ControlTextBrushKey}" Color="White" />
</ListBox.Resources>
<ListBoxItem>blah-blah</ListBoxItem>
<ListBoxItem>blah-blah</ListBoxItem>
<ListBoxItem>blah-blah</ListBoxItem>
</ListBox>

Custom style for a class which is inherited from the class of Selector

We need set own custom style or template for item of control which was inheritance from abstract class 'Selector' (for example: ComboBox, ListBox, TabControl) in WPF.
We can use two way:
1) We can add in control's resource some style and template. But it isn't good way, because these styles and templates have access only in boundary of control.
2) We can use inheritance from Selector ItemContainerStyle dependency property and set in it new style value.