I
I
iRumba2015-05-29 06:30:39
WPF
iRumba, 2015-05-29 06:30:39

How to get an image from resources?

Hello. I'm making a button with an icon. I placed a png image in property.resources and I want to display it on a button.
Here is the button code

<Button Name="saveButton" Style="{StaticResource dialogButtonControl}" Click="saveButton_Click">
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*"/>
                            <ColumnDefinition Width="auto"/>
                        </Grid.ColumnDefinitions>
                        <TextBlock Text="Сохранить" Style="{StaticResource imagedButtonTextBlock}" Grid.Column="1"/>
                        <Image Grid.Column="0">
                            <Image.Source>
                                <BitmapImage UriSource="/ConfigWPF;component/Resources/saveButton.Image.png"/>
                            </Image.Source>
                        </Image>
                    </Grid>
                </Button>

The project is called ConfigWPF
In the designer, pictures are displayed, but when the project is run in debug or release, the buttons have no pictures. The Resources folder also appeared in the source codes, where the pictures I need are located. I tried to copy this folder to the folder with the finished application, it did not help.
I would like to see pictures on the buttons, if possible they should be sewn into compiled files, and not hang out in a separate folder. Getting icons from resources is required in XAML, not in C# code. Tell me how to do it? What I have in the code, I found somewhere on the Internet. The other options didn't work at all.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sumor, 2015-05-29
@Sumor

Try specifying the full path to the resources as a Uri of type pack .
Sometimes, when pictures are not in the assembly that is being run, the application cannot find them in resources.
The full path will look something like this:
component - part of the path, points to resources.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question