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;
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
{
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)
{
if (File.Exists(inFileName))
{
try
{
using (var fs = new FileStream(inFileName, FileMode.Open, FileAccess.Read, FileShare.Read))
{
var dic = (ResourceDictionary)XamlReader.Load(fs);
Resources.MergedDictionaries.Clear();
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