I'm designing my first major app using WPF/C# and I'm trying to understand referencing Resources better.
Many guides tell me to use the first way I am failing to use.
- I design a resource in illustrator
- make it 96 dpi,
- save it as a png,
Then I:
- Open Resources.resx
- Click Add Resource ->Image
- Select my existing PNG called "SuperInt_Alert"
- Change the build type of that new png to Resource
Then when I try to show the image in my xaml, I use this:
xmlns:prop="clr-namespace:Stark.Properties"
<...code...>
<Image Source="{x:Static prop:Resources.SuperInt_Alert}" HorizontalAlignment="Center" VerticalAlignment="Top"
Grid.Row="1"
Grid.Column="1"
></Image>
Gives me a System.Windows.Markup.XamlParseException with Message='Provide value on 'System.Windows.Markup.StaticExtension' threw an exception.'. The Xaml designer also doesn't show my image. It's blank, but no errors.
While
<Image Source="/Stark;component/Resources/SuperInt_Alert.png" HorizontalAlignment="Center" VerticalAlignment="Top"
Grid.Row="1"
Grid.Column="1"
></Image>
Works just fine. It even shows it in my designer.
Why?
I'm just trying to understand the differences between the two ways to use a resource. What is wrong with the first way. I actually like the first way better, because when I type in the resource name, it lets me use IntelliSense to auto-complete my resource name. The second way does not because it is like a string.
Also, I do not have to set the resource type to Public, correct? I can leave it as internal because no other projects is using my resource file? I just have to make sure the build type is set to Resource/Content/Embedded Resource, correct?
Thanks so much!