Posts

Showing posts with the label C#

Learn CSS Grid the easy way

Image

The .NET 8 Auth Changes You Must Know About!

Image
This is a test for embedding videos. Here's a video on  .Net 8 security simplification:

Start template for Xaml MapControl

Image
 The Xaml.MapControl comes with a nice example that sow different options. This can be found in the examples directory at  https://github.com/ClemensFischer/XAML-Map-Control . This post is meant to show a more simple solution. And my hope is that I can use this as a start template. The goal is to end up with this view: And this is the steps to get this going: Create new project and setup  Create a new project in Visual Studio. When writing this I selected the tradistional .Net Framework 4.8. Then I installed the Map Control by the package manager console:      PM> Install-Package XAML.MapControl For this template I didn't use any MVVM Frameworks. This is to make less depentant on third-party solutions. I used the base MVVM template I wrote aboute in:  Absolute Mini MVVM .  Copy those two classes to the folder explained below.   Then I made the following folders in Visual Studio: Models Views ViewModels AbsoluteMiniMvvm Extensions For thi...

Absolute minimal MVVM

Since I have plans for showing some examples using WPF with MVVM, I thought it would be a good idea to post the code for a very basic MVVM template. This is so I don't have to rely on some advanced frameworks. And this way the examples can focus on the issue at hand. The files may be placed in a library and referenced by several projects, or they may be copied inside the project itself. The first class to be used is the base for handling INotifyPropertyChanged in the ViewModels and models: using System.ComponentModel; using System.Runtime.CompilerServices; namespace AbsoluteMiniMvvm { public class PropertyChangedBase : INotifyPropertyChanged { public event PropertyChangedEventHandler PropertyChanged; public void RaisePropertyChanged([CallerMemberName] string propertyName = null) { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); } } } The second is for the Command: namespace AbsoluteMiniMvvm { public class Command : ICommand { ...

Tip to enable key-events in WPF

Working on a project with editing shapes I came over a problem when I wanted to canced the operation when the user pressed the escape-key. When I added an event handler for KeyPress or KeyDown or even PreviewKeyDown it never fired. This was because the graphical elements didn't actully have focus. For my user-control for the graphic element I solved this by adding this in the constructor: this.Focusable = true; this.FocusVisualStyle = null; The second line ensured that the dotted focus-rectangle also disseapeared. For a xaml-based approach this is the markup: <Canvas Focusable="True" FocusVisualStyle="{x:Null}">  <!-- The shapes or elements like an elipse, rectangle, path or stack-panel... --> </Canvas>