WPF Scrollable + Zoomable + Dragable Control

Unluckily there is no standard control to zoom, drag and scroll your content. My implementation is based on following tutorial. With this implementation you are able to zoom, drag and scroll arbitrary controls. Showcase ScrollDragZoomControl.xaml <UserControl x:Class=”MinimalMonitoringClient.Controls.ScrollDragZoomControl” xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation” xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml” Background=”Transparent”> <UserControl.Template> <ControlTemplate TargetType=”UserControl”> <ScrollViewer x:Name=”scrollViewer” Loaded=”scrollViewer_Loaded” HorizontalScrollBarVisibility=”Visible” VerticalScrollBarVisibility=”Visible”> <Grid Name=”grid” RenderTransformOrigin=”0.5,0.5″> <Grid.LayoutTransform> <TransformGroup> <ScaleTransform x:Name=”scaleTransform” /> …

Packet structure

The most “complicated” thing with this library is clearly the packet structure. We have to keep some things in mind to guarantee a flawless serialization. We differ between two packet types. The Request and the response packet. Request Packet The request packet is used to “start” a conversation. We literally request something. public class CalculationRequest …

Send/Receive packets

The server can only register each packet type once. Therefore, on serverside we have to use the “RegisterStaticPacketHandler” method. That will map a packettype directly to the given delegate. In the following example we start to listen to a “CalculationRequest” after a connection has been established. public void Demo() { //1. Start listen on a …

Send and receive a packet async

//1. Establish a connection to the server. ClientConnectionContainer container = ConnectionFactory.CreateClientConnectionContainer(“127.0.0.1″, 1234); //2. Register what happens if we get a connection container.ConnectionEstablished += async (connection, type) => { Console.WriteLine($”{type.ToString()} Connection established”); //3. Send a request packet async and directly receive an answer. CalculationResponse response = await connection.SendAsync<CalculationResponse>(new CalculationRequest(10, 10)); Console.WriteLine($”Answer received {response.Result}”); };

Send and receive a packet with a delegate

public void Demo() { //1. Establish a connection to the server. container = ConnectionFactory.CreateClientConnectionContainer(“127.0.0.1″, 1234); //2. Register what happens if we get a connection container.ConnectionEstablished += connectionEstablished; } private void connectionEstablished(Connection connection, ConnectionType type) { Console.WriteLine($”{type.ToString()} Connection established”); //3. Register what happens if we receive a packet of type “CalculationResponse” container.RegisterPacketHandler<CalculationResponse>(calculationResponseReceived, this); //4. Send a …

Send and receive a packet in a lambda

//1. Establish a connection to the server. ClientConnectionContainer container = ConnectionFactory.CreateClientConnectionContainer(“127.0.0.1″, 1234); //2. Register what happens if we get a connection container.ConnectionEstablished += (connection, type) => { Console.WriteLine($”{type.ToString()} Connection established”); //3. Register what happens if we receive a packet of type “CalculationResponse” connection.RegisterPacketHandler<CalculationResponse>((response, con) => Console.WriteLine($”Answer received {response.Result}”), this); //4. Send a calculation request. connection.Send(new …

Client Setup

[TCP/UDP] ClientConnectionContainer The ClientConnectionContainer contains a TCP and a UDP connection by default. In addition the ClientConnectionContainer supports: Reconnecting if the TCP and/or the UDP connection has been lost Offering various methods to send data (async, fast, slow) Buffering packets if there is no available connection Remember your settings and packet-configurations after a reconnect public …

Server Setup

static void Main(string[] args) { //1. Create a new server container. ServerConnectionContainer serverConnectionContainer = ConnectionFactory.CreateServerConnectionContainer(1234, false); //2. Apply some settings serverConnectionContainer.AllowUDPConnections = true; //3. Set a delegate which will be called if we receive a connection serverConnectionContainer.ConnectionEstablished += ServerConnectionContainer_ConnectionEstablished; //4. Set a delegate which will be called if we lose a connection serverConnectionContainer.ConnectionLost += ServerConnectionContainer_ConnectionLost; …

UWP (WinRT) Get Raw and Real Resolution

Working with resolutions can be a real pain with WinRT apps. The MS framework isn’t as far developed as we wish sometimes. Getting the “real” resolution on a device depends on several factors. Does the device supports software buttons Do we display the titlebar Which scale factor is currently active The orientation of the device DPI All …