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

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?

Related

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.

Keep element in view while scrolling

Simpel question, I have a windows phone page that contains a scrollviewer with inside it an image, a textblock and a richtextbox.
Now when the user starts scrolling I want to keep the textblock in view on top when the image has scrolled outside the page.
So the effect is, user starts scrolling upwards, everything scrolls upwards, when the image is outside the page, the textblock stays at the top of the page but the richtextbox keeps scrolling upwards.
Any thoughts?
Here is a way to reach this result:
First, the layout. I've set a grid, with two rows. The first is empty, and will host the header when we need to freeze it. The second row contains the scrollviewer.
Inside the scrollviewer, I've put the controls in a grid, but you can use whatever container suits you.
<ScrollViewer Grid.Row="1"
Margin="0"
Padding="0"
x:Name="ParentScroll"
ManipulationMode="Control"
MouseMove="ParentScroll_MouseMove">
<Grid x:Name="ChildGrid">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition />
</Grid.RowDefinitions>
<Image Source="Picture.jpg" Grid.Row="0"/>
<TextBlock Text="Header" Grid.Row="1" x:Name="TextHeader" />
<RichTextBox Grid.Row="2" x:Name="RichText">
<Paragraph>
<Bold>RichTextBox</Bold>
<!-- More stuff -->
</Paragraph>
</RichTextBox>
</Grid>
</ScrollViewer>
I use the MouseMove event to be notified of the scrolling event. You can also dig into the template, extract the ScrollBar control, and subscribe to the ValueChanged event, as described here: http://social.msdn.microsoft.com/Forums/wpapps/en-US/81fcd34e-6ec9-48d0-891e-c53a53344553/scrollviewer-synchronization
Note that you need to set ManipulationMode to Control or the position of the controls won't be updated at a smooth rate. I guess it's due to some internal optimization.
In the code behind, I use the TransformToVisual method to compute the relative position of the controls to the ScrollViewer. This way, I can know when the header goes out of view. When it does, I remove it from the child grid, and put it outside of the ScrollViewer, in the parent grid. When the top of the RichTextBox goes out of view, I put the header back into the ScrollViewer:
private void ParentScroll_MouseMove(object sender, System.Windows.Input.MouseEventArgs e)
{
if (Grid.GetRow(this.TextHeader) == 1)
{
var generalTransform = TextHeader.TransformToVisual(ParentScroll);
var childToParentCoordinates = generalTransform.Transform(new Point(0, 0));
if (childToParentCoordinates.Y < 0)
{
this.ChildGrid.Children.Remove(this.TextHeader);
this.ParentGrid.Children.Add(this.TextHeader);
Grid.SetRow(this.TextHeader, 0);
}
}
else
{
var generalTransform = RichText.TransformToVisual(ParentScroll);
var childToParentCoordinates = generalTransform.Transform(new Point(0, 0));
if (childToParentCoordinates.Y > 0)
{
this.ParentGrid.Children.Remove(this.TextHeader);
this.ChildGrid.Children.Add(this.TextHeader);
Grid.SetRow(this.TextHeader, 1);
}
}
There may be less-hacky ways to reach the same results, but this solution seems to work smoothly in the emulator.
I've found a working solution myself... the complete detail is available on my blog here... it contains also the link to my demo project on GitHub.
The trick was to get hold of the VerticallScrollBar inside the ScrollViewer and to set the ManipulationMode to Control to get enough feedback on the UI thread.
With the scroll offset information of the scrollbar we than animate the specific ui element we want to keep in view.

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!!!

Navigate to the last frame from SwapChainBackgroundPanel

I am writing a Windows Store app using C++/XAML with DirectX interop - SwapChainBackgroundPanel.
The application is based on the template "Split Page". From each list view item, a DirectX page may be launched using code below.
Window::Current->Content = ref new MyD3Components::DirectXPage();
Window::Current->Activate();
This is working fine and DirectX page opens up and plays very well.
What I would like to have a button in the app bar which helps user to go back and display the "Split Page" to allow selecting another DirectX page. This I have not been able to accomplish yet.
Among several things I have tried, below is the most logical one to my opinion. It gives a "Platform::DisconnectedException" when user wants to go back to the last page.
Windows::UI::Xaml::Controls::Frame^ rootFrame = SDL::App::GetRootFrame();
Window::Current->Content = rootFrame;
Window::Current->Activate();
Please look to see if you have a suggestion or better a solution.
Here the sample example for your question :
What i am creating : 2 pages...
You will have (go to page 2)link on page 1...If u click that,the second page should appear that says "Page 2" at the top. Notice that there is a back button to the left of the page title. Click the button to return to the first page...
1.) Find the TextBlock element named pageTitle and change the Text property to Page 1. The XAML should look like this:
<TextBlock x:Name="pageTitle" Grid.Column="1" Text="Page 1"
Style="{StaticResource PageHeaderTextStyle}"/>
2.)Add the following XAML as a second child element to the root Grid. The StackPanel element should be a sibling to the Grid that contains the back button and page title.
<StackPanel Grid.Row="1"
Margin="120,0,120,60">
<HyperlinkButton Content="Click to go to page 2" Click="HyperlinkButton_Click_1"/>
</StackPanel>
3.)Make the following changes to BasicPage2.xaml.
Find the TextBlock element named pageTitle and change the Text property to Page 2. The XAML should look like this:
<TextBlock x:Name="pageTitle" Grid.Column="1" Text="Page 2"
Style="{StaticResource PageHeaderTextStyle}"/>
4.)Add the following XAML as a second child element to the root Grid. The StackPanel element should be a sibling to the Grid that contains the back button and page title.
<StackPanel Grid.Row="1"
Margin="120,0,120,60">
<TextBlock HorizontalAlignment="Left" Name="tb1" Text="Hello World!"/>
</StackPanel>
5.)Add the following code to the BasicPage1 class in BasicPage1.Xaml.cs
private void HyperlinkButton_Click_1(object sender, RoutedEventArgs e)
{
this.Frame.Navigate(typeof(BasicPage2));
}
6.)Now that we've prepared the new pages, we need to make BasicPage1 the first thing that appears when the app starts. Open app.xaml.cs and change the OnLaunched method to call Frame.Navigate by using BasicPage1 instead of the BlankPage. The entire OnLaunched method should look like the following:
protected override void OnLaunched(LaunchActivatedEventArgs args)
{
// Create a Frame to act navigation context and navigate to the first page
var rootFrame = new Frame();
rootFrame.Navigate(typeof(BasicPage1));
// Place the frame in the current window and ensure that it is active
Window.Current.Content = rootFrame;
Window.Current.Activate();
}
Now you are ready to test the app. Start the app, and click the link that says Click to go to page 2. The second page should appear that says "Page 2" at the top. Notice that there is a back button to the left of the page title. Click the button to return to the first page.
Thats it! hope it helps u.
After a bit of trial and error, I am in the position to answer my own question. It seems that all I needed to do was to remove my rendering callbackfrom the CompositionTarget.
It was added like below.
m_eventToken = CompositionTarget::Rendering::add(ref new Windows::Foundation::EventHandler<Object^>(this, &DirectXPage::OnRendering));
Before replacing the current window and activating it, I called below.
CompositionTarget::Rendering::remove(m_eventToken);
I guessed this helped DirectX not to output to rendering pipeline and complain (disconnectedexception) when the target is not there.

Creating a login page for Win 8 apps

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.