Serializing a resource dictionary throws an exception

6 posts, 0 answers
  1. Zoran
    Zoran avatar
    1 posts
    Member since:
    Mar 2014

    Posted 22 Jan 2015 Link to this post

    Hello,

    I have a trouble Saving a resource dictionary which uses Telerik.Windows.Controls assembly. Telerik.Windows.Controls.

    The exception thrown:

    An unhandled exception of type 'System.NotSupportedException' occurred in System.dll

    Additional information: 'Office2013ResourceKeyTypeConverter' is unable to convert 'Telerik.Windows.Controls.Office2013ResourceKey' to 'System.Windows.Markup.MarkupExtension'.

    Part of xaml that's causing the problem:

    <Grid>
                    <Path
                        Stretch="Fill"
                        Fill="{telerik1:Office2013Resource ResourceKey=ValidationBrush}"
                        HorizontalAlignment="Left"
                        VerticalAlignment="Top"
                        SnapsToDevicePixels="True"/>
                    <Border Background="{telerik1:Office2013Resource ResourceKey=ValidationBrush}" Margin="5 0 0 0" Padding="1">
                        <ContentPresenter
                            Content="{Binding Error}"
                            TextBlock.Foreground="{telerik1:Office2013Resource ResourceKey=MainBrush}"
                            Margin="4 2"
                            TextBlock.FontSize="15"
                             />
                    </Border>
                </Grid>
                <ContentControl/>
            </Grid>

    and namespace mapping:

    xmlns:telerik1="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls"

    I load this resource dictionary with

    var myDict = Application.LoadComponent(new Uri(packUri, UriKind.Relative)) as ResourceDictionary;

    and then try to save it with:

    System.Windows.Markup.XamlWriter.Save(myDict);

    And that's when the exception is thrown.

    Compiler tooltip: "Local property 'ResourceKey' can only be applied to types that are derived from ThemeResourceExtension`1"

    I've checked it, and Office2013ResourceExtension derives from ThemeResourceExtension`1.

    What might be the problem here?
  2. Evgenia
    Admin
    Evgenia avatar
    1406 posts

    Posted 26 Jan 2015 Link to this post

    Hello Zoran,

    The exception is caused by the fact that telerik1 namespace does not exis in this style file. In fact Office2013Resource as well as all themes that support mark-up extensions (Windows8, Windows8Touch, Office2013 and VisualStudio2013) reside in telerik namespace. Since we are referencing different assemblies in our controls style files, our xaml preprocessor renames them so that there are no collisions. In your case telerik1 points to Controls assembly and Controls namespace. Please replace telerik1 with telerik or controls (the latter was previously declared as namespace declaration) and everything should work as expected.
    As for serializing ResourceDictionary - in fact XamlWriter.Save method has some known limitations stated in msdn documentation. Why do you need to do this with serialization and deserialization? Why don't you create a custom style - do the needed modifications there and apply it implicitly? Do you really need to load and save the whole resource dictionary? Any further information on the topic will help us better understand your scenario and assist you.

    Regards,
    Evgenia
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  3. UI for WPF is Visual Studio 2017 Ready
  4. Andreas
    Andreas avatar
    4 posts
    Member since:
    Apr 2015

    Posted 15 May 2015 in reply to Evgenia Link to this post

    Hi!

    I also have issues with this. From what I understand, I should change the name somewhere? But what is it that I should change? I have attached a picture of the Telerik.Windows.Controls.xaml. Could you please tell me what I should change, and to what?

     

    Thanks in advance.

  5. Evgenia
    Admin
    Evgenia avatar
    1406 posts

    Posted 18 May 2015 Link to this post

    Hi Andreas,

    In your case telerik1 points to Controls assembly and Controls namespace. Please replace telerik1 with telerik (the universal schema) or controls and everything should work as expected. 

     Why we declare telerik and telerik1 in our style files? - Since we are referencing styles from different assemblies in our style files, our xaml preprocessor renames the namespaces so that there are no collisions - it appends 1 after telerik.

    We apologize for any inconveniences this may have caused. We will do our best to improve the way our  style files are being preprocessed in future.

    Regards,
    Evgenia
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  6. Andreas
    Andreas avatar
    4 posts
    Member since:
    Apr 2015

    Posted 19 May 2015 in reply to Evgenia Link to this post

    Hi!

     

    Thanks for the quick response. I removed the telerik1 namespace and changed all references to telerik1 to telerik. But now I get a strange error. See attached image. Is that anything you know of?

  7. Evgenia
    Admin
    Evgenia avatar
    1406 posts

    Posted 21 May 2015 Link to this post

    Hello Andreas,

    We are unaware of such errors in our Telerik.Windows.Controls.Input.xaml implicit style file. Have you made any changes to it except the change of the namespace? Could you please send us a sample runnable version of your project where this reproduces so that we can inspect it locally and further assist you? For the purpose you should open a new support thread and add the sample code there as archive attachment.

    Regards,
    Evgenia
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top
UI for WPF is Visual Studio 2017 Ready