Avatar of akohan
akohan
 asked on

xaml error message

hello group,

I am working on a xaml file (WPF) and keep running into this error message.

{"'Provide value on 'System.Windows.StaticResourceExtension' threw an exception.' Line number '6' and line position '9'."}


<Window x:Class="myproject.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        WindowStartupLocation="CenterScreen"
        Title="MainWindow" 
        Height="850" Width="1000">

Open in new window


What is causing this? I'm using default xml name spaces. I will appreciate it if you let me know.


Thanks,
amit
C#Microsoft Development.NET Programming

Avatar of undefined
Last Comment
akohan

8/22/2022 - Mon
unmeshdave

please provide complete xaml.
akohan

ASKER
Sure. here is the xaml file I'm getting error as:
 
'Provide value on 'System.Windows.StaticResourceExtension' threw an exception.' Line number '22' and line position '10'.

<Window x:Class="akohan.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:s="clr-namespace:akohan"
        xmlns:c="clr-namespace:akohan.Controls"
        WindowStartupLocation="CenterScreen"
        Title="MainWindow" 
        Height="850" Width="1000">
   
    <Window.Resources>
        <ContextMenu x:Key="DesignerCanvasContextMenu">
            <MenuItem Header="Paste" Command="{x:Static ApplicationCommands.Paste}">
                <MenuItem.Icon>
                    <Image Source="/akohan;component/Resources/image/Paste.png" Width="16"/>
                </MenuItem.Icon>
            </MenuItem>
            <MenuItem Header="Select All" Command="{x:Static s:DesignerCanvas.SelectAll}"/> 
        </ContextMenu>
    </Window.Resources>

    <Grid Margin="10">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>

        <ContentControl Content="{StaticResource MyToolbar}"/>

            <Grid Grid.Row="1" Margin="0,10,0,0">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="265"/>
                <ColumnDefinition/>
            </Grid.ColumnDefinitions>
            <!-- Toolbox -->
            <StackPanel Grid.Column="0" Margin="0,0,5,0">
                <Expander Header="set 1" IsExpanded="True"/>
                <Expander Header="set 2" Content="{StaticResource ShapeStencils}" IsExpanded="True"/>
            </StackPanel>
            <!-- GridSplitter-->
            <GridSplitter Focusable="False" Width="2" Background="LightGray" VerticalAlignment="Stretch" HorizontalAlignment="Right"/>
            <!-- Designer -->
            <GroupBox Header="Canvas" Grid.Column="1" Margin="3,0,0,0">
                <ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
                    <s:DesignerCanvas Focusable="True" x:Name="MyDesigner" Background="{StaticResource windowBackgroundBrush}" Margin="10" FocusVisualStyle="{x:Null}" ContextMenu="{StaticResource DesignerCanvasContextMenu}" />
                    
                </ScrollViewer>
            </GroupBox>
            
            
        </Grid>
    </Grid>
</Window>

Open in new window

Aaron Jabamani

For static resource, you should define it before reference to it (dynamic resource doesn't have this limitation). you could place the resources "MyToolbar" in the Resources section of the Window (Window.xaml) or the application (App.xaml).
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
akohan

ASKER
Thanks Apeter,

Can you tell me how I can do that? any link that discusses it? something that will walk me step by step.


Thanks.
ASKER CERTIFIED SOLUTION
Aaron Jabamani

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
akohan

ASKER
Thanks!