Button icons missing after ClickOnce deployment - wpf

I added icons to my buttons in my WPF ClickOnce app but they are missing after deployment. They show up fine in debug in Visual Studio 2012. The icons are set as follows:
Build Action: Content
Copy to Output Directory: Copy if newer
This is following another post I saw that says to do this to use them in the following way in XAML:
<Button Style="{StaticResource LinkButton}" Command="{Binding PullForwardCommand}">
<StackPanel Orientation="Horizontal">
<Image Source="pack://siteoforigin:,,,/Resources/Icons/pullfwd.png" />
<TextBlock Text="Pull Forward" Style="{StaticResource MenuTB}"/>
</StackPanel>
</Button>
I did see all the icons are shown in a folder Resources/Icons (as named in my project) where the app is published (albeit as forward.png.deploy).
How do i get the icons to show up in the deployed app?

Change the Icon properties to
Build Action : Resource
Copy to Output Directory : Do not Copy
Hope this should work

Related

How to show an svg icon using svg image path in react native?

I want to show SVG icons but the thing I couldn't find the way to show. I tried to use Image and Use components of react-native-svg but they don't work with that. And I tried to do that with native way but it's really hard work to show just SVG icons.
Example code:
<Svg width="80" height="80">
<Image href={require('./svg/1f604.svg')} />
</Svg>
Initially, I had the same problem when I had SVG icons in my machine or saved in web URL.
I explored the react-native-svg library, but it does not allow you to include source of SVG icon already created. We can only create new icons using that library.
Later I found react-native-svg-uri which does allow us to use a given path to the icon.
You can use it like this:
import SvgUri from 'react-native-svg-uri';
<SvgUri
width="200"
height="200"
source={{uri:'http://thenewcode.com/assets/images/thumbnails/homer-simpson.svg'}}
/>

WPF - Import image as resource

In WinForms it is possible to import an image as a resource, and the image would still work when compiled in the /bin/Debug folder.
I can't figure out how to get this working in WPF, when I run the application the image doesn't load, because the image is saved in /Projects/AppName/images/, and the application is compiled into /Projects/AppName/bin/Debug when I run it in Debug mode.
Do I simply need to make a copy of my Images folder and put it where the application is compiled? Or is there another way. Here is my code which displays my image:
<Image Width="300">
<Image.Source>
<BitmapImage DecodePixelWidth="300" UriSource="/images/jamsnaps-dark.png" />
</Image.Source>
</Image>
Create a folder (e.g. images) in your Visual Studio Project.
Add the image file(s) to that folder.
Set their Build Action to Resource (in the Properties window, see second image in this answer).
Then write the UriSource property like you already did:
UriSource="/images/jamsnaps-dark.png"
That URI is effectively a Resource File Pack URI, where the prefix is automatically added by the XAML Parser.
In code behind, you would write
bitmap.UriSource = new Uri("pack://application:,,,/images/jamsnaps-dark.png");
Two options :
1) Go out from bin/Debug and in to your application folder by ../../ and then to your image.
<Image>
<Image.Source>
<BitmapImage UriSource="../../images/jamsnaps-dark.png" />
</Image.Source>
</Image>
2) Compile your images as Content from properties in the context menu on the image file , and then when compiled they would be placed in been debug.
I don't remember if you also need to tell them to copy local also in properties ( i'm not near a computer at the moment so i can't check .
Add the image to your project directory
In the solutions explorer, right click the image and select Include in Project
Build Action should be set to Resource by default.
You can then start to use the image path relative to the root e.g. images/text.jpg if you put it in a folder called images.

WPF Custom fonts problem

This is really weird. In Blend 4, the custom font works when I see the application in the designer, but when I run it, the font is gone and it goes back to arial or something. This is my XAML:
<TextBlock Text="Text G" FontFamily="/ProjectName;component/Fonts/#Futura Lt BT" FontSize="48" Background="#FFC44747" />
The font is in a folder called "Fonts" and the control in which I'm trying the font is in a folder called "Controls". I know it must be a problem with the relative position of the "Fonts" folder to the "Controls" folder, but I've already tried a lot of stuff and it doesn't work.
Also, the XAML markup I put up there is what Blend creates when I select the custom font. The font is copied as a resource all right (I already check the csprof file and it's there).
Any ideas? This has been kicking my butt for a couple hours now.
Thanks.
While I understand that this is far too late to help the question author, I am leaving this to help future viewers of this question.
The information in this answer comes from the Packaging Fonts with Applications page on MSDN:
Adding Fonts as Content Items
You can add fonts to your application as project content items that are separate from the application's assembly files. This means that content items are not embedded as resources within an assembly. The following project file example shows how to define content items.
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!-- Other project build settings ... -->
<ItemGroup>
<Content Include="Peric.ttf" />
<Content Include="Pericl.ttf" />
</ItemGroup>
</Project>
In order to ensure that the application can use the fonts at run time, the fonts must be accessible in the application's deployment directory. The element in the application's project file allows you to automatically copy the fonts to the application deployment directory during the build process. The following project file example shows how to copy fonts to the deployment directory.
<ItemGroup>
<Content Include="Peric.ttf">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Pericl.ttf">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
Adding Fonts as Resource Items
You can add fonts to your application as project resource items that are embedded within the application's assembly files. Using a separate subdirectory for resources helps to organize the application's project files. The following project file example shows how to define fonts as resource items in a separate subdirectory.
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!-- Other project build settings ... -->
<ItemGroup>
<Resource Include="resources\Peric.ttf" />
<Resource Include="resources\Pericl.ttf" />
</ItemGroup>
</Project>
When you add fonts as resources to your application, make sure you are setting the element, and not the element in your application's project file. The element for the build action is not supported.
The following markup example shows how to reference the application's font resources.
<TextBlock FontFamily="./resources/#Pericles Light">
Aegean Sea
</TextBlock>
Please follow the above link for details on referencing Font resources from code and other useful information.
Everywhere over the internet and in books it says that when you add a font you should set the Build Action to "Resource" (example here). And it 'worked for a while. Anyway, to fix my problem, I had to change it from "Resource" to "Content".

How can i use UserSettings when i import wpf usercontrols/views via mef

i have the following scenario. i have a main application wich can import usercontrols/views from other .dlls via mef. all works fine. but if i define usersettings im my plugin dlls, i got the following error
Das Konfigurationssystem konnte nicht initialisiert werden.
is there any way to include the settings in my plugin.dlls? or are there other ways to use UserSettings with plugin.dlls and mef?
thx
First i'm sorry, i really dont know what i did wrong in my first try with usersettings.
all i can say now its works like a charme.
i built usersettings for my plugin project with vs2010 and use it in xaml like this:
<Slider x:Name="zoomer" Width="100"
Value="{Binding Source={x:Static Properties:Settings.Default}, Path=Zoomer, Mode=TwoWay}"
Minimum="1.0" Maximum="2.0" TickFrequency="0.1" IsSnapToTickEnabled="True">
in my plugin project i take the Application.Current.Exit += ApplicationExit; to call
Settings.Default.Save();
I think in UserSettings are defined on an application, so they don't really work with libraries. One way to handle plugin settings is to have a settings service which the host exports, and have your plugins import the service and use it to save/load their settings.

System.OutOfMemoryException when using MediaElement in Silverlight 3

I'm trying to build a simple Silverlight 3 MediaPlayer using the MediaElement tag:
<Border Margin="8,8,0,8" Grid.Column="1" Grid.Row="1" BorderBrush="Black" BorderThickness="1" CornerRadius="7">+
<MediaElement x:Name="FighterPilot" Source="http://localhost/repository/FighterPilot.wmv" Stretch="Fill"/>
</Border>
This works very well for low resolution wmv files. But when a WMV File that has a 720p resolution, i get the build error
Xap packaging failed:
System.OutOfMemoryException
Do anyone have any clue why I get this build error?
Thankful for any help on this one!
Update: The PC I'm developing on has loads of free RAM, so memory shouldn't be a problem.
Assuming that you are using Visual Studio and the WMV file is in your Silverlight project, set the build action on the WMV file to "None" and set "Copy to output directory" to "Copy Always". That way it will not get bundled with the XAP file.
Or you could consider putting the WMV file in a "Video" directory under the ClientBin folder in the website which you can then access using the following:
FighterPilot.Source = new Uri("/Video/FighterPilot.wmv", UriKind.Relative);
No, I've never had that problem. The easy solution would be to not include the wmv file in the Silverlight project. You could add it somewhere in the ASP.NET project instead to avoid it being packaged in the xap all together.

Resources