Adding Images to FlipView from Code - windows-8

I am trying to add some images to a FlipView using the following code:
for (int N = 1; N < 30; N++)
{
string name = String.Format(#"ms-appx:/Gallery/{0:00}.jpg", N);
Uri uri = new Uri(name);
BitmapImage img = new BitmapImage(uri);
MainFlipView.Items.Add(img);
}
but it only displays some texts. I defined the FlipView in my XAML:
<FlipView x:Name="MainFlipView">
</FlipView>
What should I do?

The text showing is a call to the ToString method of the BitmapImage because you have no DataTemplate defined. Define on:
<FlipView>
<FlipView.ItemTemplate>
<DataTemplate>
<Image Source="{Binding}" />
</DataTemplate>
</FlipView.ItemTemplate>
</FlipView>

Try this format for entering the file name
images\\Photos\\italia1.jpg
.here images and photos are obviously folders and italia1.jpg is the pic file. I have used this to set this image as the lock screen of the device. So maybe this is the format that could work for your flipview problem.

Your path to the image should look like this:
string name = String.Format(ApplicationData.Current.LocalFolder.Path + #"/Gallery/{0:00}.jpg", N);

Related

View a specific image from the complete gallery path without browsing

I'm trying:
<Image Source="/storage/emulated/0/Pictures/Test/IMG_20200408_085036.jpg"/>
No effect.
File imageSpc = new File('/storage/emulated/0/Pictures/Test/IMG_20200408_085036.jpg');
var imageSpc = new File('/storage/emulated/0/Pictures/Test/IMG_20200408_085036.jpg');
Error, cannot create static variable for type File or var.
<Image x:Name="fotka" Aspect="AspectFit" HeightRequest = "50"
WidthRequest = "60"/>
fotka.Source = ImageSource.FromFile("/storage/emulated/0/Pictures/Test/IMG_20200408_085036.jpg");
No effect
Is possible to show specific image from gallery in XAML or at least from the code
I did enable ADB notification option in device.
In The moment image to be displayed compiler show error:
How to fix this Error?
According to your description, you want to display image using gallery path, if yes, please take a look the following code:
Firstly, you need to get image path from gallery in Android or ios.
Create interface IFileSystem in PCL(Forms)
public interface IFileSystem
{
string GetGalleryImage();
}
Then implementing this interface in platform, the example is in Android.
[assembly: Dependency(typeof(FileSystemImplementation))]
namespace demo3.Droid
{
public class FileSystemImplementation : IFileSystem
{
public string GetGalleryImage()
{
var filePath = Environment.GetExternalStoragePublicDirectory(Environment.DirectoryPictures);
var path = System.IO.Path.Combine(filePath.AbsolutePath, "Test/image1.jpg");
return path;
}
}
}
Add one Image control in PCL(Forms), name image1, using DependencyService to get image path.
<Button
x:Name="btn1"
Clicked="Btn1_Clicked"
Text="load image" />
<Image
x:Name="image1"
HeightRequest="100"
WidthRequest="100" />
private void Btn1_Clicked(object sender, EventArgs e)
{
var path = DependencyService.Get<IFileSystem>().GetGalleryImage();
image1.Source = ImageSource.FromFile(path);
}
This is article about DependencyService, you can take a look:
https://learn.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/dependency-service/introduction
Update:
I found, each image before show in activity must be resized to max size 4096 x 4096 px otherwise image not shown, without any errors message.

Adding Image to a Button in Windows 10 Phone App

I am trying to add an image to a button . I want to archive something like this
This is what I was trying to do but the image doesn't appear
<StackPanel Orientation = "Horizontal">
<Button x:Name = "kap2"
FontFamily = "Arial"
Content = "Te drejtat dhe lirite themelore"
Width = "250"
Height = "50"
HorizontalAllignment = "Left">
<Button.Background>
<ImageBrush ImageSource = "Asses/number/1.png" Stretch="Fill">
</ImageBrush>
</Button.Background>
</Button>
</StackPanel>
The word 'Asses' I think it should be 'Assets'.
If this doesn't work, try also
/Assets/number/1.png
The problem is about spelling. Make sure that folder names are correct and the image name is correct too.

How to show the previous page gridview images in flipview control in another page in windows 8?

I am displaying the items in grid view .I want to show the grid view items in another page using flip view control.How to dynamically display the selected item position in second page ?
Please tell me how to achieve this?
EDIT:
In First Page :
Grid View item click event i wrote code like this:
private void PhotoGrid_ItemClick(object sender, ItemClickEventArgs e)
{
var itemid = ((flipimage)e.ClickedItem);
flipimage s = new flipimage() { ImageUrl = itemid.ImageUrl, Title = itemid.Title };
this.Frame.Navigate(typeof(FlipPage), s);
}
In Second Page:
protected override void OnNavigatedTo(NavigationEventArgs e)
{
flipimage s = (flipimage)e.Parameter;
string url = s.ImageUrl;
flipviewcontrol.Items.Add(url);
}
I want to display previous page selected item in second page and also click on next in flipview need to show after that selected item data.Please tell me how to write the code.
For data binding to
flipview :
XDocument xdoc = XDocument.Load("XMLFile1.xml");
IEnumerable<flipimage> images = from img in xdoc.Descendants("Image") select new flipimage(img.Element("ImageTitle").Value, img.Element("ImageUrl").Value);
flipviewcontrol.DataContext = images;
Design of Flipview:
<Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
<FlipView HorizontalAlignment="Left" VerticalAlignment="Top" x:Name="flipviewcontrol" ItemsSource="{Binding}">
<FlipView.ItemTemplate>
<DataTemplate>
<Image HorizontalAlignment="Left" Source="{Binding ImageUrl}" Height="762" VerticalAlignment="Top" Width="1360" x:Name="imagecontrol"/>
</DataTemplate>
</FlipView.ItemTemplate>
</FlipView>
</Grid>
Please tell me how to show previous page selected item value and when click on next in filpview need to show after selected items data of the page vice versa!!!

how to apply Font.WeightBold for only one ListBoxitem in ListBox

I am binding listboxitems from an arrayList.This arraylist contains all textbox and combobox text.Now my question is how can i make only one listitem font as bold through code not xaml..because am not adding listbox items from xaml.
any suggestion, idea to implement this..
thanks in advance.
EDIT:
xaml:
<ListBox Name="lstbx" Width="200" HorizontalAlignment="Left" Margin="0,0,0,0" BorderBrush="Transparent" > </ListBox>
code:
private ArrayList LoadListData()
{
ArrayList arrList = new ArrayList();
//txtFullName.FontWeight = FontWeights.Bold; //this didnt work
arrList.Add(txtFullName.Text);
arrList.Add(" ");
}
lstbx.ItemsSource=LoadListData();
I don't know if this is what you want but basically I'm filling the listbox with TextBlocks and setting the text content as I want. Just for demonstration:
private void MakeBold()
{
for (int i = 0; i < 5; i++)
{
TextBlock s = new TextBlock();
s.Text = "Testing" + i;
if (i == 3)
s.FontWeight = FontWeights.Heavy;
lstbx.Items.Add(s);
}
}
I get this result:
I hope this helps.
I am assuming txtFullName is declared programmatically. Even if you set the FontWeight programmatically, you are still adding the text only to your list, and the weight information never gets passed along.
Pass the whole TextBox instead and it should work:
arrList.Add(txtFullName);

Bind xaml vector images dynamically

I'm looking for a way to bind xaml images dynamically in code.
There are lots of examples online to show how to bind png or xaml images in the window's xaml, or to load png files in code.
But I have found no examples for xaml files with build action=page. XmlReader can't handle them since they are compiled to baml.
LoadComponent(new Uri("...filename.baml") will apparently load the baml but what kind of image class do I load this into? BitmapImage(new Uri("...filename.baml") does not seem to work, probably because it's not a bitmap.
Thanks in advance.
Additionally, if your image is stored in a Xaml vector file in this kind of format:
You can load the individual xaml vector images in the following way (it is probably best to prevent the dictionary being added multiple times, if like me, you are loading it via an OpenFileDialog):
C#:
string fullPathAndFileName = "C:\Image_Name.xaml";
ResourceDictionary dict = new ResourceDictionary();
dict.Source = new Uri(fullPathAndFileName);
Application.Current.Resources.MergedDictionaries.Add(dict);
DrawingImage image = dict[dict.Keys.Cast().ToList()[0]] as DrawingImage;
myImage.Source = image;
Xml:
Image Height="200" Width="200" x:Name="myImage"
After much trial and error and searching, the following article helped me on my way:
Access ResourceDictionary items programmatically
If each Xaml vector image is contained inside a ResourceDictionary with a key (see my 2nd post below for the format)...
If your Xaml vector image files are all stored in your project (build action: page), you can load them in the following way:
//Get the ResourceDictionary using the xaml filename:
ResourceDictionary dict = System.Windows.Application.LoadComponent(new Uri("/yourprojectname;component/youriconfolder/youriconfilename.xaml", System.UriKind.Relative)) as ResourceDictionary;
//Get the xaml as a DrawingImage out the ResourceDictionary
DrawingImage image = dict[dict.Keys.Cast<object>().ToList()[0]] as DrawingImage;
I could return the image and bind it to the viewmodel property, which returns the iconfilename.xaml. Then I use a converter with the above code to lookup the icon and return it as a DrawingImage.
Or you can assign it as the source of an Image (see my 2nd post below).
UPDATE: 2015.10.08 - It seems Carl didn't get around to the "XAML format example" part of his post. The XAML would look something like this:
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<DrawingImage x:Key="SomeUniqueKey">
<DrawingImage.Drawing>
<DrawingGroup>
...
</DrawingGroup>
</DrawingImage.Drawing>
</DrawingImage>
</ResourceDictionary>
Then you could do:
DrawingImage image = dict["SomeUniqueKey"] as DrawingImage;
Or, if you prefer using the Image directly,
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Image x:Key="SomeUniqueImage">
<Image.Source>
<DrawingImage>
...
</DrawingImage>
</Image.Source>
</Image>
</ResourceDictionary>
And:
Image someImage = dict["SomeUniqueImage"] as Image;