Posts

Switching between WPF XAML views using MVVM DataTriggers

Image
Related post: https://www.technical-recipes.com/2016/switching-between-wpf-xaml-views-using-mvvm-datatemplate/ This post addresses the problem of being able to switch between different views based on the property of a ViewModel class. To get started in Visual Studio, create a new WPF Application: So that when we build and run the application we have a blank window like this: To demonstrate how WPF windows can be made to switch between different views, create two new XAML views, View1.xaml and View2.xaml, each consisting of a simple TextBlock containing different texts to demonstrate that the views are different. In your Visual Studio project, right-click your project folder and select Add > New Item. Select User Control (WPF) and name your file as View1.xaml: In the xaml portion of the file, insert the code to display the Text in the view as follows: [code language="xml"] <UserControl x:Class="XamlSwitching.View1" xmlns=...

Getting started with Java in Eclipse

Image
1. Download Eclipse Obtain the installer from the following site: https://eclipse.org/downloads/ and complete the installation: 2. Create a new Eclipse project Open Eclipse and select File > New > Java Project. Give the project a name ('HelloWorld'): Click Next. And then click Finish. 3. Add your Java class Select File > New > Class: Set the Name field to 'HelloWorld' and check the box labelled 'public static void main(String[] args)': Click Finish. So that your project looks like this: 4. Write your code In this example, the proverbial "Hello World" example: [code language="java"] public class HelloWorld { public static void main(String[] args) { System.out.println("Hello, World"); } } [/code] 5. Build and run your Java project: Select the down arrow next to the Run icon and select Run As > Java Application: Giving the desired "Hello World" console output: ...

Getting started with Mono in Linux

Image
Some instructions on how to get started with using Mono in Linux environments: from installation to running your first "Hello World!" example. Open up your terminal and issue the following commands: [code language="text"] sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF [/code] [code language="text"] echo "deb http://download.mono-project.com/repo/debian wheezy main" | sudo tee /etc/apt/sources.list.d/mono-xamarin.list [/code] [code language="text"] sudo apt-get update [/code] [code language="text"] sudo apt-get install Mono-Complete [/code] Check that your Mono has installed by using the 'version' command: [code language="text"] mono --version [/code] We can now test our installation of Mono by writing some code, in this case the proverbial "Hello World!" example. Open a text editor of your choice and enter ...

Using POSIX threads in Microsoft Visual Studio

Image
Threads can be used to implement parallelism. For UNIX-based systems, a standardized C language threads programming interface has been specified by the IEEE POSIX 1003.1c standard. Implementations that adhere to this standard are referred to as POSIX threads, or Pthreads. Windows does not support pthreads directly, instead the Pthreads-w32 project seeks to provide a portable and open-source wrapper implementation. The first step is to obtain the pthread project from the following ftp site: ftp://sourceware.org/pub/pthreads-win32/ And extract it to a location of your choice: This will be the location of where your project dependencies and additional library files will be located. To demonstrate an example pthreads usage in a Microsoft Visual Studio environment, first create a new Empty Project: Add the main.cpp source file to your empty project and use the following code sample: [code language="cpp"] #include <pthread.h> #include <stdio.h>...

Getting started with Gurobi in Microsoft Visual Studio

Image
A guide on how to get up and running with Gurobi , a powerful software tool that is well suited to finding solutions to tough optimization problems encountered in industry and academic research. In addition to finding good solutions within practical time scales, I was pleasantly surprised to discover how easy it was easy to use and configure within Microsoft Visual Studio. To apply the Gurobi tools to optimization problems, the developer simply makes calls to Gurobi Application Program Interfaces (APIs) at the appropriate places in the code, tweaking them to suit the application area. The following steps demonstrate how to achieve this for a mixed integer programming problem: 1. Install & Licence Gurobi Run the Gurobi installer file. At the time of writing this post, I installed 32-bit version of Gurobi 6.5.0, using the straightforward 'vanilla' installation: ... thereby installing Gurobi, and it's contents to a default location: 2. Create a new...

Using OpenGL in Microsoft Visual Studio

Image
Getting started with using OpenGL / freeglut in a Microsoft Visual Studio environment for 32 bit versions. 1. Obtain freeglut Go to the freeglut site to obtain the MSVC package: http://www.transmissionzero.co.uk/software/freeglut-devel/ At the time of writing this demonstration we obtain version 3.0.0 in zip file format: http://files.transmissionzero.co.uk/software/development/GLUT/freeglut-MSVC.zip 2. Obtain glew http://sourceforge.net/projects/glew/files/glew/ At the time of writing this demonstration we obtain version 1.13.10 in zip file format: http://sourceforge.net/projects/glew/files/latest/download?source=files 3. Place freeglut and glew in the location of your choice: 4. Create a new empty project in Visual Studio Add your main.cpp source code file. Don't have to put anything in it for the time being: 5. Set the Additional Include Directories Select project properties > C/C++ > General tab > Additional Include Directories. Do thi...

Using a genetic algorithm to solve the n-Queens problem in C++

Image
A post showing how a genetic algorithm when used appropriately can be used as a powerful means to solve the n-Queens problem of increasing sizes. A downloadable Visual Studio 2010 C++ project implementing the genetic algorithm is available. Problem Description The N-Queens problem is the placement of queens on a chess board so that none are threatened - no single queen share a common row, column, or diagonal. The difficulty of the problem explodes with the number of queens involved and is known to be computation expensive. For example, there are 4,426,165,368 possible arrangements of eight queens on an 8×8 board, but only 92 solutions (source: Wikipedia ). Applying the genetic operators An outline of the genetic algorithm that was applied to this problem and implemented in C++ is as follows: Generate a population of solutions representing the positions of the N number of queens on the chessboard. Solutions ("chromosomes") are represented using integer arra...