Why does my Bitmap Image show in the designer but not in the .EXE

177 views Asked by At

I have a ressource dictionary in a control library to state my bitmap image. key= Refresh -M

UriSource="/Resources/Icons/Basic/refresh-100.png"

You can see in the code below that its instanciated in a button viewbox.

Since my styles dictionary are appart form the main project i made "WPFStyle_Ascendecies.xaml" that include all of them so I only have to include this one in app.xaml

/------Images-----\

View Designer

App.exe

/------#See last button-----\

<!--Left Top to DownMenu -->
        <StackPanel  Background="DimGray" Grid.Row="0" Grid.RowSpan="3" Grid.Column="0" Grid.ColumnSpan="2">



            <TextBlock Text="{Binding Title}"  Padding="0,14,0,0" Height="56" Margin="0,0,0,0" FontSize="18"  Background="Black" Foreground="White" TextAlignment="Center" />
            <Button x:Name="Homepage"          Content="Home Page" Height="30" Margin="0,0,0,1" Click="Homepage_Click"                  />
            <Button x:Name="Clients"           Content="Clients"   Height="30" Margin="0,0,0,1" Click="Clients_Click"                   />
            <Button                            Content="Hello"     Height="30" Margin="0,0,0,1"                                         />
            <Button  Height="30" Margin="0,0,0,1" >
                <Viewbox>
                    <Image Source="{StaticResource Refresh -M}"/>
                </Viewbox>
            </Button>


        </StackPanel>


        <!--PagesPresenterFrame-->
        <Frame x:Name="Main" Grid.Column="2" Margin="0,34,0,0" Grid.RowSpan="2"/>


    </Grid>
</Border>

1

There are 1 answers

2
DasiyTian_1203 On

You use the relative uri to display the image. In the XAML file, the compiler found the image based on your relative uri and the root path where XAML is located, so the image can be displayed. When you run exe, the father uri is folder where the exe in , so exe cannot find the image in combination with the relative path you provided, the image will not be displayed. Solution: such as exe in Solution/bin/Debug, add Basic/refresh-100. PNG in the Debug folder,use UriSource= "/Basic/refresh-100. PNG” in xaml , run exe , the image will be shown

[Update]

You could set the Copy to the Output Directory as 'Copy if newer' or 'Copy always' in the properties of the picture. See the below picture: enter image description here