PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, May 6, 2022

[FIXED] How to set up the image source path properly in XAML

 May 06, 2022     image, wpf, xaml     No comments   

Issue

i'm trying to put a close button image on my newly created tabs for my app, but i just can't seem to get the right path. This is how i've tried inputting it (code is from MainWindow.xaml):

<TabControl Margin="10,26,10,10" ItemsSource="{Binding FileTabs}">
            <TabControl.ItemTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal">
                        <TextBlock Text="{Binding FileTabName}" />
                        <Button Name="closeTabBtn">
                            <Image Width="20" Height="20" Source="/Images/button-close.jpg" />
                        </Button>
                    </StackPanel>
                </DataTemplate>
            </TabControl.ItemTemplate>

This is my project structure:

enter image description here

What is the correct path for the image source property since i'm kind of new at this ?


Solution

You should set the Build Action of the image file to Resource in Visual Studio and try with a pack URI if your relative path still doesn't work:

Source="pack://application:,,,/Images/button-close.png"


Answered By - mm8
Answer Checked By - Candace Johnson (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing