Creating a login page for Win 8 apps - authentication

I'm trying to have a login page for my app, jus like the windows login account. But this is not a account sign in. Once the user sets a password, every time the user opens the app afresh, it asks for the password.
From this site, I got how to create the login page. But the problem im facing is, once i put the grid inside the ContentControl it does not expand.
I had to specify the height and width of the grid named mainbackground. I do not want to hard code the values because as the resolution changes the height and width may vary.
<Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush }">
<Grid.RowDefinitions>
<RowDefinition/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<ContentControl x:Name="parent" Grid.Row="0" Grid.RowSpan="1">
<Grid x:Name="MainBackground" Height="768" Width="1366">
<!-- rest of the xaml declaration-->
</Grid>
</ContentControl>
<ContentControl x:Name="container" Height="450" Margin="0,194,0,124">
<Popup x:Name="logincontrol1" IsOpen="False" >
</ContentControl>
</Grid>
Few questions,
Is this the correct method to create login page?
Why doesn't the grid expand to the who screen without me having to specify the height and width?
What is the actual use of content control? Didnt find elaborate explanations online.
Thank you

The advice is not to write your own login page, but to use the CredentialPicker control.
In your case, you are not hooking the picker into anything, and that is a valid scenario. Set the picker options up like this...
CredentialPickerOptions opts = new CredentialPickerOptions {
AuthenticationProtocol = AuthenticationProtocol.Basic,
Caption = "My App Login",
Message = "Log in here",
TargetName = "MyApp"
};
var res = await CredentialPicker.PickAsync(opts);
and then you can access the CredentialUserName and CredentialPassword values for your own logic.

Related

How to change the tab index in avalonia ui

In Avalonia Ui,
I have multiple layouts in my ui and I want a very specific tab order,
something like
<TextBox Tabindex="2">
<StackPanel>
<TextBox Tabindex="1">
</StackPanel>
<TextBox Tabindex="0">
that would result in using the tab-key cycling from bottom to top.
Is this possible? I found nothing.
I don't think so. KeyboardNavigation.TabIndex is not implmented yet: https://github.com/AvaloniaUI/Avalonia/issues/3025.
You have some limited Control using the functions provided in KeyboardNavigation and by using another control, for example a DockPanel or a Relative Panel.
Here is a very basic example for how you can use a DockPanel to do what you wish to:
<DockPanel LastChildFill="False"
VerticalAlignment="Top"
Name="TabOrderConatiner">
<TextBox Name="First" Tag="2" DockPanel.Dock="Top"></TextBox>
<TextBox Name="Third" Tag="0" DockPanel.Dock="Bottom"></TextBox>
<TextBox Name="Second" Tag="1" DockPanel.Dock="Top"></TextBox>
</DockPanel>
However it is like I said above limited compared to what TabIndex can provide.
Apart from that you should also be able to set the first TabItem when the container becomes active like that from your code-behind:
var tabOrderContainer = this.FindControl<DockPanel>("TabOrderConatiner");
var initialElement = this.FindControl<TextBox>("Third");
KeyboardNavigation.SetTabOnceActiveElement(tabOrderContainer, initialElement);
but I did not manage to get this to work...

pdfnet - re-opening a pdf after returning to a page with NavigationCacheMode.Enabled

I have 2 pages on a windows store app project.
First page displays a pdf file in a small part of the page, and i have a button that when i press i open the other page with the pdf loaded in full screen.
On page1 i have this on its constructor:
this.NavigationCacheMode = NavigationCacheMode.Enabled;
Im using PDFtron to view and edit the pdf files.
on Page1 OnNavigatedTo method i have this
pdftron.PDFNet.Initialize();
MyPDFViewCtrl = new pdftron.PDF.PDFViewCtrl();
PDFViewBorder.Child = MyPDFViewCtrl;
MyToolManager = new pdftron.PDF.Tools.ToolManager(MyPDFViewCtrl);
pdfViewer.Visibility = Visibility.Visible;
and this on xaml
<Grid x:Name="pdfViewer" Background="Blue" Canvas.ZIndex="111" Visibility="Visible" >
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Border x:Name="PDFViewBorder" Background="Green" Grid.Row="0"/>
</Grid>
to open the pdf i have something like this:
folder = await ApplicationData.Current.LocalFolder.CreateFolderAsync(Constants.DataDirectory, CreationCollisionOption.OpenIfExists);
file = await folder.CreateFileAsync(document.fileName, CreationCollisionOption.OpenIfExists);
docpdf = new PDFDoc(file);
MyPDFViewCtrl.SetDoc(docpdf);
Debug.WriteLine(MyPDFViewCtrl.GetPageCount());
So the problem is this:
When i enter page1, it displays the pdf correctly, i then press the button and navigate to page2 where it shows the file in fullscreen correctly, when i go back to previous page the file seems to be loaded correctly to the docpdf variable (it shows the correct number of pages on the Debug.WriteLine) , but it doesn't show on the MyPDFViewCtrl, i get a empty Green Square.
Do i need to enable any sort of parameter?

XAML Bind a TextBox with WebView's current URL

I am trying to make a basic browser in XAML:
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<TextBox x:Name="urlBox"
Text="{Binding ElementName=webView,Path=Source,Mode=TwoWay}"
KeyDown="OnUrlEnter" AcceptsReturn="False"
TextWrapping="Wrap"/>
<WebView Grid.Row="1" x:Name="webView"/>
</Grid>
What I want is that when a user click on a link in the WebView, the URL TextBox is updated accordingly and of course, if user enters the URL and press [Enter] button, the webView should navigate to the specified URL but I have already achieved that. I have tried handling NavigationStarting, NavigationCompleted, NavigationFailed (deprecated), LoadCompleted (deprecated) but none of them helps me get new URL whenever user click on links in the WebView. (The event handlers are only invoked once when I do webView->Navigate. Needless to say, {Binding ElementName=webView,Path=Source,Mode=TwoWay} does not seem to work.)
What should I do to synchronize the WebView's URL and the TextBox? There should be an easy way to do this.
Hi what you could use is.
expose a property
private string browserURL;
public string BrowserURL
{
get{return browserURL;}
set{ browserURL=value;
NotifyPropertyChanged("BrowserURL");
}
}
public constructor()
{
WebBrowser.Navigating += WebBrowser_Navigating;
this.DataContext= this;
}
private void TechMCaresBrowsercontroll_Navigating(object sender, NavigatingEventArgs e)
{
browserURL=e.Uri;
}
XAML Code
<TextBox x:Name="urlBox"
Text="{Binding BrowserURL}"
KeyDown="OnUrlEnter" AcceptsReturn="False"
TextWrapping="Wrap"/>
so every time the browser will be navigating to a new URL you exposed property's value would get changed calling NotifyPropertyChanged and would update your textbox.

Change ItemSize in ListPicker Windows Phone

I'm new to windows mobile apps.
I have a pivot page and inside that there is multiple pivot items.
Inside the pivot item there is list picker which values are hard coded.
If there is more items in list picker all items show in a new page by default.
My issue is since all the item font are too small when opening the screen.
How can I change the font size of list picker items when those are opening.
My code like this.
<toolkit:ListPicker Grid.Row="0" Grid.Column="2" FontSize="21" Header="" Margin="10,12,-157,12" Background="White" Foreground="Black" BorderThickness="1" >
<sys:String>Convenience Eateries (CE)</sys:String>
<sys:String>Grocery Store (GS)</sys:String>
<sys:String>Secondary Network-ASD</sys:String>
<sys:String>Secondary Network-PSD</sys:String>
<sys:String>Cash and Carry</sys:String>
<sys:String>Modern Trade-Convenience Organized</sys:String>
<sys:String>Modern Trade-Grocery independent(SMMT)</sys:String>
<sys:String>HoReCa-Leisure outlets</sys:String>
<sys:String>HoReCa-Sports Clubs</sys:String>
<sys:String>HoReCa-Night Clubs</sys:String>
<sys:String>HoReCa-Karaoke</sys:String>
<sys:String>HoReCa-Casino</sys:String>
<sys:String>HoReCa-Café and Restaurant/Pubs</sys:String>
<sys:String>HoReCa-Other</sys:String>
<sys:String>Military-Welfare Shop</sys:String>
<sys:String>Military-Canteen</sys:String>
<sys:String>Convenience Mobile Outlets</sys:String>
<sys:String>Unconventional Outlets-Wine Stores</sys:String>
<sys:String>Unconventional Outlets-Other</sys:String>
</toolkit:ListPicker>
Try using ListPickerItem children instead of strings. They should have a better default look than shown above:
<toolkit:ListPicker>
<toolkit:ListPickerItem>Bob</toolkit:ListPickerItem>
<toolkit:ListPickerItem>Betty</toolkit:ListPickerItem>
<toolkit:ListPickerItem>Frank</toolkit:ListPickerItem>
<toolkit:ListPickerItem>Frank</toolkit:ListPickerItem>
</toolkit:ListPicker>
To change how the items look in the full mode page, you need to change the ListPicker's FullModeItemTemplate property. Something like this:
<toolkit:ListPicker>
<toolkit:ListPicker.FullModeItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding}" FontSize="25" />
</DataTemplate>
</toolkit:ListPicker.FullModeItemTemplate>
<sys:String>Convenience Eateries (CE)</sys:String>
<sys:String>Grocery Store (GS)</sys:String>
<!-- Hard coded values go here, just as in your code. -->
</toolkit:ListPicker>

Bing Maps on Windows Store Apps (C#/XAML) display popup when pushpin tapped

I'm using Bing Maps in my Windows Store app, I display some pushpins with some locations on it.
What I want to do is when the user taps on a pushpin, a popup appears with some info related to the location of that push pin. something similar to the popup when the user taps on my location in Microsoft maps application
How can this be done ?
Very easy, you can use the Tapped event of your Pushpin to trigger a popup then use a MapLayer.SetPosition to position your popup see http://msdn.microsoft.com/en-us/library/hh846488.aspx
Like this
currentLocationPushpin.Tapped += Current_location_pushpin_tapped;
then
void Current_location_pushpin_tapped(object sender, TappedRoutedEventArgs e)
{
MapLayer.SetPosition(placesAroundYou,location);
MapLayer.SetPositionAnchor(placesAroundYou, new Point(-200, 40));
BingMap.Children.Add(_mapLayer);
}
Try using a Popup control or fake one like this
You can either use a Popup control (see MSDN documentation here) or toggle visibility of a Border element to fake a Popup using Visibility="Collapsed", try this
<Border Background="#FFC3C2BF" Opacity="50" Margin="38,0,0,376" BorderThickness="1" BorderBrush="Black" CornerRadius="8" HorizontalAlignment="Left" MinWidth="50" Width="126" Height="auto">
<TextBlock x:Name="PushpinText" HorizontalAlignment="Left" TextWrapping="Wrap" VerticalAlignment="Top" Foreground="Black" Padding="10,10,10,10" />
</Border>