What is the best way to share data between a WPF window and its User Controls?

前端 未结 3 630
死守一世寂寞
死守一世寂寞 2021-01-05 09:46

WPF can be infuriating sometimes.

I have a fairly simple application that consists of a single main window that contains a tab control and several tabs. I did not l

3条回答
  •  死守一世寂寞
    2021-01-05 10:23

    You could put the settings object into a static property in a wrapper class (SettingsHolder in this example and reference it application wide via

    in XAML:

    {Binding SettingName, Source={x:Static local:SettingsHolder.Settings}}
    

    with local being the namespace your SettingsHolder class is in.

    in Code:

    var x = SettingsHolder.Settings.SettingName;
    SettingsHolder.Settings.SettingName = x;
    

提交回复
热议问题