I am working on "Visual Studio 2022" and using ".NET Framework 4.8.1" I am making a derived control. A "ToolTip" in my case and I am facing an issue with its custom dependency properties. Every time I change the value of a custom dependency property to any other than default value, after I run my app and close it, into the "Property Editor" of "Visual Studio" the field is empty!!!
What I have tried:
This is a code example of my derived "ToolTip" control:
namespace MyControlLibrary.Controls
{
public class MyToolTip : ToolTip
{
public enum IconTypes
{
Custom,
Error,
Information,
None,
Question,
Warning,
}
public static readonly DependencyProperty IconTypeProperty =
DependencyProperty.Register(nameof(IconType),
typeof(IconTypes),
typeof(MyToolTip),
new FrameworkPropertyMetadata(IconTypes.None,
new PropertyChangedCallback(OnIconTypeChanged)));
[Category("MyCategory")]
[Description("...")]
public IconTypes IconType
{
get { return (IconTypes)GetValue(IconTypeProperty); }
set { SetValue(IconTypeProperty, value); }
}
private static void OnIconTypeChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
{
}
static MyToolTip()
{
}
public MyToolTip()
{
}
}
}
And this is how I am testing it into "MainWindow":
<Window
x:Class="MyApp.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
xmlns:local="clr-namespace:MyApp"
xmlns:MyControls="clr-namespace:MyControlLibrary.Controls;assembly=MyControlLibrary"
Title="MainWindow"
Height="450"
Width="800"
WindowStartupLocation="CenterScreen">
<Grid>
<Button
Content="MyToolTip Test"
Cursor="Hand"
Padding="9"
HorizontalAlignment="Center"
VerticalAlignment="Center">
<Button.ToolTip>
<MyControls:MyToolTip>
<StackPanel>
<TextBlock Text="MyToolTip Test!!!"/>
</StackPanel>
</MyControls:MyToolTip>
</Button.ToolTip>
</Button>
</Grid>
</Window>
Also [
^]here is a VS solution which reproduces the issue!!!
Any idea why is this happening?