Click here to Skip to main content
15,877,446 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
I'm working on a small project where I introduced an image button as a user control.
The funny thing is, that it just works fine, but I'm getting an error message inside my MainWindow.xam:
'Invalid URI: The format of the URI could not be determined'
The image property including the path information is marked as invalid (Image="\Images\icon_HMI_NewTask.png").
But as I said, pressing F5 just works fine and I'm getting my button with the proper text and image.

But I would like to avoid any issues with it which I don't see right now.

Please help!

Adding a UserControl Button to my MainPage:
<userControls:LargeMenuButton Label="New Decision" Image="\Images\icon_HMI_NewDeci.png" />

The control consists of the XAML part:
<UserControl x:Class="OpenPointList.UserControls.LargeMenuButton"
             d:DesignHeight="100" d:DesignWidth="100">
    <StackPanel Orientation="Horizontal" x:Name="LayoutRoot" HorizontalAlignment="Center">
        <Button Height="52" >
            <StackPanel Orientation="Vertical" Width="Auto">
                <Image Source="{Binding Path=Image, ElementName=myLargeMenuButton}" Height="32" Width="32"/>
                <TextBlock Foreground="Black" FontSize="12" Text="{Binding Path=Label}" TextAlignment="Center" />

And here is the CS part:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace OpenPointList.UserControls
    /// <summary>
    /// Interaction logic for LargeMenuButton.xaml
    /// </summary>
    public partial class LargeMenuButton : UserControl
        #region Fields

        public static readonly DependencyProperty LabelProperty = DependencyProperty.Register("Label", typeof(string), typeof(LargeMenuButton), new PropertyMetadata(""));
        public static readonly DependencyProperty ImageProperty = DependencyProperty.Register("Image", typeof(ImageSource), typeof(LargeMenuButton), new PropertyMetadata(null));


        #region Constructor

        /// <summary>
        /// Default Constructor
        /// </summary>
       public LargeMenuButton()

            LayoutRoot.DataContext = this;


        #region Custom Control properties

        /// <summary>
        /// Set and get for the text which shall be displayed on the button
        /// </summary>
        public string Label
            get { return (String)GetValue(LabelProperty); }
            set { SetValue(LabelProperty, value); }

        /// <summary>
        /// Sets or gets the Image source for the icon which shall be displayed on the button
        /// </summary>
        public ImageSource Image
            get { return (ImageSource)GetValue(ImageProperty); }
            set { SetValue(ImageProperty, value); }

Agent__007 29-Dec-14 6:16am    
Did you try "Pack URIs"? link:

Basically, try either:
Carpi_1968 29-Dec-14 6:29am    
You are perfect!
That was the key to get it resolved.

1 solution

Adding this answer as per the OP's response to my comment above:

Did you try Pack URIs[^]?

Basically, try either:


That should do the trick.
Share this answer
Carpi_1968 30-Dec-14 3:49am    
I tried your proposals and both of them are solving my issue.

Thanks again for your proper help.
Agent__007 30-Dec-14 3:56am    
You are most welcome. I am glad it helped. :)

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