Sunday, 2 August 2015

Overriding the windows theme in WPF

WPF applications are styled by default to match the current Windows theme. If you want your application to use another Windows theme, simply override the default theme in the App.xaml file of your project.

This is what a simple application window looks like by default on Windows 8:



In order to override the look of your application so that it resembles the Windows 7 theme, simply change your App.xaml to add this to your Application.Resources section

<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
   <ResourceDictionary Source = "/PresentationFramework.Aero;component/themes/Aero.NormalColor.xaml"/>
   </ResourceDictionary.MergedDictionaries>
</ResourceDictionary>


Next, add a reference to the PresentationFramework dll from the Solution Explorer (right click on references):


Select the PresentationFramework.Aero dll from the list:



Run your application.
Your application will now look like this:



The downside is that the window (border) does not seem to be affected by this.

The other Windows themes can also be selected (Eg: Luna). Just select the appropriate dll reference and update the code highlighted in red above to match it. The other options can be seen in the image showing the selection of the reference to be added.

Sunday, 12 July 2015

(WPF) Check(events) if the user has switched to High contrast mode in C#

When users use high contrast modes on Windows, hardcoded colors in Windows Presentation Foundation applications result in an inconsistent(often ugly and not very usable) look. Changing colors or themes dynamically when the switch is made is sometimes required(although rarely, if you design your styles well).

For those like me who prefer doing this in C# rather than XAML, the SystemParameters.HighContrast property provides a boolean value that is True or False depending on whether one of the high-contrast modes is enabled. This property can be checked by an event handler that is registered to the SystemParameters.StaticPropertyChanged event.

One caveat is that while the SystemParameters.HighContrast property is available on .NET versions 3 and up, the StaticPropertyChanged .event is only available from version 4.5.
For applications that support .NET versions below 4.5, simply subscribe to the SystemEvents.UserPreferenceChanged event instead. For example usage, see my previous post (lines 47 and 63).

Windows Presentation Foundation TextBox with placeholder/hint/watermark

WPF does not ship with a textbox control which has support for a watermark aka placeholder aka hint.

This is my custom control. By no means is this the most efficient or tiniest solution. There are probably better. This is intended for learners because it does not require XAML(XML) Triggers or styles. Just plain old C# with a dependency property and event handling.


Friday, 23 January 2015

Guava dependency error while installing M2Eclipse on Eclipse Juno

Quick update:

Recently I was working on Eclipse Juno, I encountered a problem while trying to install M2Eclipse.
The eclipse software installation status complained to me that it could not find the artifact 'bundle com.google.guava...'.

While for some this may be a no-brainer, I have posted it here for those who think this could be a bug. This occurs when you try to install the 1.5 version of M2E. If you cannot download the latest version of Eclipse, you can simply settle for installing version 1.4 of M2E because the version of Guava that M2E 1.5 requires is not bundled with Eclipse Juno.

Monday, 19 January 2015

A simple bottle app for listing directory contents (python 3)

Here is a simple directory listing application created using the bottle.py micro framework:
(Please notify me of any problems with my code using my github presence or in the comments).

Saturday, 6 December 2014

Programming GUI's with Python3

The backward incompatible version of the Python programming language, Python3 (introduced on the python.org website as Python3000 or Python3k - see: https://www.python.org/download/releases/3.0/) has had some significant years of development. It was originally released in December 2008. However, the transition of its gigantic arsenal of tools and modules did not keep up - until recently. This is especially true with respect to the GUI tool-kits available for the language. Although Python boasts a breath-taking list of GUI tool-kits, most of these were created for the Python 2.x series.

Apart from Tk(a python GUI tradition, bundled with Python as Tkinter), Qt was probably one of the first major tool-kits with support for Python 3 - known as PySide.

For all the fans of Gtk3, you can develop applications in Python 3 that use the Gtk tool-kit (along with many other components of the Gnome project). The now-deprecated PyGTK is no longer recommended for use. It is time to switch over to the newer, actively-maintained, PyGObject, which provides GObject Introspection bindings for Python 3.

Also among the major players, WxWidgets/WxPython has also begun to see some development for Python 3 in the recent weeks. WxPython releases for Python 3 are created under Project Phoenix.

While views on this may vary, my opinion is that it is of no use to newcomers to the Python world to learn Python 2.x only to have to learn Python 3.x later. Some will argue that it isn't a big deal to learn both; however I would have to say that it is not a worthwhile pursuit when one has a a wide variety of interests and does not have enough time to approach them redundantly ;).

Several years after the initial release of Python 3, we are finally starting to see significant efforts being made to port our favorite libraries and tools to Python 3. This is a relief for those who are tired of the usual responses on various Q&A sites such as, "Why don't you just use Python 2.x? It will be supported for a long time to come". Although some libraries are still not Python3-ready, it's a start.

Here are the links to the toolkits mentioned above:
  1. PySide (Python3 bindings for Qt): http://qt-project.org/wiki/PySide
  2. PyGObject (Python3 bindings for Gtk): https://wiki.gnome.org/Projects/PyGObject
  3. WxPython (Python3 bindings for WxWidgets): http://wxpython.org/Phoenix/docs/html/main.html
For a list of other  Python 3 packages, see https://pypi.python.org/pypi?:action=browse&c=533&show=all