WPF - Image Source - not within expected range

In my XAML and on creation, I get the following exception:

Error 3 The value "colorpick.png" cannot be assigned to the "Source" property. The value is not in the expected range.

Here's the XAML:

"Source =" colorpick.png "is underlined.

One of the few things I could find about this is the below blog post: http://nickeandersson.blogs.com/blog/2008/06/wpf-image-and-v.html

colorpick.png is set to Build action = resource.

Any hints would be greatly appreciated!

Here's all the xaml:

<UserControl x:Class="MyApp.Controls.ColorSettings"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:MyApp">
    <Grid>
        <StackPanel>
          <ScrollViewer>
           <ListView Name="lvColors" MinHeight="100" MinWidth="300" SelectionChanged="lvColors_SelectionChanged">
                <ListView.ItemContainerStyleSelector>
                    <local:ColorSettingsStyleSelector/>
                </ListView.ItemContainerStyleSelector>
                <ListView.View>
                <GridView>
                    <GridViewColumn Header="Level" DisplayMemberBinding="{Binding Level}"></GridViewColumn>

                    </GridView>
            </ListView.View>
        </ListView>
        </ScrollViewer>
            <StackPanel Orientation="Horizontal" Name="spColorPicker" Visibility="Hidden">
                <Image Source="colorpick.png" Width="200" Height="200" MouseLeftButtonDown="Image_MouseLeftButtonDown" MouseMove="wheel_MouseMove" Name="wheel"/>
                <Rectangle Width="200" Height="200" Name="rectDisplay"/>
            </StackPanel>
        </StackPanel>

    </Grid>
</UserControl>

      

+1


a source to share


2 answers


I think you might need to use the WPF Resource File Pack URI syntax .



+3


a source


Try changing it to

<Image Source="/AssemblyName;component/colorpick.png" ...

      



where AssemblyName is the name of your assembly (component is a literal).

Suppose colorpick.png is in the root of your project if it (for example) uses a folder with images /AssemblyName;component/images/colorpick.png

+3


a source







All Articles