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"
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"
Name="myLargeMenuButton"
mc:Ignorable="d"
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" />
</StackPanel>
</Button>
</StackPanel>
</UserControl>
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
{
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));
#endregion
#region Constructor
public LargeMenuButton()
{
InitializeComponent();
LayoutRoot.DataContext = this;
}
#endregion
#region Custom Control properties
public string Label
{
get { return (String)GetValue(LabelProperty); }
set { SetValue(LabelProperty, value); }
}
public ImageSource Image
{
get { return (ImageSource)GetValue(ImageProperty); }
set { SetValue(ImageProperty, value); }
}
#endregion
}
}