WPF
33 TopicsWPF application becomes unresponsive after plugging/ unplugging USB device supporting pen events
I've run across an issue on Windows 10 and 11 where WPF apps seem to become unresponsive when unplugging or plugging in a USB device that registers as an input device that can receive touch/stylus events. This can be seen by creating a basic WPF app in Visual Studio, running it, and then adding/removing one of these devices. I used Spy++ to see which messages the app was receiving. I saw a number of messages I was expecting to see - WM_DEVICECHANGE, WM_POINTERDEVICECHANGE, as well as 0x02C8 or 0x02C9 (WM_TABLET_ADDED or WM_TABLET_DELETED, respectively). However, after this, thousands (or sometimes tens of thousands) of messages were sent to a window belonging to the app that is at (0,0) with dimensions 0x0. Its caption is "OLEChannelWnd". The messages are mostly the same: They're all posted to the window The message ID is 0x0400 (WM_USER + 0) The wParam is always the same (0x0000BABE) The lParam varies each time I restart the WPF app, but they seem to settle on a small number of values - for example, the last time I tried this, I saw 0x05D08BB0 4-6 times, then 0x0D1B8E98 a dozen or more times, then 0x0D1B7B90 several times, and so on. During these messages, the app would become unresponsive for as long as these messages were posted. This could take upwards of 5- 10 minutes before recovering, and sometimes would result in a crash from the app running out of memory. After doing research online, I found some posts that talked about a possible issue in the PenThreadWorker thread - that it could be running into some kind of deadlock when initializing certain objects. I also found several posts that mentioned disabling the stylus & touch events by setting "Switch.System.Windows.Input.Stylus.DisableStylusAndTouchSupport". I can add this to the app.config for my app as follows: <runtime> <AppContextSwitchOverrides value="Switch.System.Windows.Input.Stylus.DisableStylusAndTouchSupport=true" /> </runtime> or, equivalently, I can do the following during application startup: AppContext.SetSwitch("Switch.System.Windows.Input.Stylus.DisableStylusAndTouchSupport", true); This does fix the issue - I don't see these WM_USER messages being sent to the app, and as such the app becomes immediately responsive once the device is plugged/unplugged. However, one of the WPF apps that I'm working with (i.e. not the simple test app) needs to process tablet events, so this setting can't be used there. Furthermore, it can only be set either in app.config or during application startup - any calls to it after that are ignored. I've tried this with .NET 4.5.1, .NET 4.6 (which is required to use the code-based method) as well as .NET 4.8.1, but in all cases I see this same result. As mentioned, I know this isn't an issue unique to my app since I'm able to reproduce this issue by creating a basic WPF app and following the same steps. Additionally, I observed the same issue with other test applications I've found online while trying to troubleshoot this issue. Interestingly, I have observed this within Microsoft's own Visual Studios 2017 (which is what I'm using for development) and have found a few other threads online from other people running into the same problem with their apps. I have also tried updating to later Visual Studios versions for development of my app, but this doesn't solve the issue either. Finally, I followed this post from Microsoft regarding https://learn.microsoft.com/en-us/dotnet/desktop/wpf/advanced/disable-the-realtimestylus-for-wpf-applications and still was unable to fix the issue.32Views0likes0CommentsWPF App on Windows Server (RDP) – Error Sometimes When Opening New Window
Hi everyone, I have a WPF app that runs from a network drive. It works fine on Windows 11 at the office. But when users run it through Remote Desktop on a Windows Server 2019 virtual machine (using the exact same .exe from the same network drive location), some of them get an error when opening a new window. The app starts normally, but the error happens only when opening another window — and not for every user. Strangely, the next day the same user can open the app and use it normally again without changing anything. Has anyone seen this before or know how to fix it? I’ve also attached: A screenshot of the error message The function that causes the error Thanks a lot!71Views0likes0CommentsHow to decouple views from view models using CommunityToolKit.mvvm
I am writing my first MVVM app using CommunityTookit.mvvm. I am using as reference the Micrsoft Learning link https://learn.microsoft.com/en-us/dotnet/communitytoolkit/mvvm/ioc. This link shows the setting of the viewmodel to the view DataContext using the following statement in the view's .cs file: this.DataContext = App.Current.Services.GetService<ContactsViewModel>(); The problem with this as I see it is that this statement couples the view to the view model, in this case ContactsViewModel. This means that in another app the view cannot be used with another viewmodel without modifying the view, i.e. changing ContactsViewModel above to another viewmodel type. This means that the view cannot be stored in a common library that is shared among different apps. There is a C# Corner example with the older MVVM TookKit that solved this problem using a ViewModelLocator class. This project is found https://www.c-sharpcorner.com/article/getting-started-with-mvvm-light-with-wpf/. The solution is to put the following code in the view's XAML file: DataContext="{Binding Main, Source={StaticResource Locator}}" The source object for the binding is found by looking for a ResourceDictionary that is in the scope of the view and which has an entry whose key is "Locator". In app.xaml which by definition is always in scope we have: <Application.Resources> <ResourceDictionary> <vm:ViewModelLocator x:Key="Locator" d:IsDataSource="True" /> </ResourceDictionary> </Application.Resources> The Dictionary element with key "Locator" is an object of type ViewModelLocator. In the ViewModelLocator class there is a Main property that always returns an instance of MainViewModel: public MainViewModel Main { get { return ServiceLocator.Current.GetInstance<MainViewModel>(); } } In our example, the view's DataContext binds to the Main property of the ViewModelLocator object. The value of the Main property is a MainViewModel object and this becomes the DataContext of the view. We can now in a different app re-use the view without changing it. All we have to do in the next app is to create a different ViewModelLocator object that specifies a different viewmodel in its Main property. The view is now completely decoupled from the view model. My question is, how would we de-couple the view from the view model using the CommunityToolkit.Mvvm? Do we also use a ViewModelLocator class? Is there a more elegant way with dependency injection? Another question I have is, suppose we want to use in one app the same view twice with different view models. An example of where we might want to do this is if we had a view that displayed a chart. It is conceivable that we might want to have more than one view model display its data using the same chart view. I cannot see how to do this in either of the above Microsoft or C# Corner examples.122Views1like0CommentsDeeply Disappointed with Copilot+
At the company where I work, we purchased a Copilot+ laptop with the hope of being able to use the new Windows AI libraries, such as Windows.AI.TextRecognition. The library works well, but we are unable to process more than 2 documents concurrently, which severely limits our document processing capacity. We also feel misled, as we did not see any mention anywhere of such a limitation regarding the library. I would appreciate it if a Microsoft representative could confirm whether this limitation exists and, if not, let us know if there is any way to increase this limit. Thank you in advance.96Views0likes1CommentMicrosoft Store Service APIs v9.0 publisherQuery - Uniquely identifying user subscription
I'm working on a WPF app that will be published to the Windows Store. It supports an add-on monthly subscription. That subscription comes with consumable credits for using my app. Per user, per month, I want to track the user's credit balance. I'm using the following Microsoft Store Service API endpoint to get the user's subscription details from my backend service: collections.mp.microsoft.com/v9.0/collections/publisherQuery Here's an example response (with identifying information replaced with fake data): { "ContinuationToken": null, "Items": [ { "RecurrenceId": null, "AcquiredDate": "2025-04-28T20:34:54.2761169+00:00", "AcquisitionType": "Recurring", "EndDate": "2025-05-31T00:00:00+00:00", "Id": "11111111111122222222222333333333", "ModifiedDate": "2025-04-28T20:34:54.277868+00:00", "ProductId": "AAAAAAAAAAAA", "ProductKind": "Durable", "Quantity": 1, "SatisfiedByProductIds": [], "SkuId": "0020", "StartDate": "2025-04-28T00:00:00+00:00", "Status": "Active", "Tags": [], "TransactionId": "11111111-1111-1111-1111-111111111111", "TrialData": { "IsInTrialPeriod": false, "IsTrial": false, "TrialTimeRemaining": "00:00:00" } } ] } Based on this response, I can see there's an active subscription, with the start and end date. I'm trying to determine whether anything in this response uniquely represents this user's subscription for this month, and could be used as my own identifier when tracking user credit consumption. It looks like Id and TransactionId are the only two potential candidates, but I don't know for certain that I can count on either of these for this scenario. Can anyone confirm? Is there some altogether better approach I should be using?43Views0likes0CommentsMYSYS2 Installation Guide for Cross-Compilation on Visual Studio 2017, 2019, 2022, and WSL2
Use Notepad to create this file on your desktop or another folder: https://sourceforge.net/projects/openscriptlab/files/IDE_Compilation/MYSYS2.txt/download MYSYS2 Paths: Use Notepad to create this file on your desktop or another folder: https://sourceforge.net/projects/openscriptlab/files/IDE_Compilation/MYSYS2_Path_Win.txt/download NOTE: This folder layout, which can be easily edited, was generated with a batch file that utilizes the default configuration that comes with the UI-based setup program / installer. Use Notepad to create this file on your desktop or another folder: https://sourceforge.net/projects/openscriptlab/files/IDE_Compilation/Generate_MYSYS2_Folder_Paths_Win.bat/download215Views0likes0CommentsAppx Package Leaves Behind DLLs on Uninstall (Pipeline vs Local Debug Build)
Hello everyone, I'm encountering an issue with my WPF application that's packaged as an appx file for sideloading. I'm new to this area, so any guidance or suggestions would be greatly appreciated. Issue Overview: Pipeline Build (Release): The appx package generated in our build pipeline (with code signing) installs and runs as expected. However, after uninstalling the app, certain DLLs remain in the Windows app folder. Local Build (Debug): When I generate the appx package locally using Visual Studio in Debug mode and perform the install/uninstall on the same device, the DLLs are cleaned up properly. I didn't changed any property in the appxmanifest.xml other than the publisher name and the certificate.56Views0likes0CommentsAutomation testing for ToastNotifications
I am testing a WPF application, and I want to access a button on a Toast Notification. I am using the Microsoft UI Automation framework, but cannot locate the Notification window in the RawView tree or from the RootElement (.Find*). However tools like Inspect do find the Notification window. => what is the issue here? I could use NotificationListener, but that doesn't give access to any button. Correct me if I'm wrong. So how can I access those Toast Notifications with MS UI Automation?96Views0likes0CommentsHow can I find CPE of dll in .NET?
For example, System.IO.Packaging 8.0.0 hav weakness. https://www.nuget.org/packages/System.IO.Packaging/8.0.0 I have Vulnerability Management tool, I can receive notice of the weakness by registering CPE. I want to obtain CPE of System.IO.Packaging, but where is it available from? Thanks70Views0likes0CommentsBest design software for personal project
I'm starting to develop a WPF software, with some components like Ribbon Menu and Docking Layouts, but I find an intuitive design, better organized and cleaner, an interface that does not seem to be WinForms. Does anyone know of any components or frameworks that can do this type of design? My cordial greetings.145Views0likes0Comments