locked
WPF resource dictionary RRS feed

  • Question

  • Hi,
      I am using a set of WPF controls that are in a dll that are hosted in a Winforms application. I want to use styles to set the properties for the TextBox, Button etc. Where do I define these so that all the controls in my dll can get these styles by default without addiitonal code for each control?
     
    The way I am hosting the WPF control is to use a Winforms Form to host the WPF control.

    thanks
    Wednesday, July 2, 2008 3:20 PM

Answers

  • The other possible way is declaring resource as following
    <ResourceDictionary Source="/ComponentLibraryName;Styles.xaml"/>
    Usually you might require it when configuring "Generic.xaml" within your WPF component libraries or addressing styles from another library.
    Kind regards, Denis (GMT +02:00)
    • Proposed as answer by Denis Vuyka Friday, July 4, 2008 3:49 PM
    • Marked as answer by Marco Zhou Wednesday, July 9, 2008 10:51 AM
    • Marked as answer by Marco Zhou Wednesday, July 9, 2008 10:51 AM
    • Marked as answer by Marco Zhou Wednesday, July 9, 2008 10:51 AM
    Friday, July 4, 2008 3:49 PM

All replies

  • You would need to add a new resource dictionary into your solution (.XAML file) and then add a reference from this resource dictionary into your usercontrols xaml like below.

    <UserControl.Resources> 
            <ResourceDictionary> 
                <ResourceDictionary.MergedDictionaries> 
                    <ResourceDictionary Source="Styles.xaml"/>  
                </ResourceDictionary.MergedDictionaries> 
            </ResourceDictionary> 
        </UserControl.Resources> 
    Friday, July 4, 2008 7:47 AM
  • The other possible way is declaring resource as following
    <ResourceDictionary Source="/ComponentLibraryName;Styles.xaml"/>
    Usually you might require it when configuring "Generic.xaml" within your WPF component libraries or addressing styles from another library.
    Kind regards, Denis (GMT +02:00)
    • Proposed as answer by Denis Vuyka Friday, July 4, 2008 3:49 PM
    • Marked as answer by Marco Zhou Wednesday, July 9, 2008 10:51 AM
    • Marked as answer by Marco Zhou Wednesday, July 9, 2008 10:51 AM
    • Marked as answer by Marco Zhou Wednesday, July 9, 2008 10:51 AM
    Friday, July 4, 2008 3:49 PM