0

suppose I wish to allow users be able to customize the application interface (for example, change font family or font size, etc.). Default style settings are saved into a stylesheet, registered as a ResourceDictionary in Application.xaml file. Suppose that default Font Family is set to Tahoma

    <FontFamily x:Key="FontFamilyDefault">Tahoma</FontFamily>
    ...
    <Style TargetType="{x:Type TextBox}">
    <Setter Property="FontFamily" Value="{DynamicResource FontFamilyDefault}"/>
    ...
    </Style>

Suppose now that user can set a Font Family via a ViewModel property (FontFamily). How can I force the dynamic resource FontFamilyDefault to be set to the FontFamily property value? thanks

H.B.
  • 166,899
  • 29
  • 327
  • 400
calacausi
  • 23
  • 5
  • [Here's one option](http://stackoverflow.com/a/6229849/424129). I guess you'd be dynamically generating a new theme resource dictionary with the user preferences. Alternatively, I think it'd work to have a "theme viewmodel" as a resource in App.xaml, and use its properties everywhere as `FontFamily="{Binding FontFamily, Source={DynamicResource ThemeVM}}"`. C# code in the user prefs dialog (or whatever) can use FindResource to get the actual instance to modify. – 15ee8f99-57ff-4f92-890c-b56153 Oct 25 '16 at 13:57
  • s/DynamicResource/StaticResource/. – 15ee8f99-57ff-4f92-890c-b56153 Oct 25 '16 at 14:06
  • ed, the solution suggested could be good for me. but I can not understand how I could change my style after ViewModel has saved and committed changes into database. – calacausi Nov 02 '16 at 14:18
  • I can't parse that, sorry. What does it mean in concrete programming terms to "change my style after ViewModel has saved"? Are you referring to the option I linked to, or the alterative I suggested in my comment? There are two solutions there. "The solution" gives me no hint as to which you're referring to. – 15ee8f99-57ff-4f92-890c-b56153 Nov 02 '16 at 14:37
  • sorry for the delay. at last, i found a solution. user customizes his style settings (eg: change default font or color, background image, etc.), then saves style changes into DB. after changes are saved, ViewModel set some "StyleChanged" property to True, so that the "OnPropertyChange" event of the bound TextBox item on View is fired. finally, a code-behind procedure implements the style changes as you suggested. thank you – calacausi Nov 22 '16 at 10:29

0 Answers0