Я довольно новичок в xaml и пытаюсь связать свойства из пользовательского класса, чтобы применить систему тем, но xaml пытается связать, прежде чем мои свойства будут установлены. Я также не могу заставить INotifyPropertyChanged работать с моим пользовательским классом, и я хотел бы позволить пользователям переключать темы на лету.
мой (упрощенный) код:
public class clsThemeObjects : DependencyObject, ComponentModel.INotifyPropertyChanged
{
public event PropertyChangedEventHandler System.ComponentModel.INotifyPropertyChanged.PropertyChanged;
public delegate void PropertyChangedEventHandler(object sender, System.ComponentModel.PropertyChangedEventArgs e);
public SolidColorBrush ButtonTextBrush {
get {
return (SolidColorBrush)GetValue(ButtonTextBrushProperty);
}
set {
SetValue(ButtonTextBrushProperty, value);
if (PropertyChanged != null) {
PropertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs("ButtonTextBrush"));
}
}
}
public static readonly DependencyProperty ButtonTextBrushProperty = DependencyProperty.Register("ButtonTextBrush", typeof(SolidColorBrush), typeof(cls_Globals), new PropertyMetadata(null));
}
static class Globals
{
static ThemeObjects = new clsThemeObjects();
public Globals()
{
ApplyTheme();
}
Public static void ApplyTheme()
{
ThemeObjects.ButtonTextBrush = new SolidColorBrush(Colors.Black);
}
}
в моем xaml я делаю это:
<Button Style="{StaticResource ButtonBlankStyle}" Grid.Row="2" Name="btnAddModules" HorizontalContentAlignment="Stretch">
<Border BorderThickness="2" BorderBrush="Black" CornerRadius="2" Margin="0,4">
<TextBlock Text="Test" Foreground="{Binding Path=ButtonTextBrush, Source={StaticResource ThemeObjects}}" />
</Border>
</Button>
Я думал, что использование iNotifyPropertyChanged будет работать, но это не так, может кто-нибудь помочь, пожалуйста?
Спасибо