Click here to Skip to main content
15,898,588 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi friends ,

can any body helps me to resolve error given below:Probably the issue might be linked with x:Name in the resource dictionary definition . what i Can do to overcome that

System.Windows.Markup.XamlParseException occurred

Exception

  Message='Could not register named object. Names not supported under ResourceDictionary scope.' Line number '107' and line position '26'.

  Source=PresentationFramework

  LineNumber=107

  LinePosition=26

  StackTrace:

       at System.Windows.Markup.XamlReader.RewrapException(Exception e, IXamlLineInfo lineInfo, Uri baseUri)

       at System.Windows.Markup.WpfXamlLoader.Load(XamlReader xamlReader, IXamlObjectWriterFactory writerFactory, Boolean skipJournaledProperties, Object rootObject, XamlObjectWriterSettings settings, Uri baseUri)

       at System.Windows.Markup.WpfXamlLoader.Load(XamlReader xamlReader, Boolean skipJournaledProperties, Uri baseUri)

       at System.Windows.Markup.XamlReader.Load(XamlReader xamlReader, ParserContext parserContext)

       at System.Windows.Markup.XamlReader.Load(XmlReader reader, ParserContext parserContext, XamlParseMode parseMode)

       at System.Windows.Markup.XamlReader.Load(Stream stream, ParserContext parserContext)

       at System.Windows.Markup.XamlReader.Load(Stream stream)

       at DynamicResource_dictionary.App.LoadStyleDictionaryFromFile(String inFileName) in D:\projectC#200X\DynamicResource dictionary\DynamicResource dictionary\app.xaml.cs:line 42

  InnerException: System.NotSupportedException

       Message=Names not supported under ResourceDictionary scope.

       Source=PresentationFramework

       StackTrace:

            at System.Windows.ResourceDictionary.RegisterName(String name, Object scopedElement)

            at System.Xaml.NameScopeDictionary.RegisterName(String name, Object scopedElement)

            at System.Xaml.XamlObjectWriter.RegisterName(ObjectWriterContext ctx, String name, Object inst, XamlType xamlType, INameScope nameScope, INameScope parentNameScope, Boolean isRoot)

       InnerException:


the relevent codes which throws the exception is given below;

C#
App.xaml.cs

using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Windows;
using System.Threading;
using System.IO;
using System.Windows.Markup;


namespace DynamicResource_dictionary
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : Application
    {
        public static App Instance;
        public static String Directory;
        private String _DefaultStyle = "Style2.xaml";


        public App()
        {
            Instance = this;
            Directory = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
            string stringsFile = Path.Combine(Directory, "Styles", _DefaultStyle);
            LoadStyleDictionaryFromFile(stringsFile);
        }

        public void LoadStyleDictionaryFromFile(string inFileName)
        {
           // MessageBox.Show(File.Exists(inFileName).ToString());
            if (File.Exists(inFileName))
            {
                try
                {
                    using (var fs = new FileStream(inFileName, FileMode.Open, FileAccess.Read, FileShare.Read))
                    {
                        // Read in ResourceDictionary File
                        var dic = (ResourceDictionary)XamlReader.Load(fs);
                        // Clear any previous dictionaries loaded
                        Resources.MergedDictionaries.Clear();
                        // Add in newly loaded Resource Dictionary
                        Resources.MergedDictionaries.Add(dic);
                    }
                }
                catch
                {
                }
            }

        }
    }
}

ResourceDictionary files :Style2.xaml
<pre lang="HTML">

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

    
    <LinearGradientBrush x:Key="DarkBackground" StartPoint="0,0" EndPoint="1,1">

        <GradientStop Offset="0" Color="#FF333344"></GradientStop>

        <GradientStop Offset="1" Color="#FF666677"></GradientStop>

    </LinearGradientBrush>



    <LinearGradientBrush x:Key="LightBackground" StartPoint="0,0" EndPoint="1,1">

        <GradientStop Offset="0" Color="#FF9999AA"></GradientStop>

        <GradientStop Offset="1" Color="#FFDDDDFF"></GradientStop>

    </LinearGradientBrush>

    <!-- CONTROL BACKGROUND -->

    <SolidColorBrush x:Key="BaseColor" Color="#99000000"></SolidColorBrush>

    <!-- GLASS EFFECT -->

    <LinearGradientBrush x:Key="GlassFX" StartPoint=".5,0" EndPoint=".5,.5">

        <GradientStop Offset="1" Color="#33DDDDDD"></GradientStop>

        <GradientStop Offset="1" Color="#33000000"></GradientStop>

    </LinearGradientBrush>

    <LinearGradientBrush x:Key="GlassFXDisabled" StartPoint=".5,0" EndPoint=".5,.5">

        <GradientStop Offset="1" Color="#33BBBBBB"></GradientStop>

        <GradientStop Offset="1" Color="#11000000"></GradientStop>

    </LinearGradientBrush>

    <!-- GLOW EFFECT -->

    <RadialGradientBrush x:Key="GlowFX" GradientOrigin=".5,1" Center=".5,1">

        <GradientStop Offset="0" Color="#990000FF"></GradientStop>

        <GradientStop Offset=".5" Color="#660000DD"></GradientStop>

        <GradientStop Offset="1" Color="#33000000"></GradientStop>

    </RadialGradientBrush>

    <RadialGradientBrush x:Key="GlowFXPressed" GradientOrigin=".5,1" Center=".5,1">

        <GradientStop Offset="0" Color="#660000CC"></GradientStop>

        <GradientStop Offset="1.2" Color="#33FFFFFF"></GradientStop>

    </RadialGradientBrush>

    <LinearGradientBrush x:Key="GlowFXRowPressed">

        <GradientStop Offset="0" Color="#660000FF"></GradientStop>

        <GradientStop Offset=".7" Color="#660000AA"></GradientStop>

        <GradientStop Offset="1" Color="#66000000"></GradientStop>

    </LinearGradientBrush>

    <LinearGradientBrush x:Key="GlowFXProgress">

        <GradientStop Offset="0" Color="#660099FF"></GradientStop>

        <GradientStop Offset=".99" Color="#660022AA"></GradientStop>

        <GradientStop Offset="1" Color="#00000000"></GradientStop>

    </LinearGradientBrush>

    <LinearGradientBrush x:Key="GlowFXProgressAnimated" MappingMode="RelativeToBoundingBox">

        <GradientStop Offset="0" Color="#00000000"></GradientStop>

        <GradientStop Offset=".50" Color="#660099FF"></GradientStop>

        <GradientStop Offset="1" Color="#00000000"></GradientStop>

    </LinearGradientBrush>

    <LinearGradientBrush x:Key="GlowFXTabSelected" StartPoint=".5,1" EndPoint=".5,0">

        <GradientStop Offset="0" Color="#33DDDDDD"></GradientStop>

        <GradientStop Offset="1" Color="#332222FF"></GradientStop>

    </LinearGradientBrush>

    <!-- GLOW ANIMATION -->

    <Storyboard x:Key="GlowOut">

        <DoubleAnimation x:Name="AnimGlowOut" BeginTime="00:00:00" Storyboard.TargetName="GlowRectangle" Duration="00:00:00.250" From="1" To="0" Storyboard.TargetProperty="Opacity"></DoubleAnimation>

    </Storyboard>

    <Storyboard x:Key="GlowIn">

        <DoubleAnimation x:Name="AnimGlow" BeginTime="00:00:00" Storyboard.TargetName="GlowRectangle" Duration="00:00:00.250" From="0" To="1" Storyboard.TargetProperty="Opacity">
        </DoubleAnimation>

    </Storyboard>

    <!-- GROUPBOX -->

    


    <Style x:Key="txtBox" TargetType="TextBox" >

        <Setter Property="OverridesDefaultStyle" Value="True" />

        <Setter Property="SnapsToDevicePixels" Value="True" />

        <Setter Property="Foreground" Value="White" />

        <Setter Property="Template">

            <Setter.Value>

                <ControlTemplate x:Name="tmpltTextBox">

                    <Grid>

                        <Rectangle x:Name="BaseRectangle" Fill="{StaticResource BaseColor}" RadiusX="3" RadiusY="3"></Rectangle>

                        <Rectangle x:Name="GlassRectangle" RadiusX="5" RadiusY="5" Fill="{StaticResource GlassFX}"></Rectangle>

                        <Rectangle x:Name="GlowRectangle" RadiusX="5" RadiusY="5" Opacity="0" Fill="{StaticResource GlowFX}"></Rectangle>

                        <Border x:Name="BorderIntern" Opacity="1" BorderBrush="Black" BorderThickness="2" CornerRadius="3" Margin="1,1,-1,-1"></Border>

                        <Border x:Name="BorderExtern" Opacity="1" BorderBrush="#FF333333" BorderThickness="1" CornerRadius="3"></Border>

                        <ScrollViewer x:Name="PART_ContentHost" Opacity=".7" Content="{Binding Path=Content, RelativeSource={RelativeSource TemplatedParent}}" HorizontalAlignment="{Binding Path=HorizontalAlignment, RelativeSource={RelativeSource TemplatedParent}}" VerticalAlignment="{Binding Path=VerticalAlignment, RelativeSource={RelativeSource TemplatedParent}}" Width="{Binding Path=Width, RelativeSource={RelativeSource TemplatedParent}}" Height="{Binding Path=Height, RelativeSource={RelativeSource TemplatedParent}}"></ScrollViewer>

                    </Grid>

                    <ControlTemplate.Triggers>

                        <EventTrigger RoutedEvent="TextBox.LostFocus">

                            <EventTrigger.Actions>
                                <BeginStoryboard Storyboard="{StaticResource GlowOut}"></BeginStoryboard>

                            </EventTrigger.Actions>

                        </EventTrigger>

                        <EventTrigger RoutedEvent="TextBox.GotFocus">

                            <EventTrigger.Actions>

                                <BeginStoryboard Storyboard="{StaticResource GlowIn}"></BeginStoryboard>

                            </EventTrigger.Actions>

                        </EventTrigger>

                        <Trigger Property="IsEnabled" Value="False">

                            <Setter Property="Opacity" TargetName="PART_ContentHost" Value=".3"></Setter>

                            <Setter Property="Opacity" TargetName="BorderExtern" Value=".5"></Setter>

                            <Setter Property="Fill" TargetName="GlassRectangle" Value="{StaticResource GlassFXDisabled}"></Setter>

                        </Trigger>

                    </ControlTemplate.Triggers>

                </ControlTemplate>

            </Setter.Value>

        </Setter>

    </Style>



</ResourceDictionary>
Thanks in advance
Posted
Updated 23-Feb-12 7:28am
v2
Comments
Manfred Rudolf Bihy 23-Feb-12 13:30pm    
I'm sorry, but this is a code dump that no one will try to unravel. You would need to point out the lines which seem to contain the error as indicated by the exception.
[no name] 23-Feb-12 13:45pm    
I observed one fact . (I no longer want to ask question in this forum. No body are paid for answers. in fact I too not a professional developer. I am only an enthusiast who learn himself, I too not paid for my questions.) if I give less details people will blame that my questions are less informative. if I give all information people will say it is a code dumb; what a fun. for more precise in this case the exception occur due to x:Name in the resource dictionary.
XtErMiNaToR102 7-Mar-12 1:58am    
If you are not prepared to strip down your code snippet through the process of elimination and present the problematic code to clarify your problem, then this is not the forum you are looking for.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900