Issue with dependency properties on Visual Studio "Properties" window

Simos Sigma 1 Reputation point
2023-03-22T10:45:19.0333333+00:00

I am working on a custom WPF Window and I am facing an issue with a DependencyProperty.

Here is an example of my base class MyCustomWindow.cs:

public class MyCustomWindow : Window
{
    public static DependencyProperty UseTitleBarProperty = DependencyProperty.Register("UseTitleBar", typeof(bool), typeof(MyCustomWindow), new PropertyMetadata(true));
    
    [Category("CUSTOM")]
    [Description("...")]
    public bool UseTitleBar
    {
        get { return (bool)GetValue(UseTitleBarProperty); }
        set { SetValue(UseTitleBarProperty, value); }
    }
}

An example of my extended class MainWindow.xaml.cs:

public partial class MainWindow : MyCustomWindow
{
    public MainWindow()
    {
        InitializeComponent();
    }
}

And an example of my MainWindow.xaml:

<mlc:MyCustomWindow 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"
                    xmlns:local="clr-namespace:MyApp"
                    mc:Ignorable="d"
                    
                    xmlns:mlc="clr-namespace:MyLib.Controls;assembly=MyLib"
                    
                    Height="640"
                    Title="MainWindow"
                    Width="840"
                    WindowStartupLocation="CenterScreen"
                    
                    UseTitleBar="False">
    <Grid>
    </Grid>
</mlc:MyCustomWindow>

Programmatically it "works". But I am facing an issue on "Properties" window of Visual Studio. When I try to change the value of UseTitleBar property from there (properties window) it always displayed as true and the value doesn't change inside the code.

5Ls6F[1]

Even if I change UseTitleBar value from MainWindow.xaml code, on Properties window displays as true!!! Is this a VS issue or am I doing something wrong?

Thank you for your time!!!

Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,667 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,205 questions
{count} votes