Skip to main content

Posts

Showing posts from May, 2009

NumToBoolConverter - A simple IValueConverter implementation

Some 'Beginner's' stuff. One good thing about WPF is the ability to specify custom converters, when you do the binding. Here is a simple IValueConverter implementation, to convert an int value (1 or 0) to corresponding bool values (true or false). Useful if you want to bind a check box or something to a property of numeric type. public class NumToBoolConverter : IValueConverter { #region IValueConverter Members public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { if (value!=null && value is int ) { var val = (int)value; return (val==0) ? false : true; } return null; } public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { if (value!=null && value is bool ) …

PDF to XAML Conversion - Alternate Thoughts

Today I did a small experiment to see how we can use PDF to generate XAML files. I wanted to mimic the pdf form entry in Silverlight.

Here is the summary of what I've done.

Created a new Silver light Project in Expression Blend 3.0 Beta
As Expression Blend can import adobe illustrator files, I simply renamed a pdf file's extension from pdf to ai
Clicked File-> Import Adobe Illustrator files in Blend, and imported to my active window.
Cool, I've the whole form imported as graphical paths, preserving the whole layout.




I just modified the layout a bit so that it can be embedded it in a canvas in a scoll viewer. So that I can place Silverlight controls (textbox/checkbox etc) on top of that to Mimic form entry. Looks good.

Back To Basics - Thinking Beyond ToString()

About Back To Basics - It's often good to look back and fill any gaps we might be having, in certain aspects of the language or framework we use. I'll be examining and blogging about some well known features of C# and .NET, in Back To Basics series - Probably in a bit more detail.




If you want to convert something to string, you might need to find the converter to do the job correctly.

Here is a neat extension method for all your objects, so that it'll find the appropriate converter if one exists, or otherwise, fall back to ToString() :)

public static class ConverterExtension { public static string ConvertToString(this object value) { TypeConverter converter = TypeDescriptor.GetConverter(value.GetType()); // Can converter convert this type to string? if (converter.CanConvertTo(typeof(string))) { // Convert it return converter.ConvertTo(value, …

TFS API Insights

As I was recently working with TFS Client APIs, here are few thoughts on the same.Logging Into TFS Server To log in to the TFS Server using the TFS Client APIs, you can either use the domain authentication, or provide the username or password explicitly - Logging in using the current windows user

TeamFoundationServer _tfsServer = new TeamFoundationServer("serverUrl"); _tfsServer.Authenticate(); - Logging in using a specific network credential

_tfsServer = new TeamFoundationServer( "serverUrl", new System.Net.NetworkCredential ("userName", "password", "domain")); _tfsServer.EnsureAuthenticated(); Getting all the projects - Using VersionControlServer After logging in, you can get all the projects and project items in TFS as shown below. We are reading the latest version for each item

VersionControlServer _versonControlServer=_tfsServer.GetService …