Csharp Windows phone task complete - c#

I'm making Windows universal app using Visual Studio 2013. I'm trying to accomplish something like in this article.
On the main page I have many pictures. After clicking on one of these pictures the user goes to another page, which has a check box.
After user checkes the check box, I have to change the image on main page.
I don't know if this code is correct, but I'm doing something like this for second page
private void CheckBox_Checked(object sender, RoutedEventArgs e)
{
points.Text = (Convert.ToInt32(points.Text) + 4).ToString();
var currentCheckBoxItem = sender as CheckBox;
if (currentCheckBoxItem.IsChecked == true)
{
otra.bedre1.Source = (new Uri("ms-appx:///Assets/complete.png", UriKind.Absolute));
// }
But this is code for mainpage where can choose task:
protected override void OnNavigatedTo(NavigationEventArgs e)
{
bedre1.Source = ImageSource;
}
Any ideas?

You would need to store the name and Checkstatus as fields inside SQlite database so that its available even after the app is closed. So you would need to do some research on it.

Related

How to use CoreWebView2Frame Class in windows application

I have a windows webview2 application where we are automating 3rd party website with too many nested iframes and I want to execute javascript in a particular iframe. I want to know how get CoreWebView2Frame instance for the particular iframe using WebView2. Microsoft documentation didn't help.
I am looking for an example or a documentation to work with CoreWebView2Frame Class and shows how to execute javascript in a particular iframe by using CoreWebView2Frame.ExecuteAsync().
I have gone throught the this thread but it's too difficult for me to understand.
You can get a CoreWebView2Frame by handling FrameCreated event and use it later.
Example:
In the following example, the WebView2 browses this Uri, then we find the iframe inside the page, and store it for later use. Later when the user clicks on a button on the WinForms app, using ExecuteScriptAsync method of the iframe, we click on a link inside the iframe programmatically.
To do so, drop a WebView2 and a Button on the form. Handle Load event of the form and Click event of the button and modify the code like this:
//using Microsoft.Web.WebView2.Core;
CoreWebView2Frame sampleFrame;
private async void Form1_Load(object sender, EventArgs e)
{
webView21.Source = new Uri(
"https://www.w3schools.com/tags/tryit.asp?filename=tryhtml_link_test");
await webView21.EnsureCoreWebView2Async();
webView21.CoreWebView2.FrameCreated += CoreWebView2_FrameCreated;
}
private void CoreWebView2_FrameCreated(object? sender,
CoreWebView2FrameCreatedEventArgs e)
{
if (e.Frame.Name == "iframeResult")
{
sampleFrame = e.Frame;
}
}
private async void button1_Click(object sender, EventArgs e)
{
if (sampleFrame != null && sampleFrame.IsDestroyed() == 0)
{
await sampleFrame.ExecuteScriptAsync(
"document.getElementsByTagName('a')[0].click();");
}
}
Now if you click on the button, the link which is inside the iframe will be clicked.

How to switch tabs with button in a TabControl?

I've watched a few tutorials online on how to change tabs using buttons but for some reason all the code I've tried doesn't work. I am currently running Microsoft Visual Studio 2017 and am trying to write some code for a button to change tabs.
I couldn't find any differences between my code and code shown in tutorials, so it may just be a Visual Studio setting that I haven't set up correctly to allow the button correctly, but I couldn't figure out if or where it may be.
Here's my current code:
//Element event handlers
public Form1()
{
InitializeComponent();
}
private void buttonStart_Click(object sender, EventArgs e)
{
tabControl.SelectedTab = DestSelect;
}
private void buttonGotoIntro_Click(object sender, EventArgs e)
{
tabControl.SelectedTab = Intro;
}
//An old computer-generated segment code for the previous button.
//When I try to remove it the computer gets mad at me.
private void GotoIntro_Click(object sender, EventArgs e)
{
}
Please confirm you have subscribed to the Click event for the buttons.
public Form1()
{
InitializeComponent();
buttonStart.Click += buttonStart_Click;
buttonGotoIntro.Click += buttonGotoIntro_Click;
}
Instead of 'tabControl.SelectedTab = DestSelect;" try instead the method 'tabControl.SelectTab(DestSelect);'
I read through this article to find your (hopefully) answer:
https://social.msdn.microsoft.com/Forums/vstudio/en-US/2cf22896-c5bd-4a9b-ab61-34404b55ef01/how-to-jump-to-a-specific-tab-in-the-tabcontrol?forum=vbgeneral
I assume u want to select a tab when a different Button is clicked.
tabControl.SelectedIndex = [Index of tab to switch to];
Code should look like;
tabControl.SelectedIndex = feeTabIndex;
If this is not clear enough, tell me exactly what you want to do.

C# Windows form new page

I'm trying to make a button on my windows form create a new page when clicked, something like when you are going through an installation of a program and you would click "Next" and it would take you to a new page but not bring up an entirely seperate window. I would also have another button that would be pressed to bring up the original form.
I've looked everywhere for a answer to this so any help on how I would create this would be greatly appreciated.
private void Cleaning_Click(object sender, EventArgs e)
{
// executes new page
}
What you want to do is to create a wizard. There are lot of samples on internet regarding that. Take a look;
http://www.codeproject.com/Articles/31770/Wizard-Form-Implementation
Or
You can see that SO question
Creating Wizards for Windows Forms in C#
One simple way is to use panels in a single form. The only problem with panels is that it is hard to edit the layout and also your code would become very messy.
it IS simple BUT has a very bad downside
Simply we can add one groupbox and add your controls, in form load set groupbox visible to false and button click event visible to true something like....
private void Form3_Load(object sender, EventArgs e)
{
groupBox1.Visible = false;
}
private void button1_Click_1(object sender, EventArgs e)
{
if (button1.Text == "&Show")
{
button1.Text = "&Hide";
groupBox1.Visible = true;
}
else if (button1.Text == "&Hide")
{
button1.Text = "&Show";
groupBox1.Visible = false;
}
}

WP8 - How to create and open a WebBrowser in Windows Phone 8 only through C#

I am new to windows Phone development, so please excuse my ignorance.
I need to create and open a WebBrowser on a button click (button created on xaml page) in C# code. I have seen so many examples where the WebBrowser is created in XAML and Navigate is called in C#. But my requirement is to create a complete screen on button click.
Can anyone help me with this ? Any level of guidance would be helpful.
From the top of my head and assuming the main grid is named "LayoutRoot":
private void btnOpenAndGo_Click(object sender, RoutedEventArgs e)
{
WebBrowser web = new WebBrowser();
web.Height = LayoutRoot.Height;
web.Width = LayoutRoot.Width;
LayoutRoot.Children.Add(web);
web.Navigate(...);
}
Edit: To control the hardware back button. Override OnBackKeyPress. And do something like this:
protected override void OnBackKeyPress(CancelEventArgs e)
{
base.OnBackKeyPress(e);
if (web.Visibility = Visibility.Visibile)
{
web.Visibility = Visibility.Collapsed;
e.Cancel = true;
}
}
JonPall's Answer is nice, and if you want to open you uri in IE, try this method:
using namespace : Microsoft.Phone.Tasks
WebBrowserTask task = new WebBrowserTask();
task.URL = "http://yoururl.com";
task.Show();

Windows 8 navigation, passing an URI as parameter

I just started developing for windows 8, and I'm having some difficult in passing parameters in navigation between pages.
What I am trying to do is: I have two pages (page1 and page2) In page1, there's a menu with a button. When I click in this button, the click event should pass as a parameter an possible URI or path, that will set the source of a image in page2.
this is the code in page1:
private void Button_Click_2(object sender, RoutedEventArgs e)
{
//this.Frame.Navigate(typeof(SplitPage), "ms-appx:/Imgs/1.png");
this.Frame.Navigate(typeof(SplitPage), new Uri("ms-appx:/Imgs/1.png", UriKind.RelativeOrAbsolute));
}
and page2, for receiving the Uri:
protected override void OnNavigatedTo(NavigationEventArgs e)
{
var imgSource = e.Parameter as ImageSource;
this.imgParaPintar.Source = imgSource;
}
I'm noticing that imgSource is receiving nothing, it keeps as null.
So, any clues on what I'm doing wrong or what I am missing?
I think you need code like this (untested):
protected override void OnNavigatedTo(NavigationEventArgs e)
{
this.imgParaPintar.Source = new BitmapImage((Uri)e.Parameter);
}
You might need to add using Windows.UI.Xaml.Media.Imaging; to your file, if you don't have it there already.
It's worth noting, as stated in the comments here:
http://answers.flyppdevportal.com/categories/metro/csharpvb.aspx?ID=4b847d71-9cd5-4457-add9-f68e457b23ff
That you can only pass primitive types as navigation parameters.

Categories

Resources