I am trying to change the background image of my my App but it only accepts default Four images that are placed in Assets folder. ie Logo.png, widelogo.png etc. OR it accepts an PNG with same name as these files in Assets folder.
But I want to attach a BG Image with different name i.e Background.png. I am trying this XAML but it shows nothing:
<Grid.Background>
<ImageBrush Stretch="Fill" ImageSource="Pics/bg.png"/>
</Grid.Background>
I am new. Plz Guide me
Related
I am using the uwp component password box (XAMARIN) and set a certain image as the background, but when I click on the box, the background changes. I would like to keep the background static.
<PasswordBox x:Name="PasswordUser">
<PasswordBox.Background >
<ImageBrush ImageSource="/Assets/Login/campo-senha.png"/>
</PasswordBox.Background>
</PasswordBox>
PasswordBox.Background before clicked
PasswordBox.Background after clicked
So I would like the background to remain as I set it, always even when I click click on the box.
Please check PasswordBox style xaml, the password background has point over and focused status. so you need re-write the following resource with the ImageBrush that contains the same image source. You could place the follow resource in the page resource or application resource base on your design.
<ImageBrush x:Key="TextControlBackgroundPointerOver" ImageSource="/Assets/bgimg.png" />
<ImageBrush x:Key="TextControlBackgroundFocused" ImageSource="/Assets/bgimg.png" />
I have a Master Detail page and I want to set the icon in the navigation bar to show the menu. Therefore I put my images into an asset catalog (Asset Catalogs > Media > menu). If I want to reference that image from XAML it doesn't show up, when the image is in the asset catalog.
I tried different paths, but they all don't work. Debugging also doesn't show any images. It seems that Xamarin.Forms doesn't support asset catalogs, but that is not true. On a normal content page I have this:
<ContentPage.ToolbarItems>
<ToolbarItem Text="Configuration" Activated="OpenConfiguration" Order="Primary" Priority="0">
<ToolbarItem.Icon>
<OnPlatform x:TypeArguments="FileImageSource">
<OnPlatform.iOS>gear.png</OnPlatform.iOS>
<OnPlatform.Android>gear.xml</OnPlatform.Android>
<OnPlatform.WinPhone>Assets/gear.png</OnPlatform.WinPhone>
</OnPlatform>
</ToolbarItem.Icon>
</ToolbarItem>
</ContentPage.ToolbarItems>
This is working without problems. On my MasterPage (page, which is responsible for showing the menu entries in the master detail template) I have this:
<ContentPage.Icon>
<OnPlatform x:TypeArguments="FileImageSource">
<OnPlatform.iOS>menu.png</OnPlatform.iOS>
<OnPlatform.Android>menu.xml</OnPlatform.Android>
<OnPlatform.WinPhone>Assets/menu.png</OnPlatform.WinPhone>
</OnPlatform>
</ContentPage.Icon>
Bascially, it is the same code, but the icon doesn't show up. I get the icon only displaying if I put the images into Resources folder ...
But how can I use the images from the asset catalog in my XAML?
The only response I got from Xamarin is, that FileImageSource can't be used with an asset catalog. That isn't completely true, but since it doesn't work every time one shouldn't use it.
I am trying to add some Images as Image Sets in a Xamarin.Forms project. I followed this guide . But the icon is not displayed. Is it possible actually to use Image Sets in a Xamarin Forms Solution for the iOS project?
<Image VerticalOptions="Center"
HorizontalOptions="End"
Source="check_outline_500_active.png"
WidthRequest="40">
</Image>
Yes you can.
create the Asset catalog
add Image Set and name it "check_outline_500_active" (without .png)
add the images
done
my xaml
<Image VerticalOptions="Center"
HorizontalOptions="Center"
Source="check_outline_500_active.png">
</Image>
Result
Note
You might have to delete mtbs (on the mac) and bin/obj (on your project) or the build cache can fool you :)
Try to add images in resources folder under xamarin ios project and rename file like :
check_outline_500_active.png,
check_outline_500_active#2x.png,
check_outline_500_active#3x.png
but in code use : check_outline_500_active.png
I'm new to WP7 programming but have XP with other platforms, I am just running through all the basics so I can get to know the language but I have hit a roadblock I've entered a source for my background image:
<Grid x:Name="LayoutRoot">
<Grid.Background>
<ImageBrush ImageSource="C:/users/hypernova/pictures/Background1.jpg">
</ImageBrush>
</Grid.Background>
</Grid>
And the image shows up as a background in the design tab that is next to the XAML but when I debug and the emulator starts its just a black screen no background image, what have I missed? I have tried other ways of setting a background like:
<Grid x:Name="LayoutRoot">
<Canvas>
<Canvas.Background>
<ImageBrush ImageSource="C:/users/hypernova/pictures/Background1.jpg">
</ImageBrush>
</Canvas.Background>
</Canvas>
</Grid>
but the same thing happens I've tried a few other ways also but again nothing, I'm sure I've missed something I should have caught.
The path
C:/users/hypernova/pictures/Background1.jpg
exists on your dev machine, not on any Windows Phone 7+ device.
Remember, users will be downloading your app from the store, then running it on their phones. How would they possibly access your hard drive and get that image?
Unfortunately, since the design surface allows you to do this, it can of course be confusing to a new developer.
What you should do is add your image to your project as a Resource, then reference the resource via a pack URI (don't click on that link unless you want to scare yourself silly).
To add it as a resource, simply add the image to the root of your WP7 project, right click on it, select Properties, and then change the build action to Resource (not Embedded Resource, mind you).
Next, you have to construct a pack URI for this resource. This is ... not easy. You can use the tools in Visual Studio to do this, by editing the properties of your ImageBrush in the designer. This is the simplest, and recommended, route. All you have to do is edit the ImageSource of your ImageBrush in the Properties tool window, and select the image from the list of available images in the solution.
The other way is to manually construct the pack URI. For example, you could take the following
/[project assembly name];component/Background1.jpg
replace [project assembly name] with the name of your assembly (no extensions), and use it as your ImageSource value. You can find the correct project assembly name by looking at the Assembly Name under the Application section of the project properties.
<ImageBrush ImageSource="/MyWp7Application;component/Background1.jpg"/>
Note, depending on how your project folder structure is constructed, this URI may be different. Constructing the correct URI outside of the tools provided is a task deserving of another question.
I'm creating a WPF project using Python Tools for Visual Studio (in VS 2010). I add an Image control to the form. I click the "..." in the Image's Source property, and find an image.
This adds an "Images" folder to the project (both in the filesystem and in the solution), and copies the image to that folder (again both in the filesystem and in the solution). The image does not show up in the "Add" dialog. The Source attribute is set to "Images/foo.png".
In the XAML the source is blue-underlined because the "Build Action" is not set to "Resource". The only build actions available are "Content", "Compile", and "None". I presume "Resource" isn't available in a dynamic language like IronPython (certainly an embedded resource would be complex). I don't know whether this is the problem or whether this can be ignored.
The image does not show in the live editing window, and it doesn't show when the program runs.
I've tried "/Images/foo.png" (as suggested here), "pack://application:,,,/foo.png", "pack://application:,,,/Images/foo.png", "pack://siteoforigin:,,,/foo.png", and "pack://siteoforigin:,,,/Images/foo.png".
(The siteoforigin doesn't work because the 'origin' is ipy.exe. If I move the Images folder to the folder where IronPython is installed, then this does work. Obviously not a great solution!).
I've tried moving the Images folder in the filesystem to the same folder as the solution (i.e. one level up in the hierarchy), and having the image in the same folder as the .py file rather than in an Images subfolder.
If I change the source (directly in the XAML) to an absolute path, then it works perfectly. Obviously this isn't a great solution either!
How can I use a relative path for the Image?
It is possible. Apparently all you need to do is specify the source as a BitmapImage and relative URI will use the current directory as the base. Ignore the warnings about the file not being a resource, it doesn't really matter. It will show when you run your program.
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MyWpfApplication" Height="300" Width="300">
<Grid>
<Image>
<Image.Source>
<BitmapImage UriSource="../Relative/Path/To/Image.png" />
</Image.Source>
</Image>
</Grid>
</Window>
I think it is all due to the default value converters for images. If you bypass using them, it all seems to just work out.
The best way I found to deal with image paths is to just completely bypass that ponderous pack:// URI nonsense and simply use a Binding that binds directly to a BitmapImage.
<Image Source="{Binding imgWarningYellow}" Height="50" HorizontalAlignment="Center" VerticalAlignment="Center" />
This way, I can use a simple GetFullPath filesystem call in code to locate the damn thing and load it up as a BitmapImage:
yellowbitmap = System.Windows.Media.Imaging.BitmapImage()
yellowbitmap.BeginInit()
yellowbitmap.UriSource = System.Uri(System.IO.Path.GetFullPath("Images\warning-yellow50.png"))
yellowbitmap.DecodePixelHeight = 50
try:
yellowbitmap.EndInit()
except System.IO.FileNotFoundException as e:
print e.Message
else:
self.imgWarningYellow = yellowbitmap