0
之前绑定我是很新的XAML和我试图从一个自定义的类绑定属性应用主题系统,但XAML尝试我的属性被设置之前进行绑定。我也无法让INotifyPropertyChanged与我的自定义类一起工作,我希望允许用户即时切换主题。Silverlight的努力属性设置
我(简化)代码:
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的会工作,但它没有,任何人都可以帮助请?
感谢