Rick Strahl's Weblog  

Wind, waves, code and everything in between...
.NET • C# • Markdown • WPF • All Things Web
Contact   •   Articles   •   Products   •   Support   •   Advertise
Sponsored by:
Markdown Monster - The Markdown Editor for Windows

WebLog Posts in Category WPF


Categories
ASP.NET (325) .NET (182) Windows (78) JavaScript (72) jQuery (61) Visual Studio (54) WPF (48) IIS (48) Csharp (47) HTML (46) AJAX (45) ASP.NET (33) Localization (32) LINQ (30) WCF (28) MVC (26) Personal (25) Security (23) HTML5 (23) FoxPro (22) CSS (21) C# (20) Angular (20) Web Services (19) Web Api (16) COM (16) ADO.NET (15) Vista (11) Sql Server (11) XML (11) WebView (10) HTTP (10) IIS7 (10) Markdown (9) Microsoft AJAX (8) IIS7 (7) West Wind Ajax Toolkit (7) Web Connection (7) NuGet (6) Markdown Monster (6) Entity Framework (6) Html Help Builder (5) Live Writer (5) Internet Explorer (5) C++ (5) ASPNET5 (5) Mobile (5) SignalR (5) Software Development (5) Web (5) OWIN (5) WinForms (5) Westwind.Globalization (4) Source Control (4) Silverlight (4) Cordova (4) Conferences (3) DataBinding (3) ASP.NET Core (3) Help Builder (3) ISV (3) LetsEncrypt (3) Networking (3) Office (3) Opinion (3) Razor (3) Web Browser Control (3) WebLog (3) Web Development (2) Visual Studio Code (2) Tools (2) Speaking (2) RegEx (2) RSS (2) Linux (2) Installation (2) Bugs (2) Help (2) Dotnet (2) .NET Standard (2) Addins (2) Deployment (2) Authentication (2) ASP.NET vNext (2) ADO.NET (1) Chocolatey (1) Blazor (1) Blogging (1) Desktop (1) Control Development (1) Credit Card Processing (1) Cross-Platform (1) .NET ASP.NET Windows (1) Security (1) Visual Studio (1) ASP.NET IIS (1) ASP.NET Markdown (1) AI (1) Angular JavaScript (1) Dynamic Types (1) Email (1) CSharp Dotnet (1) Git (1) Graphics (1) Hardware (1) FireFox (1) Flexbox (1) IOS (1) JSON (1) Migration (1) rxJs (1) SEO (1) RazorPages (1) Musings (1) Travel (1) Typescript (1) Testing (1) Threading (1) VS Code (1) Web Deployment Projects (1) Web Design (1) Web Assembly (1) WebSockets (1) WebSurge (1) WebBrowser (1) WebDeploy (1) WFH (1) Windows-Terminal (1) Windsurfing (1) WPF Windows (1) WSL (1) wwHoverPanel (1)

Getting the Current TabItem when the Tab is not selected in WPF



There's no direct support in WPF to find the control that the mouse is hovering over in Items controls like the TabControl, so if you need to bring up context sensitive information like a context menu or tooltip it takes a little extra effort to get the correct item to work with in this case ContextMenuOpening.

Working around the WPF ImageSource Blues



The WPF Image control and its ImageSource property can be problematic if you are loading a lot of images in a list. Depending on where you load images from, and how, you can very easily get bogged down with slow, blocking load operations, and memory leaks when the controls are released. In this post I describe a couple of specific problems I ran into loading a sizable list of images from files and show a few ways how to avoid the potential pitfalls related to ImageSource peculiarities.

Embedding a minimal ASP.NET Web Server into a Desktop Application



Did you ever need to embed a Web Server into a non-Web application? In this post I describe how you can use host ASP.NET in a non-Web application and specifically in a WPF desktop app. What do you need, how is it different and some of the issues that you need to consider if you want to use ASP.NET in your non-Web applications.

Save Files With Elevated Permissions on UnauthorizedAccessException



If you have an application that generically allows you to edit and save files, you might on rare occasions need to save files in locations that where a regular user account does not have permissions to save. Rather than failing wouldn't it be nice to let the user know and optionally allow saving with elevated permissions? In this post I describe the workflow and implementation on how to do just that.

Caching your WebView Environment to manage multiple WebView2 Controls



I've been struggling with rare WebView initialization errors in one of my applications, that have been difficult to debug and track down. After a lot of trial and error I discovered that the problem is related to WebView Environment instantiations that might be stepping on each other. In this post I describe the problem and a solution that involves creating a single WebView Environment and reusing it for all WebView initialization.

A WPF Statusbar Control



Statusbar controls are boring, but because of the way that they are used there are a number of caveats like ensuring the UI updates even in linear code, allowing for timeouts of status messages and resetting to default, and to provide some visual clues to draw attention to the status messages displayed. In this post I talk about a custom status bar control and helper that make it super easy to use a new status bar control or attach additional functionality to an existing status bar.

Getting the .NET Desktop Runtime Installed with a Custom Runtime Checker and Installer



I've recently moved my Markdown Monster Desktop Application to .NET 7.0 and I had to make a decision on how to get the Runtime installed or packaged with my application. In this post I review the different deployment modes, the plus's and cons and the solution I ended up with which was to build a custom install wrapper that can check and install the runtime if not already present from an Installer or interactively.,

Using Application Insights in .NET Desktop Applications



Using Application Insights with desktop applications isn't the most obvious operation, as App Insights has been primarily designed as a tool for providing logging, statitics and exception report for Web based applications. However, with a little bit of reworking it's actually quite straight forward to use Application Insights with Desktop applications and in this post I show you how I integrate App Insights in my WPF applications.

Basic Windows Machine Hardware information from WMI for Exception Logging from .NET



When writing out error information for a desktop application to a log whether local or to a telmetry engine, it's useful to get some idea of what hardware the app is running on. WPF applications in particular can have odd behaviors that are related to hardware acceleration, running inside of a VM or particular video drivers. In this short post I show how you can get very basic machine and GPU information that provides information on these basic system stats that can prove useful to trackdown rare hardware related issues.

Fighting WebView2 Visibility on Initialization



The WebView2 control has a clever 'feature' that doesn't fully initialize the WebView control if it's not UI visible. While this can save resources in some scenarios it can also make for some very annoying behavior that causes startup timing and flickering issues. In this post I describe a few scenarios where this initial visibility delay loading can cause issues and show a trick you can use to get around it if this 'feature' causes a problem.

Async and Async Void Event Handling in WPF



When running WPF and WinForms applications with async operations, I've run into a number of issues with event handling 'hanging' the UI thread in unexpected ways, where the UI hangs until the mouse is moved or a key is pressed. A lot of times these issues are associated with events that fire async code, and in this post I take closer look at one scenario that can cause these hang ups along with a workaround that has proven useful in a number of occasions for me.

WebView2 Flashing when changing TabControl Tabs



I've been running into major issues with the WebView control and TabControls in WPF where switching between tabs that contain WebView controls causes a very annoying white flash. In this post I demonstrate the problem and provide an arcane fix that works around this frustrating issue.

Using the WebView control to capture HTTP Request Content



Need to capture requests when navigating the new Edge WebView2 control? The control supports this but the way that you do this is a little less obvious than you might be used to from other browser controls. Here's how to do it.

WebView and Modal Dialogs in WPF Async Code



Another day another problem with the WebView control - this time dealing with certain Windows dialogs crashing the WebView control and making it unresponsive so that the control has to be reloaded or - more commonly the application has to be restarted.

Thoughts on Async/Await Conversion in a Desktop App



I spent the last month or so working through Markdown Monster's code to switch from mostly sync code to async code. This change was forced on me by an Async Cascade triggered by a third party dependency of a component (the WebView2 control) and ended up requiring massive changes throughout the app. In this post I go over some of the issues I ran into converting from sync to async along with some thoughts on the pitfalls.

WebView2 Home and End Key Problems inside of WPF TabControl Containers



Another day another WebView2 quirk to work around: This time running into issues with the WebView2 not processing Home and End keys properly as they are being hijacked by a parent TabControl and its TabNavigation keystroke handling.

WebView2: Forwarding Alt Keys to a Host WPF Window



I've been puzzling over how to reliably integrate keyboard forwarding from the WebView2 control into WPF host forms. Unlike the IE WebBrowser control the WebView2 doesn't automatically forward Alt keys to the host form so special handling is required. In this post I describe why this is a problem and show the workaround to make this work.

Chromium WebView2 Control and .NET to JavaScript Interop - Part 2



In part 2 of this post series I take a look at how to use the new Chromium WebView2 to interact with the DOM document and interoperate between .NET and JavaScript, both calling into JavaScript from .NET, and calling into .NET from Javascript

Taking the new Chromium WebView2 Control for a Spin in .NET - Part 1



This is Part 1 of a two part article that gives an overview of the new WebView2 Web browser control that is based on Edge Chromium. In Part 1 I look at the basics of what's needed to run the control using the WebView runtime, and how to get the control embedded and configured to use for basic HTML tasks. In Part 2 I look at interaction between the .NET application and WebBrowser and Javascript.

Window Activation Headaches in WPF



Ran into a problem with properly activating a WPF when launching from Explorer and indirectly trying to activate an already running instance 'from within itself'. It seems simple, but windows focus-stealing restrictions can cause problems with actually getting focus into an application window. Here's how.

Wrestling with Clipboard Images in WPF



Retrieving images from the clipboard with WPF seems so simple, but once you get into it you'll find that there are lots of problems with reliable image retrieval that works for all images. In this post I talk about the different issues you're likely to run into and one hacky but flexible solution to better image support by selectively sniffing image formats and using different clipboard retrievals based on the image format.

WPF Window Closing Errors



I've recently had a large uptick of errors in my Markdown Monster logs that complain about `Cannot set Visibility to Visible or call Show, ShowDialog, Close, or WindowInteropHelper.EnsureHandle while a Window is closing`. This error can crop up with nested or parallel window closing operations, which might not always be obvious when they happen. I'll show some of the issues and the hacky by easy to implement work around.

First Steps in porting Markdown Monster WPF App to .NET Core 3.0



I spent a good part of the day today getting Markdown Monster to run on .NET Core 3.0 and in this post I packaged up my notes into a lengthy post with how went through this process. It wasn't exactly quick to make this happen but MM has a few peculiarities that made this process a little bit more trying than it could have been. I'll summarize some thoughts at the end on both the process and the relevance of this process.

WPF Hanging in Infinite Rendering Loop



Ran into a nasty WPF bug this week with Markdown Monster that caused MM to hang during startup in certain scenarios. Several users reported issues that I could not duplicate until I started playing around with my screen resolution and scaling. An obscure but insidious WPF bug can cause an application to go into an infinite loop which effectively locks up the application's UI and the app overall. Here's more info on what the problem is and how to work around it.

Creating a WPF ItemSource Length Filter Converter



In this short post I show you you can create a simple Value Converter to limit the max number of items in an ItemsSource value binding in WPF.

WPF Slow Window Loading due to Invalid SpellChecking Dictionaries



I ran into a nasty problem with spell checking on WPF, which caused any form that uses spell checking to load extremely slow. It turns out the problem was caused by errant entries in the global Windows dictionary key in the registry. This post describes the problem and how to find and fix your global Windows dictionary settings.

Updating Windows Applications and Installers for non-Admin Installation



I recently updated Markdown Monster to run as a non-admin installation even when running the full installer. There have been many requests for this functionality and in this post I describe several of the updates required in order to make this work.

JavaScript Debugging in a Web Browser Control with Visual Studio



Debugging a Web Browser Control embedded in a Windows application can be a bear because there's no obvious way to debug the the JavaScript code or HTML DOM/CSS inside of the application. Although the Web Browser uses the Internet Explorer Engine for HTML rendering and JavaScript execution and provides most of the engine features, the Debugger and F12 are not part of that. As it turns out you can use Visual Studio to hook up a script debugger and provide a rich debugging experience with the full IE debugger, Console and even a DOM/CSS Explorer. In this post I show how.

Debouncing and Throttling Dispatcher Events



In UI applications it's not uncommon for a number of UI events to fire more events than your application can handle. In order to limit the number of events it's often a good idea to throttle or 'debounce' events so that only a single event is fire for a given period. In this post I describe a Dispatcher based implementation for debouncing and throttling UI events in WPF applications.

Dragging and Dropping Images and Files into the Web Browser Control



Dragging content into the Web Browser control and capturing the content dropped can be tricky. The Web Browser Control is based on Internet Explorer and is actually an ActiveX control hosted inside of a container and because of that is difficult to deal with. In this post I describe how you can get around this issue and still capture images and files dropped on the control and handle the drop operations.

Debugging the Web Browser Control with FireBug



If you need to debug JavaScript code or layout issues in a Web Browser control inside of a Windows desktop application, you've probably found that the experience sucks. Although Internet Explorer on which the control is based suppports rich developer tools, those are not available in the Web Browser control. Enter an oldie but goodie: FireBug which is an embeddable Console implementation that provides a lot of the features that you find in modern browser developer tools and with a couple of lines of html you can add this debugger into your application.

Video Rendering Issues for WPF Windows



Recently I ran into a few reports of black screen of death rendering of Markdown Monster when starting up from a very few users of the application. They reported the screen just shows black, while actually being responsive to moving and showing menus etc. Also moving to another screen often fixes the problem. It turns out this is a hardware related issue with WPF with certain video hardware/monitor combinations. In this post I describe the problem and the workaround to get the application to render properly even on compromised hardware.

Faking out the .NET Runtime Version



I've been struggling with DPI Scaling issues in WPF in Markdown Monster and .NET 4.6.2 has a few fixes that address the problems I've been working on. However, requiring 4.6.2 is a problem due to lowish adoption rates and skittishness about installing new versions of .NET. In this post I show a little hack that allows me to compile my app to .NET 4.6.2 but don't require user to have that version installed so those that have it can take advantage of the updates.

Downgrading a .NET Applications from 64 bit to 32 bit for the WebBrowser Control



Recently while working on Markdown Monster I ran into some odd crashes and behaviors when interacting with the Web Browser control in this WPF application. It turns out that some of these inconsistent behaviors are apparently caused by running hte application in 64 bit mode. Switching to 32 bit mode has made the application and Web Browser interaction much more responsive and has stopped the nagging unexplainable crashes. In this post I look at 32 and 64 bit applications in .NET and outline some of the issues I ran into and how I fixed the problem by switching to building a 32 bit app.

WPF Rendering DUCE.Channel Crashes due to Image Loading



I ran into a nasty WPF rendering bug that affected only a few select machines. Rendering problems in WPF can be terribly difificult to debug because there often is no additional information on what failed and the exceptions that occur are not trappable but fall back to application wide error handling. In this post I describe a specific failure caused by a 'bad' image WPF can't deal with and how I tracked it down and fixed it.

Capturing Zoom Operations in the WPF Web Browser Control



If you need to capture Zoom operations in the Web Browser control - either to avoid letting hte user zoom or to capture the zoom operation and take action on it - you need to dig into the Web Browser's DOM events to capture the scroll wheel and key events. In this post I describe how you can do just that by looking at an application that captures scrolling and rather than zooming adjusts the font size of the content.

Detecting and Setting Zoom Level in the WPF WebBrowser Control



Zoom level detection in the Web Browser control is a pain and in this article I describe one approach I used to both capture the current Zoom level in order to adjust font sizes, and then also explicitly set the Zoom level in the Web Browser control of a WPF application.

Creating Single Instance WPF Applications that open multiple Files



If you're building document centric applications, Singleton style EXE applications are pretty common. Rather than creating new windows for each opened file, a more common scenario is to open new tabs in a single instance. In this post I'll describe how to create a WPF application that allows only a single instance to run and passes command line arguments passed in secondary instances to the primary instance and I'll describe some pitfalls that you might have to watch out for.

WPF Localization Guidance Paper Posted on CodePlex



I’m happy to announce that my WPF Localization paper went live a couple of days ago on CodePlex. This document provides an overview of localization in .NET in general as well as specifically to WPF. It covers localization with the rigid LocBaml approach, as well as using Resx resources for binding using markup extensions and attached properties respectively.

WPF Bindings and CurrentCulture Formatting



WPF doesn't apply the CurrentCulture to bindings by default, which is a little... unexpected to say the least. As it turns out there's an easy solution to this problem, but it does require using code to apply the culture specifically in every document.

Getting the App’s Startup Assembly in WPF Designer?



I've run into a vexing problem with a Markup Extension for localization. In this extension I have the need to get a reference to the parent application (the WPF EXE basically) inside the WPF designer/Blend. Due to the runtime environment of the designer I've not been able to make this work short of running the markup extension in the same assembly as the main application.

Resx and BAML Resources in WPF



Resource loading in WPF applications that mix BAML and Resx resources can be very confusing as BAML resources require that all BAML resources are stored in external satellite assemblies.

Rendering a WPF Container to Bitmap



One of WPF's nicer features is its ability to render any visual into a bitmap easily, and so I thought I'd create a simple little tool that would create rounded corner bitmap bars with transparent backgrounds. It's actually quite easy to do, but I ran into a few pitfalls and inconsistencies that make WPF coding oh so much fun.

Hosting a WCF Service in a non-.NET Client



I'm still screwing around Web Connection and trying out a quick proof of concept tonight and thought I'd share a few steps on how to host a WCF in a non .NET client via COM Interop client like Visual FoxPro. This article discusses WCF server and client creation in general terms and in addition covers the interop issues to make it work in these clients.

WPF: How hard could it be to get a SelectedItemTemplate?



Here's a fun one to do in WPF. Say you have a ListBox or ListView that is databound and you want to get at the content of the data template used for binding of the items in the list. In my case I want to trigger an animation when the item is selected to indicate the change. It's quite easy to get a...

Fumblings and Thoughts on WPF DataBinding



So I spent the evening today experimenting with databinding in WPF. Overall I'm very excited about that data binding capabilities in WPF which finally has produced a powerful and reasonably user friendly way to do data binding of just about any type to anything else. WPF makes this easily available...

WPF Experiments: Changing a Live Writer Plug-in to use WPF



Ok so I had a little free time on my hands this weekend and was looking for a simple something to use WPF on. A few weeks back I'd been playing with an Justin Brown's Amazon book plug in for Live Writer, which is part of the Windows Live Writer Plugins on CodePlex. Back when I first looked at his...

Beyond HTML: Rich Internet Applications



Rich Internet Applications (RIA) is a term used to describe non HTML based, low impact Internet applications. RIA’s typically run in the browser (although they don’t have to) and get their data from the Web server over HTTP. One of the big selling points of RIA’s is that they provide many of the...
West Wind  © Rick Strahl, West Wind Technologies, 2005 - 2024