Interested
Interested

Reputation: 11

XamlParseException when binding to static resource

There is an example implementation of a custom authorization for WPF on the Microsoft website.

After you add resources in the App.xaml:

<Application x:Class="WpfApplication.App"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Application.Resources>
    <Style x:Key="BackgroundStyle" TargetType="TextBlock">
        <Setter Property="Background">
            <Setter.Value>
                <LinearGradientBrush StartPoint="0, 0" 
                                     EndPoint="0, 0.5" 
                                     SpreadMethod="Reflect">
                    <GradientStop Color="Gray" Offset="1"/>
                    <GradientStop Color="White" Offset="0"/>
                </LinearGradientBrush>
            </Setter.Value>
        </Setter>
        <Setter Property="Margin" Value="2,0,2,0"/>
        <Setter Property="Width" Value="200"/>
    </Style>
</Application.Resources>

Add this resource in any window:

<Window x:Class="Authorization_WPF.AdminWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="AdminWindow" Height="300" Width="300">
    <Grid>
        <TextBlock Style="{StaticResource BackgroundStyle}" Text="This window is only accessible for admninistrators..."/>
    </Grid>
</Window>

Get an error:

The first step of processing an exception of type ' System.Windows.Markup.XamlParseException" PresentationFramework.dll

More information: "giving the value for "System.Windows.StaticResourceExtension" threw an exception.": the row number "6" and the position in the string "10".

How to fix it?

Upvotes: 1

Views: 1445

Answers (1)

Damir Beylkhanov
Damir Beylkhanov

Reputation: 545

remove comments near your references in App.xaml:

.... xaml/presentation This link is external to TechNet Wiki. It will open in a new window. "

... 2006/xaml This link is external to TechNet Wiki. It will open in a new window. "

Must be:

<Application x:Class="Authorization_WPF.AdminWindow"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         StartupUri="AdminWindow.xaml">

Upvotes: 1

Related Questions