1

I have a class defined like this (i have removed some code lines, like null checks, to keep it short):

public sealed class CodeTheme : INotifyPropertyChanged
{
    public void Reload()
    {
        PropertyChanged(sender, new PropertyChangedEventArgs("MyProperty"));
    }

    public Thickness MyProperty
    {
        get
        {
            return new Thickness():
        }
    }

    public event PropertyChangedEventHandler PropertyChanged;
}

I am registering the codetheme class in XAML like this, using the StandardStyles.xaml

<me:CodeTheme x:Key="Theming" />

Than, i am using it in varios templates and styles, like so:

<Style x:Key="Style1" TargetType="ListViewItem">
    <Setter Property="HorizontalContentAlignment" Value="Stretch" />
    <Setter Property="VerticalContentAlignment" Value="Stretch" />
    <Setter Property="Margin" Value="{Binding Source={StaticResource Theming}, Path=MyProperty}" />
</Style>

I then i might call the Reload method at any time in the program, the first time in the overwritten OnLaunched event of the App.xaml.cs

This works for colors, strings and other Thickness values when i assign them in DataTemplate. However when i use it in a Style, i get the following error as soon as i fire the PropertyChanged event:

System.UnauthorizedAccessException was unhandled by user code HResult=-2147024891 Message=Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)) Source=System StackTrace: (i have removed this) InnerException:

I have tried to raise the event by RunAsync from the Window.Current.Dispatcher but that didnt change anything. What am i doing wrong here?

4

1 回答 1

1

Bindings were not supported in Style Setters last time I checked.

于 2012-12-06T16:51:56.107 回答