0% found this document useful (0 votes)
81 views6 pages

Writing Custom Control With New WPF XAML Designer

Uploaded by

Leonardo Forero
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
81 views6 pages

Writing Custom Control With New WPF XAML Designer

Uploaded by

Leonardo Forero
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 6
Writing Custom Control with New WPF XAML Designer 4. Stanko Milogev JS 10 Feb 2023 CPOL How to either migrate to the new XAML designer extensibility or write WPF custom control extensibility model based on designtools.dll. The current WPF XAML Designer for NET Framework has been deprecated and will be replaced with a new WPF XAML Designer for .NET Framework, based on the same architecture used for the WPF XAML Designer for .NET (.NET Core). Download host (demo) application - 18.6 KB Download example - 430.9 KB Introduction ‘Simplified example of making a custom button with the new WPF .NET Framework control extensibility model based on .designtools.dll extension in .NET7 (Core) using a new WPF XAML Designer. With this example, | want to simplify example provided by Microsoft, and put focus only on main things when someone wants to create custom control extensibility model based on .designtools.all. Background Since Visual Studio 2022, the WPF .NET Framework control extensibility model based on .design.dll and Microsoft.Windows Design. extensibility is no longer supported. You can read more about it in New WPF XAML Designer for NET Framework, or in XAML designer extensibility migration. This article is mostly copy / paste from already mentioned Microsoft sample, and the article. In order to try to. stick to the Keep It Simple principle, | will not copy paste more information from Microsoft. Using the Code This example was made using Visual Studio 2022. It will not work in previous versions of Visual Studio and there will be one class library (NET Framework) project and one WPF Custom Control Library needed: 1. CustomControlLibrary.WpfCore - WPF Custom Control Library 2, CustomControlLibrary.WpfCore.DesignTools - Please notice that extension .DesignTools is necessary, and that the project is in NET Framework 4.8. This DLL will be later copied in Design subfolder. 3. Rebuild and create package from CustomControlLibrary.WpfCore (right mouse button -> pack) 4. At the end, NuGet packet should be installed in host application, in order to see the result: cs ees aig ied Appearance fees ea) cs oF and to populate ToolBox. To test the result, you can use also CustomControlLibrary WpfCore. Host application. * DesignTools.dll files should be either in the same folder like main application, or like in my case, in the same Design subfolder, like Microsoft explained here. That means that in main folder, | have CustomControllibrary. WpfCore.dll and in Design subfolder CustomControlLibrary. WpfCore.DesignTools.dll, like in my example. CustomControlLibrary.WpfCore 1. Create WPF Custom Control Library and change csproj to look like: XML «Project Sdk="Microsoft.NET.Sdk"> net7.@-windows enable true Tools Lib Design\CustomControlLibrary .WpfCore.DesignTools.d11 Here notice: XML. Design\CustomControl Library .WpfCore.DesignTools.d1l this line, Lam packing DesignTools.dll into Design subfolder. 2. Rename CustomControl1 to MyButton, also in Generic.xaml. 3, Add VisualStudioToolsManifest.xml. MyButton ce using System.Windows; using System.Windows.Controls; namespace CustomControlLibrary .Wpfcore { public class MyButton : Button { public static DependencyProperty RenderActiveProperty; public bool RenderActive t get { return (bool)GetValue(RenderActiveProperty); } set { SetValue(RenderActiveProperty, value); } } static MyButton() t RenderActiveProperty = DependencyProperty.Register("RenderActive", ‘typeof (bool), ‘typeof (MyButton), new PropertyMetadata(false)); y public string Test { get; set; } VisualStudioToolsManifest This file is needed to populate ToolBox like Microsoft explained here, After installing NuGet paket in the host application, you should see something like: Prete ren tole eoa XML

You might also like