Posts

Showing posts from 2017

WPF create a grid splitter

You will often find yourself needing to have two panels on a screen with a slider between them. WPF gives you a nice way to handle this with the GridSplitter control. You will need to create a column for the actual splitter and it will use the width you give it in the column definition. <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="*" /> <ColumnDefinition Width="5" /> <ColumnDefinition Width="*" /> </Grid.ColumnDefinitions> <TextBlock FontSize="55" HorizontalAlignment="Center" VerticalAlignment="Center" TextWrapping="Wrap">Left side</TextBlock> <GridSplitter Grid.Column="1" Width="5" HorizontalAlignment="Stretch" /> <TextBlock Grid.Column="2" FontSize="55" HorizontalAlignment="Center" VerticalAlignment="Center" Te...

WPF Bind a combobox to an enumeration

I've often found myself needing to bind a combo box to an enumeration I've created. You can do this in WPF but it's a bit complicated. You end up needing to create a static resource. I had mine in a user control. First the enumeration I was using: namespace XmlCoderBI.Enums { /// <summary> /// An enumeration that represents the type of conversion we're doing /// </summary> public enum ConversionType { /// <summary> /// The binary /// </summary> [Description( "Binary" )] Binary = 0, /// <summary> /// The base64 /// </summary> [Description( "Binary" )] Base64 = 1, /// <summary> /// The hexadecimal /// </summary> [Description( "Hexadecimal" )] Hexadecimal = 2, /// <summary> /// The UTF-8 /// </summary> [Description( ...

C# async and await

The async and await keywords in C# are the heart of async programming. By using those two keywords, you can use resources in the .NET Framework or the Windows Runtime to create an asynchronous method almost as easily as you create a synchronous method. Asynchronous methods that you define by using async and await are referred to as async methods. The following example shows an async method. Almost everything in the code should look completely familiar to you. The comments call out the features that you add to create the asynchrony. // Three things to note in the signature: // - The method has an async modifier. // - The return type is Task or Task<T>. (See "Return Types" section.) // Here, it is Task<int> because the return statement returns an integer. // - The method name ends in "Async." async AccessTheWebAsync() { // You need to add a reference to System.Net.Http to declare client. HttpClient client = new H...