C# Int (Integer) Infinity

Background

I’m implement a data structure which is used to convert a time range to human-readable text, e.g. 0-7 days to “Within 1 Week”, 7-30 days to “1 Week to 1 Month”. Here I use Tuple<int,int> to represent the time range but not two integers, because we can define a Dictionary<Tuple<int, int>, String> to represent a map from time range to text.

But how could we represent “Over 2 Weeks”? Apparently the second parameter of the Tuple should be infinity.

Infinity

To represent infinity for an integer, we can use int.MaxValue (it’s actually Int32.MaxValue)

So we can solve above problem using following code

 

IKVM.NET Convert JAR to .NET (C#, VB.NET) DLL

Why Convert JAR to .NET DLL

Imagine your company builds an online file converter, and its backend programming language is Java because of its position in web development. And in this project you build a file parsing library (jar format certainly) which is used to parse different types of files.

After this project is done, your boss decides to create a Windows desktop version for this software. Now the best choice is .NET, but how can you reuse your java parsing library? That’s why IKVM.NET existed.

IKVM.NET Introduction

IKVM.NET is a .NET implementation of Java which allows us to run Java code in .NET (C#, VB.NET, etc.) easily. It includes following three components:

  • JVM in .NET (which means you can run java byte code in .NET)
  • Java class library implementation
  • A compiler converting java byte code to .NET IL

There are many famous Java projects converted to .NET using IKVM.NET already, such as Tika, Curator, etc. Even Mono has include it as a built-in component.

Start Converting

This will generate a DLL file named libpst.dll from libpst.jar in current directory.

Without -target:library option, it will generate an exe file.

 

WPF Dragablz Tutorial Part 2: Set Custom Tab Host Window

Introduction

Dragablz is a WPF Tab Control which can let us to drag and drop tabs, drag tabs out as floating window and docking support, etc. It’s a pretty good control, but its documentation is too few.

In Dragablz’s official tutorial, we use default InterTabController for TabablzControl, and InterTabClient property is not specified for InterTabController, so tearing a tab out directly will only create a window which is same as the container window of the TabItem.

In this tutorial I will show you how to create a custom Tab Host Window.

 

Step 1 – Implement IInterTabClient

To set a custom Tab Host window, we should implement the IInterTabClient interface, which contains two method signature

Only the first method GetNewHost will be used here, so we can ignore the TabEmptiedHandler method.

Create a new class named MainInterTabClient.cs and make it implement IInterTabClient interface, then modify the GetNewHost method like following

The return value is the new host for dragged out tab, next we will create a new window for it.

 

Step 2 – Create a new Tab Host Window

Add a new window named TabHostWindow

Visual Studio add new window

Visual Studio add new window

In XAML View, add following code

 

Step 3 – Add Window into InterTabClient

Go back to MainInterTabClient.cs, update the GetNewHost method

It will create an instance of our newly created TabHostWindow as the host of dragged out TabItem.

Step 4 – Create a ViewModel for MainWindow

Next we need create a ViewModel class to bind newly created InterTabClient, name this class MainWindowViewModel.

 

Step 5 – Bind ViewModel

Now we need bind the ViewModel we created just now, add following line into your MainWindow constructor:

Then modify XAML of your MainWindow

 

Finally, we finish it! Drag a tab out you will see the tab will be inside a new clean window.

WPF ModernUI Tutorial Part 1

Introduction

ModernUI is a nice WPF theme and a styling framework which let you build a modern, beautiful application easily. Are you poor in designing skill and have problem with designing GUI for your WPF applicaiotn? If so, you have to try ModernUI, it is the best choice for you. In web design, there is Bootstrap for building great UI. And for WPF, it is Modern UI.

 

Screenshots

 

Installation

The installation is really easy, just search “ModernUI” in Manage NuGet Package Window, and select “ModernUI for WPF” item and click “Install”

Install ModernUI for WPF in NuGet Package Manager

Install ModernUI for WPF in NuGet Package Manager

Or run following command in Package Manager Console

 Install-Package ModernUI.WPF

 

Create a ModernUI Window

First create a new WPF Application Project named “ModernUISample”. After creating project, select MainWindow.xaml, change the XAML as following:

The ModernWindow class is defined under FirstFloor.ModernUI.Windows.Controls, so add following line to MainWindow.xaml.cs to import this namespace

Then let MainWindow inherit from class ModernWindow

 

Click “Debug” button to run the program, we will see a black rectangle with a light blue border is shown. What’s wrong with it? It’s because that we have not applied the theme files to our application.

Open App.xaml, and add following code:

 

 

Run the program again, you will see a modern window is shown

Modern UI blank window