How do I get a property in wpf that references a property in a static class to implement notifications?

CodingNinja 96 Reputation points
2021-10-27T12:12:09.983+00:00

Why CurrentRepositoryUrl does not receive the change when ConfigManager.RepositoryConfig.IsConfigured changes.

XAML
<TextBlock Text="{Binding CurrentRepositoryUrl, Mode="OneWay"}"


CSharp
// Code-Behind
[AddINotifyPropertyChangedInterface] // Fody AOP.
public partial class MainWindow : Window
{
    public string CurrentRepositoryUrl
    {
        get
        {
            if (!ConfigManager.RepositoryConfig.IsConfigured)
            {
                Dispatcher.Invoke(() => hypCurrentRepository.ToolTip = "Go to Config Page.”");

                return "Repo Not Configured.";
            }

            Dispatcher.Invoke(() => hypCurrentRepository.ToolTip = "View Repo...");

            return ConfigManager.RepositoryConfig.RepositoryUrl;
        }
   }
}

public static ConfigManager
{
    public static RepositoryConfig RepositoryConfig { get; private set; }
}

[AddINotifyPropertyChangedInterface] // Fody AOP.
public RepositoryConfig
{
    public bool IsConfigured { get; set; }
    public string RepositoryUrl { get; set; }
}
Developer technologies | Windows Presentation Foundation
Developer technologies | XAML
{count} votes

2 answers

Sort by: Most helpful
  1. CodingNinja 96 Reputation points
    2021-10-28T11:38:27.98+00:00

    I seem to have guessed the problem, if I bind directly to ConfigManager.RepositoryConfig.RepositoryUrl using the x:Static syntax, then it updates automatically, if I reference it in the Code-Behind, it doesn't.


  2. CodingNinja 96 Reputation points
    2021-10-29T12:32:11.727+00:00

    I don't mind using x:Static syntax, my Code-Behind properties don't have to refer to ConfigManager.
    If I do need to, I will reset the value of the property rather than referencing it using a read-only property.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.