Posts

Donate

Entity Framework Core Scaffold-DbContext Error - The certificate chain was issued by an authority that is not trusted.

Image
Hello, I was converting a .NET core 2.2 console application into a .NET 7 project that will reverse engineer a sample database from Microsoft called ContosoRetailDW as the data source for my Entity Framework Core project. Upon running the Scaffold-DbContext command in Nuget Package Manager Console, an error occured was shown on the window with the specific message "A connection was successfully established with the server, but then an error occurred during the login process. (provider: SSL Provider, error: 0 - The certificate chain was issued by an authority that is not trusted.)" Scaffold-DbContext "Server=Your_Server;Database=ContosoRetailDW;Integrated Security=True" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models After reading through the forums, the solution that worked form me was to add a TrustServerCertifcate setting with a value to true or Encrypt setting set to false. The latter is the recommended one based from the forum answers. Option

Visual Studio 2022 Error - There was a problem adding your GitHub account. Your default web browser might be using HSTS for localhost.

Image
Good day! I was about to publish one of my .NET 7 console application to GitHub using Visual Studio 2022. And when adding my account, an error occured which states that "There was a problem adding your GitHub account. Your default web browser might be using HSTS for localhost.". After doing some research, I found this post Disabling HSTS for localhost on Chromium-based browsers which fixed the problem for MS Edge or Google Chrome Browsers. First you need to type in the browser url " about://net-internals/#hsts " command to open the Domain Security Page of your browser where you can clear the HSTS. Under " Delete domain security policies " domain textbox, type in localhost and click the delete button. After that, I have successfully added my GitHub account in Visual Studio 2022 and was able to publish my project. Cheers!

Accessing WebView2 Control And It's properties In A C# Class Library

Image
Team, In a situation wherein you need to access a WebView2 control properties in a class library and that the WebView2 control is added in a WPF project, all you need to do is to reference the Microsoft.Web.WebView2.Wpf.dll and Microsoft.Web.WebView2.Core.dll from the WPF project into the class library. The sample code below is a utility class located in a class library project which has a WebView2 control object that performs navigation to a url that is set from the WPF project. public static class WebBrowserUtility { public static readonly DependencyProperty BindableSourceProperty = DependencyProperty.RegisterAttached( "BindableSource" , typeof ( string ), typeof (WebBrowserUtility), new UIPropertyMetadata( null , BindableSourcePropertyChanged)); public static string GetBindableSource(DependencyObject obj) { return ( string )obj.GetValue(BindableSourcePr

How To Set Overlay On Top Of A WPF WebBrowser Or WebView2 Control

Image
Good day! A common scenario to our projects is to use the Overlay concept that is, show a nearly transparent modal on top of our form. I have been using the code below to create an Overlay using just a Border and a TextBlock but to no avail, it just won't sit right on top of the WebBrowser control. In the picture right next to the Border control snippet, only the input controls are covered by the overlay and ignoring the WebBrowser control. <Border BorderBrush= "Black" BorderThickness= "1" Background= "#80000000" Visibility= "{Binding Path=IsBusy, Converter={StaticResource BoolToVisibilityConverter}}" Grid.RowSpan= "4" Grid.ColumnSpan= "3" > <Grid> <TextBlock TextAlignment= "Center" Margin= "0" TextWrapping= "Wrap" Width= "500" Text= "{Binding Path=OverlayMessage}" HorizontalAlignment= "Center" VerticalAlignment= "

WPF WebBrowser Control Not Rendering External HTML Content Properly

Image
Good day Team, I'm currently working on a project to show some information about settings to a WPF WebBrowser control. The project also has the ability to produce a report in an .html file that can be viewed through the browser by the clients. Upon comparing the results from both the .html file and the file rendered to the webbrowser, I noticed that the html file is broke when rendered. Some of the borders are missing and some of the colors are not reflecting. Upon doing some research, I found a solution that is to change the meta tag to use the MS edge engine. When I verified my code to dynamically generate the html file, I noticed that the code to set the meta tag uses plain text/html content such as the code below. private void WriteOpenMainTags( string prevFile, string currFile, ref StringBuilder openMaintags) { openMaintags.AppendLine( "<!DOCTYPE HTML>" ); openMaintags.AppendLine( "<html>" ); openMaintags.AppendLine( "&

Using MahApps.Metro.IconPacks In WPF Application

Image
Good day! Ever wonder how to style your WPF application controls or window with icons where you can choose from several hundreds of icons in a package? Well, nothing to worry about since there's an awesome Nuget Package that provides icons to suit your needs. It's called MahApps.Metro.IconPacks . The cool thing is, it's even grouped into several categories and that each category containes hundreds of icons. To use this awesome library of icons in your WPF project, install the Nuget Package specifically MahApps.Metro.IconPacks. In your XAML view, reference the MahApps.Metro.IconPacks namespace first. xmlns:iconPacks="http://metro.mahapps.com/winfx/xaml/iconpacks" To use them like applying icons to your menu items, call the iconsPacks namespace and select PackIconMaterial. Then set the Kind property with the icon of your liking. <iconPacks:PackIconMaterial VerticalAlignment= "Center" HorizontalAlignment= "Center"

How To Close A Window Via Click Command Using MVVM In WPF

Image
Good day! Here's a simple WPF tutorial on how to close a window in WPF thru button click which applies the MVVM pattern. For simplicity sake, I'll demonstrate by using Menu item with a command to close the window. Start by creating a WPF project that target's the latest framework and add classes for DelegateCommand, MainViewModel and ViewModelBase inside a ViewModels folder. See below project setup. Add the code for ViewModelBase class that implements the INotifyPropertyChanged interface. public class clsViewModelBase : INotifyPropertyChanged { public event PropertyChangedEventHandler PropertyChanged; protected void OnPropertyChanged( string propertyName) { if (PropertyChanged != null ) PropertyChanged( this , new PropertyChangedEventArgs(propertyName)); } } Next is to add the functionality of the DelegateCommand class that implements the ICommand interface. This class handles the Commands bound to the WPF controls pu

WPF Menu Item Drop Alignment Appears To The Left Instead Of Right In Windows 10

Image
Hello, I was assigned a new laptop and when I ran several of my WPF applications into this machine, I suddenly noticed that the menu items drop alignment appears to the left instead of right. Since this is a OS setting, we need to change some values in the registry. Open registry editor and navigate to this registry path -> Computer\HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Windows . Change the MenuDropAlignment value from 1 to 0 similar to the picture below. Once done changing the value, make sure to reboot your machine for this changes to take effect. After that, your menu item drop alignment changes from left to right. Output Cheers!

Using OpenFileDialog Or MessageBox In .NET Core Class Library Project With WPF Application

Image
Good day Team! Given that you need to access the OpenFileDialog or MessageBox Dialog In Your .NET Core Class Library that is part of a solution that contains a WPF project, there's an easy hack provided by our Solutions Architect that is to hand hack the .csproj settings. First is to open the .csproj file using an editor. Inside Property Group node, add enable WPF by adding a UseWPF element with the value of true such as below. <Project Sdk= "Microsoft.NET.Sdk" > <PropertyGroup> <TargetFramework>net7.0-windows10.0.17763.0</TargetFramework> <ImplicitUsings>enable</ImplicitUsings> <Nullable>enable</Nullable> <UseWPF>true</UseWPF> </PropertyGroup> <ItemGroup> <PackageReference Include= "Company.Utilities.CompanyLibNET7" Version= "1.0.0.3" /> <PackageReference Include= "Microsoft.Extensions.DependencyInjection" Version= "7.

How To Download GitHub Source Code Using Mobile Device

Image
Good day! Given that you have a difficulty downloading a specific source code from github using the mobile device like screenshot below, here's a solution on how to do it using the google chrome mobile browser. First is to click the elipse (3 dots vertically aligned) button beside the url textbox. Scroll down the drop down box and check Desktop Site Once enabled, your browser will show the desktop view of github page and the Code button colored green appears as expected. You may now proceed with downloading the source code. Cheers!

Donate