Unable to find static resource in runtime even while designer can see it
Posted
by xumix
on Stack Overflow
See other posts from Stack Overflow
or by xumix
Published on 2010-05-27T08:10:09Z
Indexed on
2010/05/27
8:11 UTC
Read the original article
Hit count: 491
So i have this markup:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:Werp.MigrationHelper">
<Style TargetType="{x:Type UserControl}" x:Key="WizardPageControl" x:Name="WizardPageControl">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type UserControl}">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="10" />
<ColumnDefinition Width="475" />
<ColumnDefinition Width="10" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="10" />
<RowDefinition Height="410"/>
<RowDefinition Height="50" />
<RowDefinition Height="10" />
</Grid.RowDefinitions>
<StackPanel Orientation="Vertical" Name="MainContent" Grid.Row="1" Grid.Column="1">
<ContentPresenter Content="{TemplateBinding Content}"/>
</StackPanel>
<StackPanel Grid.Column="1" Grid.Row="2" Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Bottom" Margin="0,0,0,10" Height="30">
<Button Name="BackButton" Width="50" xml:space="preserve">< _Back</Button>
<Button Name="NextButton" Width="50" Margin="10,0,0,0" xml:space="preserve" IsDefault="True">_Next ></Button>
<Button Name="CancelButton" Width="50" Margin="10,0,0,0" IsCancel="True">_Cancel</Button>
<Button Name="FinishButton" IsEnabled="True" Width="50" Margin="10,0,0,0">_Finish</Button>
</StackPanel>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>
<Application xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Resources\WizardPageControl.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
<UserControl x:Class="Werp.MigrationHelper.WizardPageControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="clr-namespace:Werp.MigrationHelper" mc:Ignorable="d">
</UserControl>
Then I try to use it:
<PageFunction
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:Werp.MigrationHelper"
x:Class="Werp.MigrationHelper.WizardPage1"
x:TypeArguments="local:WizardResult"
KeepAlive="True"
WindowTitle="Wizard Page 1"
>
<local:WizardPageControl Style="{StaticResource ResourceKey=WizardPageControl}">
<local:WizardPageControl.Content>
qweqweqweqweq
</local:WizardPageControl.Content>
</local:WizardPageControl>
</PageFunction>
The VS designer show everything Ok, but in runtime i get
System.Windows.Markup.XamlParseException occurred
Message='Provide value on 'System.Windows.StaticResourceExtension' threw an exception.' Line number '4' and line position '5'.
Source=PresentationFramework
LineNumber=4
LinePosition=5
StackTrace:
at System.Windows.Markup.WpfXamlLoader.Load(XamlReader xamlReader, IXamlObjectWriterFactory writerFactory, Boolean skipJournaledProperties, Object rootObject, XamlObjectWriterSettings settings, Uri baseUri)
at System.Windows.Markup.WpfXamlLoader.LoadBaml(XamlReader xamlReader, Boolean skipJournaledProperties, Object rootObject, XamlAccessLevel accessLevel, Uri baseUri)
at System.Windows.Markup.XamlReader.LoadBaml(Stream stream, ParserContext parserContext, Object parent, Boolean closeStream)
at System.Windows.Application.LoadComponent(Object component, Uri resourceLocator)
at Werp.MigrationHelper.WizardPage1.InitializeComponent() in d:\Home\Docs\Visual Studio 2008\Projects\csharp\wizardpage1.xaml:line 1
at Werp.MigrationHelper.WizardPage1..ctor(WizardData wizardData) in D:\home\Docs\Visual Studio 2008\Projects\csharp\WizardPage1.xaml.cs:line 12
InnerException:
Message=Cannot find resource named 'WizardPageControl'. Resource names are case sensitive.
Source=PresentationFramework
StackTrace:
at System.Windows.StaticResourceExtension.ProvideValue(IServiceProvider serviceProvider)
at MS.Internal.Xaml.Runtime.ClrObjectRuntime.CallProvideValue(MarkupExtension me, IServiceProvider serviceProvider)
InnerException:
Whats the prolem??
© Stack Overflow or respective owner