none
How can I add style resources to a Word Application AddIn for WPF Windows? RRS feed

  • Question

  • Hi there

    I am trying to style WPF Windows for a Word Application Add-In in Visual Studio 2010. Rather than styling every Window with copy/paste styles, I would like to add a single file containing all styles (Styles.xaml) and then refer to its styles whenever needed.

    In a traditional WPF project, I am doing this in App.xaml. Does anybody know how to do that in a Word Application Add-In?

    Any help is highly appreciated.

    Kind regards

    Nora

    Wednesday, August 22, 2012 11:18 AM

Answers

  • Hello everybody

    I found it out on my own. It was a rather stupid mistake -- the xaml file containing the styles must start and end with the ResourceDictionary tag, not with the Window tag. Example:

    <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
      <Style TargetType="{x:Type DataGridRow}">
        <Style.Triggers>
          <Trigger Property="IsMouseOver" Value="True">
            <Setter Property="Background" Value="#FFF0F0F0" />
          </Trigger>
        </Style.Triggers>
      </Style>
    </ResourceDictionary>
    

    Hope this helps other people!

    Kind regards

    Nora

    • Marked as answer by nora.sailer Friday, November 9, 2012 4:20 PM
    Friday, November 9, 2012 4:20 PM

All replies

  • Hi nora.sailer,

    Thanks for posting in the MSDN Forum.

    As far as I know that app.xaml exists in WpfApplication project or WpfBrowserApplication or sliverlight Application. And in Word add-in I think we will not use this file. And I never see WPF window can be embedded in Word add-in. You are able to create WPF User Control in Word add-in, however you will not be allow to create a WPF window in it.

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us

    Thursday, August 23, 2012 2:57 AM
    Moderator
  • Hi Tom

    Thanks for your reply.

    Actually, one can create WPF windows. Visual Studio does not offer the template for it, but you can simply rename the root tag "UserControl" to "Window". Works perfectly well.

    But even if this was not possible, I still would want to be able to style UserControls centrally, not individually.

    Kind regards

    Nora

    Thursday, August 23, 2012 4:01 PM
  • Hi Nora,

    I suggest you do it like what you will do in the WPF application. There tell me where you get the problem.

    T.X.


    志异征诛,三让两家王朝
    功同开辟,一桮万古江南

    Saturday, August 25, 2012 2:57 AM
  • Hi T.X.

    I am referring to a ResourceDictionary in the WPF Window like this:

      <Window.Resources>
        <ResourceDictionary>
          <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="pack://application:,,,/Octoiur;component/Views/Styles.xaml" />
          </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
      </Window.Resources>

    The ResourceDictionary lies in the same subfolder "Views" as all the Windows (relative to the root of the Assembly named Octoiur) and is called Styles.xaml.

    When I am trying to load that Window, the Xaml parsing stops at the Source=... line.

    Exception (XamlParseException): 'Set property 'System.Windows.ResourceDictionary.Source' threw an exception.

    Inner Exception (InvalidOperationException): ResourceDictionary LoadFrom operation failed with URI 'pack://application:,,,/Octoiur;component/Views/Styles.xaml'

    Exactly the same exceptions are thrown when I replace the pack source by the file source:

    <ResourceDictionary Source="Styles.xaml" />
    

    Oh, and I tried different build actions on Styles.xaml, such as Page or Resource. This did not help either.

    Kind regards

    Nora

    • Edited by nora.sailer Monday, August 27, 2012 2:24 PM
    Monday, August 27, 2012 2:23 PM
  • Hi nora,

    I will involve some experts into this issue to see whether they can help you. There might be some time delay, thanks for you patience.

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us

    Tuesday, August 28, 2012 7:16 AM
    Moderator
  • Hi Tom

    That's fine, I'm not in a hurry (yet), as styling does work when applied directly in the Windows concerned.

    I'v been thinking: Maybe there's something wrong with the ResourceDictionary, not with calling it? Maybe these experts could also tell us in what such files (xaml and xaml.cs) differ from the usual App.xaml/App.xaml.cs of native WPF applications?

    Kind regards, and thanks for your help

    Nora

    Wednesday, August 29, 2012 6:44 AM
  • Hello Nora,

    Because of its complexity your question falls into the paid support category which requires a more in-depth level of support. If the support engineer determines that the issue is the result of a bug the service request will be a no-charge case and you won't be charged. Please visit the below link to see the various paid support options that are available to better meet your needs. http://support.microsoft.com/default.aspx?id=fh;en-us;offerprophone

    Thanks,

    Sreerenj G Nair

    Thursday, October 11, 2012 11:37 AM
  • Hello everybody

    I found it out on my own. It was a rather stupid mistake -- the xaml file containing the styles must start and end with the ResourceDictionary tag, not with the Window tag. Example:

    <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
      <Style TargetType="{x:Type DataGridRow}">
        <Style.Triggers>
          <Trigger Property="IsMouseOver" Value="True">
            <Setter Property="Background" Value="#FFF0F0F0" />
          </Trigger>
        </Style.Triggers>
      </Style>
    </ResourceDictionary>
    

    Hope this helps other people!

    Kind regards

    Nora

    • Marked as answer by nora.sailer Friday, November 9, 2012 4:20 PM
    Friday, November 9, 2012 4:20 PM