ApplicationBar not showing up in Windows Phone HTML Template - windows-phone-8

I have created an application bar in code behind in a new Windows Phone HTML template. Originally the application bar was in xaml but I removed it. I created my application bar like I normally do in the code behind, although in this template for some reason it will not show up. I cannot figure out what the issue is, I have no errors. My code is below. The only thing I did in the XAML of the template is add a pivot control and I made the browser visibility false. My code is below. Any ideas?
XAML
<!--LayoutRoot is the root grid where all page content is placed-->
<Grid x:Name="LayoutRoot" Background="Transparent">
<phone:Pivot>
<phone:Pivot.TitleTemplate>
<DataTemplate>
<TextBlock Text="APPLICATION NAME">
</DataTemplate>
</phone:Pivot.TitleTemplate>
<phone:PivotItem Header="one">
</phone:PivotItem>
<phone:PivotItem Header="two">
</phone:PivotItem>
</phone:Pivot>
<phone:WebBrowser x:Name="Browser" Visibility="Collapsed"
IsScriptEnabled="True"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Loaded="Browser_Loaded"
Navigated="Browser_Navigated"
NavigationFailed="Browser_NavigationFailed"
ScriptNotify="Browser_ScriptNotify"/>
<ProgressBar x:Name="PerformanceProgressbar"
VerticalAlignment="Top"
IsIndeterminate="False"
Visibility="Collapsed">
</Grid>
XAML.CS
public MainPage()
{
InitializeComponent();
BuildLocalizedApplicationBar();
}
private void BuildLocalizedApplicationBar()
{
ApplicationBar appbar = new ApplicationBar();
/appbar.Mode = ApplicationBarMode.Minimized;
ApplicationBarMenuItem settings = new ApplicationBarMenuItem();
settings.Text = AppResources.MainPage_Settings;
settings.Click += settings_Click;
appbar.MenuItems.Add(settings);
}

You are just creating an object ApplicationBar, but you are not adding it to your Page. Page has a property ApplicationBar which you should set with your created instance of class ApplicationBar.
What would work:
private void BuildLocalizedApplicationBar()
{
ApplicationBar appbar = new ApplicationBar();
/appbar.Mode = ApplicationBarMode.Minimized;
ApplicationBarMenuItem settings = new ApplicationBarMenuItem();
settings.Text = AppResources.MainPage_Settings;
settings.Click += settings_Click;
appbar.MenuItems.Add(settings);
this.ApplicationBar = appbar; // or simply ApplicationBar = appbar;
// you can also add Appbar directly = ApplicationBar = new ApplicationBar();
// and then modify via this property
}
Note that you can have many ApplicationBars (objects) and exchange them easily.

Use this code would work:
click here for more details
private void BuildLocalizedApplicationBar()
{
ApplicationBar appbar = new ApplicationBar();
/appbar.Mode = ApplicationBarMode.Minimized;
ApplicationBarMenuItem settings = new ApplicationBarMenuItem();
settings.Text = AppResources.MainPage_Settings;
ApplicationBar.MenuItems.Add(settings );
settings.Click += new EventHandler(settings_Click);
}

Related

Save all images in ListView

I am loading a bunch of images from Vk.com in a ListView.I'd like to be able to download/save all images in any list to the phone's gallery, either in a simple event or by default. How would I go about this?
This is the XAML.
<Page.BottomAppBar>
<CommandBar>
<AppBarButton FontSize="15" FontFamily="Times New Roman" Icon="Back" Label="Albums" Click="AppBarButton_Click"/>
</CommandBar>
</Page.BottomAppBar>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="50"></RowDefinition>
<RowDefinition Height="*"> </RowDefinition>
</Grid.RowDefinitions>
<TextBlock x:Name="MyTextBlock" FontSize="35" HorizontalAlignment="Center"></TextBlock>
<ListView Grid.Row="1"
ItemsSource="{Binding}"
SelectionMode="None"
IsItemClickEnabled="False"
>
<ListView.ItemTemplate>
<DataTemplate>
<Image Stretch="UniformToFill" Source="{Binding image_final}"
AutomationProperties.Name="{Binding Title}"
Width="Auto"
Height="Auto"
></Image>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</Grid>
You've tagged this as WP8 and WP8.1. The code below is for 8, however shouldn't take too much work for 8.1.
You can download and save an image to the users gallery like this:
using Microsoft.Xna.Framework.Media;
using System.Windows.Media.Imaging;
using System.IO;
WebClient client = new WebClient();
client.OpenReadCompleted += (s, ev) =>
{
var streamResourceInfo = new StreamResourceInfo(ev.Result, null);
BitmapImage bitmap = new BitmapImage();
bitmap.SetSource(streamResourceInfo.Stream);
WriteableBitmap bmp = new WriteableBitmap(bitmap);
MediaLibrary library = new MediaLibrary();
using (MemoryStream stream = new MemoryStream())
{
Extensions.SaveJpeg(bmp, stream, bmp.PixelWidth, bmp.PixelHeight, 0, 100);
library.SavePicture("imagename.jpg", stream.ToArray());
}
MessageBox.Show("The picture has been saved to your Pictures Hub", "Success!", MessageBoxButton.OK);
};
client.OpenReadAsync(new Uri("http://example.com/imageurl.jpg"));
Obviously put the correct image URL in the last line. And optionally replace "imagename.jpg" with the real name of the image.
This link really explains everything: saving images, and organizing them into folders. Definitely worth a read.
https://social.msdn.microsoft.com/Forums/sqlserver/en-US/769c9a6c-961c-47ea-bddf-a381db932289/saving-an-image-from-the-web-to-the-saved-pictures-folder-in-windows-phone-81-rt-c?forum=wpdevelop
Explanation:
//Create a storage folder in the Pictures Library:
StorageFolder AppFolder = await KnownFolders.PicturesLibrary.CreateFolderAsync("XYZ", CreationCollisionOption.OpenIfExists);
//Naming and storing the file:
var uri = imageuri; //image uri
var filename = Path.GetFileName(uri.LocalPath); //designates file name
var thumbnail = RandomAccessStreamReference.CreateFromUri(uri);
var remoteFile = await StorageFile.CreateStreamedFileFromUriAsync(filename, uri, thumbnail);
await remoteFile.CopyAsync(albumname, filename, NameCollisionOption.FailIfExists); //Fail if argument filename is a string by which a file is already saved.
I hope this helps.

Back button not working when placed in AppBar

I'm working on a Windows 8.1 app. I have added a basic page to my project, which automatically adds a back button:
<Button x:Name="backButton"
Margin="39,59,39,20"
Command="{Binding NavigationHelper.GoBackCommand, ElementName=pageRoot}"
Style="{StaticResource NavigationBackButtonNormalStyle}"
VerticalAlignment="Top" />
The button works fine. However, when I move this button to an AppBar, it doesn't work. The view doesn't go back to the previous page.
What is going wrong in the latter case?
The AppBar isn't in the same namespace as the page and so the Command binding to the page's NavigationHelper property doesn't resolve. This is the case for any binding of the AppBar to the page.
You can fix this by setting the AppBar's DataContext to the page in page.Loaded
XAML
<Page.BottomAppBar>
<AppBar x:Name="bottomAppBar" IsOpen="True">
<Button x:Name="backButton"
Margin="39,59,39,20"
Command="{Binding NavigationHelper.GoBackCommand}"
Style="{StaticResource NavigationBackButtonNormalStyle}"
VerticalAlignment="Top" />
</AppBar>
</Page.BottomAppBar>
C#
public BasicPage1()
{
this.InitializeComponent();
this.navigationHelper = new NavigationHelper(this);
this.navigationHelper.LoadState += navigationHelper_LoadState;
this.navigationHelper.SaveState += navigationHelper_SaveState;
this.Loaded += BasicPage1_Loaded;
}
async void BasicPage1_Loaded(object sender, RoutedEventArgs e)
{
bottomAppBar.DataContext = this;
}
--Rob

Display Tooltip on Tapping the pushpin(Custom marker) in Windows Phone 8 Map

In a Windows Phone map I am drawing my mapmarker and using them as pushpin.
MapLayer mapLayer = new MapLayer();
foreach (LocationDetail locationDetail in locationListobj)
{
MapOverlay overlay = new MapOverlay();
overlay.Content = GetImage(locationDetail);
overlay.GeoCoordinate = new GeoCoordinate(locationDetail.Latitude, locationDetail.Longitude);
overlay.PositionOrigin = new Point(0.0, 1.0);
mapLayer.Add(overlay);
}
AllyMap.Layers.Add(mapLayer);
A new requirement came up that upon tapping on the map we have to show the description in a infobar. Can anybody please help me how could I do that.
You need to set the ToolTipService.ToolTip property on the PushpinViewModel which should be a UIElement. ToolTips must be hooked up to a UIElement, which actually renders in your visual tree, to be triggered by mouse hover. Hovering is just a way of showing the tooltip.
<ToolTipService.ToolTip>
<ToolTip Style="{StaticResource ToolTipStyle}">
<StackPanel Orientation="Vertical">
<TextBlock Text="{Binding Title}" />
<TextBlock Text="{Binding Description}" TextWrapping="Wrap" />
</StackPanel>
</ToolTip>
</ToolTipService.ToolTip>
You could refer this for more:
http://social.technet.microsoft.com/wiki/contents/articles/24118.windows-phone-8-maps-api-making-custom-pushpin-with-custom-tooltip-c-xaml.aspx
Hope it helps!

Tile and longlistselector itemTemplate

I would like to to create an itemtemplate of longlistselector using a tile
is it possible?
how to do it in xaml?
could someone show me some code to do it?
Using a longlistselector is very easy for this tile applications.
<phone:PhoneApplicationPage.Resources>
<DataTemplate x:Key="TileDataTemplate">
<Grid Background="{StaticResource PhoneAccentBrush}"
Margin="0,0,12,12">
<StackPanel VerticalAlignment="Top">
<TextBlock Text="{Binding Content}" TextWrapping="Wrap"/>
</StackPanel>
<StackPanel VerticalAlignment="Bottom">
<TextBlock Text="{Binding Title}" Margin="6,0,0,6"/>
</StackPanel>
</Grid>
</DataTemplate>
</phone:PhoneApplicationPage.Resources>
<phone:LongListSelector Margin="0,0,-12,0"
SelectionChanged="LongListSelector_SelectionChanged"
LayoutMode="Grid"
GridCellSize="150,150"
ItemsSource="{Binding DataBindingItems}"
ItemTemplate="{StaticResource TileDataTemplate}"
/>
here the most important thing note is the LayoutMode="Grid" GridCellSize="150,150" properties.
Edit:::
I have added the code for the tile where i would show up a tile with two textblocks showing up some content on top and then title in the end. The way you have to wire up some sample data or dynamic depends on code behind. Ping me if that is needed. And this is really basic stuff. Accept if you get the answer.
// find the tile object for the application tile that using "flip" contains string in it.
ShellTile oTile = ShellTile.ActiveTiles.FirstOrDefault(x => x.NavigationUri.ToString().Contains("flip".ToString()));
if (oTile != null && oTile.NavigationUri.ToString().Contains("flip"))
{
FlipTileData oFliptile = new FlipTileData();
oFliptile.Title = "Hello WP8!!";
oFliptile.Count = 11;
oFliptile.BackTitle = "Updated Flip Tile";
oFliptile.BackContent = "back of tile";
oFliptile.WideBackContent = "back of the wide tile";
oFliptile.SmallBackgroundImage = new Uri("Assets/Tiles/Flip/159x159.png", UriKind.Relative);
oFliptile.BackgroundImage = new Uri("Assets/Tiles/Flip/336x336.png", UriKind.Relative);
oFliptile.WideBackgroundImage = new Uri("Assets/Tiles/Flip/691x336.png", UriKind.Relative);
oFliptile.BackBackgroundImage = new Uri("/Assets/Tiles/Flip/A336.png", UriKind.Relative);
oFliptile.WideBackBackgroundImage = new Uri("/Assets/Tiles/Flip/A691.png", UriKind.Relative);
oTile.Update(oFliptile);
MessageBox.Show("Flip Tile Data successfully update.");
}
else
{
// once it is created flip tile
Uri tileUri = new Uri("/MainPage.xaml?tile=flip", UriKind.Relative);
ShellTileData tileData = this.CreateFlipTileData();
ShellTile.Create(tileUri, tileData, true);
}

How do I change the background color of a textblock in MVVM-WPF

I am new to WPF technology. i am using MVVM architecture.
I want to change the background of textblock based on viewmodel's attribute.
e.g If i am using 'brush' object, I want to bind it to background color of textblock.
<TextBlock Margin="0,1"
HorizontalAlignment="Center"
FontFamily="Arial"
FontSize="16"
Text="{Binding Line}"
TextWrapping="Wrap"
Background="{Binding brushobj}"/>
How to implement it?
You could define it like this, inside your ViewModel.
private Brush _brushobj;
/// <summary>
/// Gets or sets the BrushObject.
/// </summary>
public Brush BrushObj
{
get
{
return _brushobj;
}
set
{
// Set value
_brushobj = value;
// Notify UI that the value has changed.
RaisePropertyChanged("BrushObj");
// OnPropertyChanged("BrushObj"); // Use the appropriate function to notify the UI.
}
}
Then simply set the value with something like this:
BrushObj = (Brush)new BrushConverter().ConvertFromString("Green");
Last you bind it to your View like you did in your question:
Background="{Binding BrushObj}"
Edit: I tried to make a project myself just to verify that this was indeed working and the following code worked fine. If it's still not working it's more likely to be something with your MVVM setup causing problem.
MainWindowViewModel:
namespace WpfApplication1
{
public class MainWindowViewModel : ObservableObject
{
private Brush _brushobj = (Brush)new BrushConverter().ConvertFromString("Red");
public Brush BrushObj
{
get
{
return _brushobj;
}
set
{
_brushobj = value; // Set value
RaisePropertyChanged("BrushObj"); // Notify UI that the value has changed.
}
}
}
}
MainWindow:
<Window x:Class="WpfApplication1.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">
<Grid>
<TextBlock Margin="0,1"
VerticalAlignment="Center"
HorizontalAlignment="Center"
FontFamily="Arial"
FontSize="16"
Text="Testing a lot of stuff here! important stuff!"
TextWrapping="Wrap"
Background="{Binding BrushObj}"/>
</Grid>
</Window>