Defining Styles in WPF
Of course, we can put the styles for controls in each windows xaml file. But I am more prefer to all styles storing in a single file, that is more similar with CSS file. If any changes in styles required, you need to modify a single file. That is more manageable.
But, please don't forget to add the reference in App.xaml:
<Application.Resources>
<ResourceDictionary Source=
"Styles.xaml"
/>
</Application.Resources>
For further details please visit our opensource project - AdvGenContact Manager
Dynamically Create an instance of class in code
In C#, you can create an instance of class dynamically. For example, you can create an instance of class according to database values, rather than hard coded.
You just need to use reflection.
Code
ObjectHandle obj = Activator.CreateInstance(AssemblyName,className); | |
Controller = (IApp) obj.Unwrap(); |
Please note that, Assembly Name is without ".dll", such as "AdvgenContact.App.WPF", and the class name need to be full qualified, for example, "AdvgenContact.App.WPF.MainApp".
If you wish to know more, please check out our open source project, AdvgenContact.
Surface Roadshow at Carindale
When I did my shopping at Westfield Carindale, I found there was a roadshow for Microsoft Surface. That was interesting! In front of the counter, there was a Christmas Tree which is made of Surface. That sounds very geek! Beside that, there is something real! There were a few surface 2 and surface pro 2. I tried a surface pro2! That is cool! It has Windows 8.1, not the RT version! Moreover, it has a touch cover, which has a physical netbook size keyboard. That is better than surface which has only a soft keyboard. I think if I have money, I will buy that as a chirstmas present for myself!
Singleton in C#
To implement Singleton Pattern in C#, that is easy. I like to static class. For example:
Code
public static class GobalData | |
{ | |
public static Group Group {get;set;} | |
} |
HOWTO: Find a Physical Path in ASP.Net from URL
In a number of situations, we need to know a Physical Path in a server from URL. For example, we need to upload some photo. Thus, this is a very common task, and is very easy to do in C#
Code
string serverPath = Server.Map("~/Photo"); // e.g. it returns "C:\site\Photo" |