Loc in style

Feb 26, 2013 at 5:52 PM
Edited Feb 26, 2013 at 5:53 PM

I have a problem with defining images in style for custom control. Following code works only until the language is changed...
<Style x:Key="MediaFilesLocationButtonImageStyle" TargetType="{x:Type Controls:ImageButton}" BasedOn="{StaticResource {x:Type Controls:ImageButton}}">
    <Setter Property="NormalImage" Value="{lex:Loc Key=Assembly:Dict:Film_48x48, Converter={StaticResource bitmapSourceTypeConverter}}" />
    <Setter Property="HoverImage" Value="{lex:Loc Key=Assembly:Dict:FilmPressed_48x48, Converter={StaticResource bitmapSourceTypeConverter}}" />
    <Setter Property="PressedImage" Value="{lex:Loc Key=Assembly:Dict:FilmPressed_48x48, Converter={StaticResource bitmapSourceTypeConverter}}" />
    <Setter Property="DisabledImage" Value="{lex:Loc Key=Assembly:Dict:FilmDisabled_48x48, Converter={StaticResource bitmapSourceTypeConverter}}" />
When I try to change the language I get "After a 'SetterBase' is in use (sealed), it cannot be modified." exception on following line:
/// <summary>
/// This method is called when the resource somehow changed.
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="e">The event arguments.</param>
public void ResourceChanged(DependencyObject sender, DictionaryEventArgs e)
    if (sender == null)
        --> UpdateNewValue(); <--
Solution for now is to set the values together with the control declaration where it works... Nevertheless, it would be nice to have an option to define them in the style.
Feb 28, 2013 at 6:32 PM

this looks like it is not solvable. As the error message tells you, the Setter is in between the LocExtension and the target WPF object and cannot be modified after creation (similar to Binding). Please use another way to achieve your desired effect.

Best regards,