Posts

Showing posts from June, 2017

A simple example of using dependency injection using Unity in WPF

Image
Step 1: Create a new Visual Studio project Step 2: Add the necessary Unity reference Select Tools > NuGet Package Manager. Type in the following command: [code language="txt"] Install-Package Unity -Version 4.0.1 [/code] Unity website for NuGet can be found here: https://www.nuget.org/packages/Unity/ Step 3: Remove the startup URL In App.xaml get rid of the StartupUri value: Step 4: Add the Model class / interface IModel.cs [code language="csharp"] namespace DependencyInjection { public interface IModel { } } [/code] Model.cs [code language="csharp"] namespace DependencyInjection { public class Model : IModel { public Model() { Text = "Hello"; } public string Text { get; set; } } } [/code] Step 5: Add the ViewModel class To deal with the error that we receive in the XAML when a ViewModel has "No parameterless constructor defined for this object" ...

Using fullpage.js to implement HTML page scrolling

Image
Some instructions on how to use fullpage.js to scroll between sections in your web page. I am not a web developer, so this post will contain a minimum of javascripting, css styling and so on. I just wanted to see how fullpage.js can be incorporated so that individual web pages can be scrolled horizontally in an animated way. Step 1: Download fullpage.js Fullpage.js javascript can be downloaded from here: https://alvarotrigo.com/fullPage/ This will download a file called fullPage.js-master.zip. Once the zip file has been downloaded, extract it somewhere. Step 2: Create folder structures for your web page(s) I have created a folder called 'FullPage' containing the subfolders 'html' and 'resources' in which the HTML file(s) and style sheets/javascripts will be contained respectively: Step 3: Install the necessary styling and resources. In the 'resources' folder create a further two subfolders 'css' and 'javascript'...

Applying the 2-opt algorithm to travelling salesman problems in Java

Image
This post tackles the problem of applying the 2-opt algorithm to travelling salesman problems in Java. The results of applying the 2-opt heuristic and applying it to a number standard traveling salesman test problems. are shown For a more in-depth description of the 2-opt heuristic, please refer to the following Wiki page: http://en.wikipedia.org/wiki/2-opt The actual 2-opt heuristic can be summarised by the following pseudocode steps, repeating for all feasible combinations of I and k: [code language="xml"] 1. take route[1] to route[i-1] and add them in order to new_route 2. take route[i] to route[k] and add them in reverse order to new_route 3. take route[k+1] to end and add them in order to new_route 4. return the new_route; [/code] A nearest neighbour search algorithm is included in the Java implementation. A comparison is made of the kind of results we get from the 2-opt algorithms, with and without improving the initial tour using the nearest n...

Creating installations using Inno Setup in Visual Studio

Image
Step 1: Run the Inno Setup installer When using Inno Setup within Visual Studio project as a post-build exercise to create an installer package, you will need the contents of the Inno Setup folder as this will contain the command line executables, dll files etc. If you have not already done this, you can get it from here: http://www.jrsoftware.org/ Step 2: Create a new Visual Studio project Right click on the solution and select to add a new Installer project (class library) 3. Add 'Inno Setup' contents to your Installer project I like to keep everything completely self-contained within Visual Studio projects, so whether you prefer to reference the Inno content that has already been installed to the Program Files folder is up to you Right-click and select Add > New folder. In Windows Explorer copy the existing Inno Setup folder contents to the one you created in your Visual Studio project. Once the contents are copied over I then right-click the...

Using the Gecko browser using MVVM

Image
A similar post on using the Gecko browser via WPF can be found here: https://www.technical-recipes.com/2017/using-the-gecko-web-browser-in-wpf/ In this post I extend these ideas a little so that the Gecko web browser, a WinForms control, can be used as part of the MVVM pattern. Some other modifications are necessary, such as incorporating ICommand implementations, and supervisor controlling patterns to get this thing running. Step 1: Create a new WPF project Create using a suitably recent version of .NET. In this example I use version 4.5.2. Step 2: Install NuGet packages Install Gecko. In my example I install the Windows 32-bit version. Select Tools > NuGet Package Manager > Package Manager Console Run the following command: [code language="text"] Install-Package Geckofx45 [/code] Install System.Windows.Interactivity Select Tools > NuGet Package Manager > Package Manager Console Run the following command: [code language="text...

Using the Gecko web browser in WPF

Image
Some instructions on how to incorporate the Gecko (Firefox) web browser, which is WinForms-based, for use within your WPF / XAML based C# project. A similar post can be found here, whereby I use the MVVM-based approach: https://www.technical-recipes.com/2017/using-the-gecko-browser-using-mvvm Step 1: Create a new WPF project Step 2: Install Gecko via NuGet In my example I install the Windows 32-bit version. Select Tools > NuGet Package Manager > Package Manager Console Run the following command: [code language="txt"] Install-Package Geckofx45 [/code] Step 3: Add any other essential references Right click your project folder and select Add References. (Make sure that System.Windows.Forms is already installed.) Select WindowsFormsIntegration as the reference to add: Step 4: Set the configuration to 32 bit As shown in the Configuration Manager screenshot below: Step 5: Update the main View In this example the element is given the Name...