Here's the situation:
I have a combobox within a button,, In expression blend when I add image to combo box item with the cod below, there's no problem apparently, image and textblock are showing well but as I run the proj.((F5)) there'e no sign of image, What I'm doing Wrong???
here's the code I use to add the image:
<ComboBoxItem Background="LightCoral" Foreground="Red"
FontFamily="Verdana" FontSize="12" FontWeight="Bold">
<CheckBox Name="CoffieCheckBox">
<StackPanel Orientation="Horizontal">
<Image Source="coffie.jpg" Height="30"></Image>
<TextBlock Text="Coffie"></TextBlock>
</StackPanel>
</CheckBox>
Any help Is much appreciated...
One likely problem might be that the image file is in your project folder without being copied to the build folder; /bin/Release for example. The application then will not find the file anymore. You can either ensure that the image is being copied when the application is compiled (that alone may not work actually as unqualified URIs make the parser look for resources as far as i know, the designer however does not seem to care) or you can embed the image as a resource. I do not know how to change compile settings in Blend however as i only use Visual Studio...
I had a similar problem showing images (used Uri strings) in a listview in a Silverlight application. They appeared properly in Expression Blend, but were not visible when I started it from Visual studio.
I kept my images in a folder called Images in my project, by setting the "Build action" for my image properties into "Content" fixed the problem. Now they show up when running the application. Hope it helps!
Related
I'm creating a WPF C# .Net App with the Aero theme which is supposed to run on Win7 as well as Win10.
On Win10 everything works as it's supposed to, however on Win7 the GUI looks vastly different.
In particular, my MenuItems simply seem to ignore certain settings such as VerticalContentAlignmentand BorderThickness.
Pics:
Win7 vs
Win10
How do I fix this?
(Some Code:)
xmlns:Themes="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero"
<MenuItem Header="Intranet"
Grid.Column="2"
x:Name="Menu_Intranet"
ToolTip="Intranet"
BorderBrush="white"
BorderThickness="5"
VerticalAlignment="Stretch"
Click="Menu_1_Click"
ToolTipService.ShowOnDisabled="true"
VerticalContentAlignment="Center"/>
Thanks in advance!
I edited the MenuItemControlTemplate (right click on the control you want to edit in the designer -> edit template) and applied it to the MenuItems via Template="{DynamicResource MyMenuItemControlTemplate}".
I guess this leaves no room for the OS/Theme to apply its own settings.
I am currently developing a default WPF control Kit.
But I am stuck with using the correct kind of uri in xaml.
What I have is an image wich should be used as the background for the non-client area of my window.
To make the default controls available very easy I want to put everything in a dll.
Other apps can quickly reference that dll and get access to the style.
The problem is, that my image is not showing up when using the dll style in an app.
My image (/Resources/WindowBackground.jpg) is set to Resource and I am using the following xaml:
<Image Grid.ColumnSpan="99" Grid.RowSpan="99">
<Image.OpacityMask>
<ImageBrush ImageSource="pack://application:,,,/Resources/WindowBackground.jpg"/>
</Image.OpacityMask>
</Image>
I also tried:
<Image Grid.ColumnSpan="99" Grid.RowSpan="99" Source="/Resources/WindowBackground.jpg"/>
Both write the following into the output (Couple times):
..."System.IO.IOException" in PresentationFramework.dll...
I also tried lots of other uris wich sometimes lead to XamlParseExeptions and other not so nice stuff.
Thank you for any hints :D
You can find your answer in the Pack URIs in WPF page on MSDN. For your particular situation, you can use the following syntax to reference your resource image file:
pack://application:,,,/ReferencedAssembly;component/Resources/WindowBackground.jpg
From the linked page:
The following example shows the pack URI for a XAML resource file that is located in a subfolder of the referenced assembly's project folder.
pack://application:,,,/ReferencedAssembly;component/Subfolder/ResourceFile.xaml
Note: The type of resource file here is irrelevant.
I am building a wpf application and I wanted to use Open Sans Regular font in my application.
I referred this link for embedding font. I added OpenSans Regular.ttf file to resources under project properties.
Then I referred them in my application as mentioned below:
<Window x:Class="FontEmbeddingDemo.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525" FontFamily="Resources/#Open Sans">
<Window.Resources>
</Window.Resources>
<Grid>
<TextBlock Height="100" Text="This is test text." FontSize="14" FontFamily="Resources/#Open Sans"/>
</Grid>
</Window>
In designer of Visual Studio I can see font changed to open sans but when I run the application it is taking system default font (Arial in my system).
Do let me know if you need any other information.
From MSDN Page:
When you add fonts as resources to your application, make sure you are
setting the <Resource> element, and not the element
in your application's project file. The <EmbeddedResource> element for
the build action is not supported.
So, I guess, you will have to add this font file to your project as you would add any other file and set its BuildAction to Resource instead of adding the font to the Resources under Project Properties, which will make it as an EmbeddedResource.
EDIT
Read this excellent article on how to use custom fonts in a WPF application.
You could also, get this working by way #Sheridan mentioned - which is setting BuildAction to Content. However, the problem with this approach is you will have loose separate file hanging around along with your binary. Users can potentially change this file, which may cause problems with your app. It is best to use Resource as BuildAction as the font gets bundled into the assembly.
In my opinion, I believe that the accepted answer to this question may either be incorrect, or misleading. I am using Font files in exactly the same way and I have absolutely no need to set their BuildAction to Resource. My Font files have a BuldAction set to Content and that works just fine. I'm guessing that the accepted answer would only help users that have set their Font file to EmbeddedResource.
The comment that #sthotakura quoted from the linked MSDN page is merely talking about manually editing the project file, which the question author is not doing. Note that there is no mention of BuildAction property in the linked page apart from mentioning that the EmbeddedResource value is invalid in this case.
Please try this instead or as well:
Set the BuildAction of the Font file(s) to Content.
Reference the Font file like this (with the all important starting slash):
FontFamily="/Resources/#Open Sans"
I just tried removing the starting slash in my project and the Font defaulted to another Font, so I'm pretty sure that this will work... all the same, please let me know. I'm more than happy to remove this answer if I am mistaken.
I'm using Blend 4 and VisualStudio 2010 to build a kiosk WPF 4.0 app that has a wizard-like function. I've decided I'd like individual steps moved to separate UserControls, to keep the main window of the application as lean as possible. However, I'm having trouble including the UserControl into the main window, since image paths are being mangled after moving the XAML to a separate UserControl file.
This code works when it's put into the main window XAML:
<Button Grid.Row="1" Grid.Column="2" Height="{Binding ActualWidth, RelativeSource={RelativeSource Self}}" Margin="20" VerticalAlignment="Bottom" Style="{DynamicResource ImageButton}">
<Button.Background>
<ImageBrush ImageSource="/Images/Extra/motor_boat_2.jpg" Stretch="UniformToFill"/>
</Button.Background>
</Button>
But when I move that code to a separate user control and include it in the main window, the designer throws and exception:
IOException: Cannot locate resource 'images/extra/sailing_boat.jpg'.
I've tried using a couple of different syntaxes, but all fail, sometimes using the %ProgramFiles% directory, other times converting the absolute path to relative (as above). Sometimes, the Build Project operation in Blend 4 fails because of this.
All the images are marked as Resource with Build Action set to Copy Always.
VisualStudio has no problem building and running the application, the UserControl displays correctly within the running application with no thrown exceptions.
EDIT:
Using relative paths in the UserControl and then building and running the app from VisualStudio and switching back to Blend correctly displays the images, until the next modification to the UserControl.
Use Pack URI like following:
Uri uri = new Uri("pack://application:,,,/Images/Extra/motor_boat_2.jpg");
I just created a puppet in Microsoft Blend consisting of imageboxes that are displaying a dummy image(Which is a white box). In blend it shows the images but in visual studio (and when running the application) the images aren't showing.
This is a snippet of the code I am using
<Image Source="/Images/BodyParts/dummy.jpg" Height="10" Width="20" Stretch="Fill" OpacityMask="{x:Null}" x:Name="backFoot" Canvas.Left="41.71" Canvas.Top="147.668" />
alt text http://img26.imageshack.us/img26/1401/blendvscomparewo7.jpg
Please note that the circles you are seeing in both versions are different controls not images.
Be sure your picture "dummy.jpg" appears in the solution explorer within the correct folder
example:
Solution Explorer http://img403.imageshack.us/img403/4976/solutiontm2.jpg
And if you right click -> properties on the image, you should see the "Properties" window.
Then set the "Build Action" to "Content" as shown below:
Properties http://img338.imageshack.us/img338/9166/propertiesfl9.jpg