So basically.. I added 2 new pages in a frame and when I press a button it changes frame..
But if I check a checkbox on the first page it wont be checked if I go to another page and then go back to the first one..
here is a more visual look http://recordit.co/Py3zptKLck
Source code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace CheckboxesAndPages
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void button_Click(object sender, RoutedEventArgs e)
{
main.Content = new SecondPage();
}
private void button1_Click(object sender, RoutedEventArgs e)
{
main.Content = new thirdPage();
}
}
}
There is no source code for the 2 pages.
You are giving it a new SecondPage every time
SecondPage secondPage = new SecondPage();
private void button_Click(object sender, RoutedEventArgs e)
{
main.Content = secondPage;
}
Related
I am trying to jump to an error page if reading data fails, although I thought only if usercontrol activates(eg. button pressed) can successfully navigate, but is there anyway to do it automactally?
Window
|--Page
|--Page
Windows
--Page
--Page
Code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Xml;
namespace Launcher
{
/// <summary>
/// Interaction logic for BootPage.xaml
/// </summary>
public partial class BootPage : Page
{
public BootPage()
{
InitializeComponent();
readConfig();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
bootError(1001); **//This works**
}
void readConfig()
{
string gamePath;
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load("e:\\bootstrap.xml");
XmlNodeList boot = xmlDoc.DocumentElement.SelectNodes("/config/startup/arkkdmca/boot");
foreach (XmlNode node in boot)
{
try
{
gamePath = node.SelectSingleNode("drive").InnerText + ":\\" + node.SelectSingleNode("directory").InnerText;
MessageBox.Show(gamePath);
}
catch(Exception)
{
gamePath = "null";
bootError(1001); **//This Failed**
return;
}
}
}
void bootError(int errorCode)
{
this.NavigationService.Navigate(new ErrorPage(errorCode));
}
}
}
I have a wpf MultiROIStats.dll with mode, view, ViewModel. Here is the C# of the view:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace MultiROIStats
{
using ViewModel;
//xmlns:dg="clr-namespace:Microsoft.Windows.Controls;assembly=WpfToolkit"
/// <summary>
/// Interaction logic for MultiROIStats.xaml
/// </summary>
public partial class MultiROIStats : Window
{
public MultiROIStats()
{
InitializeComponent();
DataContext = new MultiROIStatsViewModel();
}
}
}
To use this MultiROIStats,dll, I insert it info the reference of another project. Now I need to access the ViewModel (some methods there) of the inserted MultiROIStats.dll. I am wondering how should I do this? I initiated an object of the inserted MultiROIStats.dll, but cannot find the method I want to use in its ViewModel:
private void btnSave_Click(object sender, RoutedEventArgs e)
{
MultiROIStats mroi = new MultiROIStats();
mroi.Show();
// here should be mroi.viewmode.dothings() ... but I don't know how to access it
}
You should be able to get to it by casting the DataContext to the view-model type:
MultiROIStats mroi = new MultiROIStats();
mroi.Show();
var viewmodel = mroi.DataContext as MultiROIStatsViewModel;
if (viewmodel != null)
viewmodel.dothings();
var window = new MultiROIStats();
window.Show();
var vm = window.DataConntext as MultiROIStatsViewModel;
vm.DoThings();
Windows Phone 8 App
In my MainPage.xaml I have the following:
<Image HorizontalAlignment="Left" Height="215" VerticalAlignment="Top" Width="450" Margin="10,299,-40,0" Source="/Assets/Images/MTCOB.jpg"/>
What I want is for the user to tap this and then a website open in IE8.
In my MainPage.xmal.cs I have the following:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using GamesWithGold.Resources;
using Microsoft.Phone.Tasks;
using System.Windows.Interop;
namespace GamesWithGold
{
public partial class MainPage : PhoneApplicationPage
{
public MainPage()
{
InitializeComponent();
}
private void Image_Tap(object sender, System.Windows.Input.GestureEventArgs e)
{
}
}
}
.............
I am new to this so would really like some help getting my first app out in BETA.
Try this:
private void Image_Tap(object sender, System.Windows.Input.GestureEventArgs e)
{
WebBrowserTask BrowserTask = new WebBrowserTask();
BrowserTask.Uri = new Uri("http://www.google.com",UriKind.Absolute);
BrowserTask.Show();
}
I got a little problem in my program here. I am trying to add items to my datatable and then get it to show on my datagrid. I can do it with a simple code from my main page but I want an external page to send the results to me but I cant find out what I am doing wrong here.
MainWindow
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Data;
namespace Træner_Program
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
Display();
}
public DataTable dt = new DataTable();
public DataTable dtBind = new DataTable();
public void Display()
{
//I create the data in memory
//usually the date is get from DataBase and cached in memory to enhance the performance
dt = new DataTable();
dt.Columns.Add("Øvelse");
dt.Columns.Add("Vægt");
dt.Columns.Add("Sæt");
dt.Columns.Add("Gentagelser");
dt.Columns.Add("Pause");
dtBind = dt.Copy();
Binding bind = new Binding();
bind.Source = dtBind;
this.dtgPlan.SetBinding(ListView.ItemsSourceProperty, bind);
}
public void AddRow(string Øvelse, string Vægt, string Sæt, string Gentagelser, string Pause)
{
DataRow dr = dt.NewRow();
dr["Øvelse"] = Øvelse;
dr["Vægt"] = Vægt;
dr["Sæt"] = Sæt;
dr["Gentagelser"] = Gentagelser;
dr["Pause"] = Pause;
dt.Rows.Add(dr);
dtBind = dt.Copy();
Binding bind = new Binding();
bind.Source = dtBind;
this.dtgPlan.SetBinding(ListView.ItemsSourceProperty, bind);
}
private void btnGem_Click(object sender, RoutedEventArgs e)
{
//this is the working command from mainpage
//AddRow("Bænkpres", "80", "3", "10", "50");
}
private void btnTilføj_Click(object sender, RoutedEventArgs e)
{
var tilføjØvelse = new Tilføj_Øvelse();
tilføjØvelse.Show();
}
}
}
Add items
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
namespace Træner_Program
{
/// <summary>
/// Interaction logic for Tilføj_Øvelse.xaml
/// </summary>
public partial class Tilføj_Øvelse : Window
{
MainWindow mw = new MainWindow();
public Tilføj_Øvelse()
{
InitializeComponent();
}
private void btnTilføj_Click(object sender, RoutedEventArgs e)
{
mw.AddRow("Bænkpres", "80", "3", "10", "50");
Close();
}
private void btnAnuller_Click(object sender, RoutedEventArgs e)
{
Close();
}
}
}
This is because you are creating a new MainWindow instead of using the initial one that is calling the Child Window.
A simple fix could be to pass a reference of the Parent MainWindow into the Child like so:
Update the child:
public partial class Tilføj_Øvelse : Window
{
MainWindow mw;
public Tilføj_Øvelse(MainWindow mainWindow)
{
InitializeComponent();
mw = mainWindow;
}
private void btnTilføj_Click(object sender, RoutedEventArgs e)
{
mw.AddRow("Bænkpres", "80", "3", "10", "50");
Close();
}
private void btnAnuller_Click(object sender, RoutedEventArgs e)
{
Close();
}
}
and then update the call to it:
private void btnTilføj_Click(object sender, RoutedEventArgs e)
{
var tilføjØvelse = new Tilføj_Øvelse(this);
tilføjØvelse.Show();
}
Though, the best (and recommended) way is to use the MVVM pattern and create a shared ViewModel for both of these Windows.
Hi I am trying to programmatically control a WPF animation but am getting the error above, could someone help with the error - not very familiar with c# - thanks
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Media.Animation;
namespace WpfApplication10
{
///
/// Interaction logic for Window1.xaml
///
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
}
AnimationClock clock;
void StartAnimation()
{
DoubleAnimation animate = new DoubleAnimation();
animate.To = 300;
animate.Duration = new Duration(TimeSpan.FromSeconds(5));
animate.RepeatBehavior = RepeatBehavior.Forever;
clock = animate.CreateClock();
test.ApplyAnimationClock(Ellipse.WidthProperty, clock);
}
void PauseAnimation()
{
clock = new AnimationClock();
clock.Controller.Pause();
}
void ResumeAnimation()
{
clock.Controller.Resume();
}
private void button1_Click(object sender, RoutedEventArgs e)
{
PauseAnimation();
}
}
}
It means you cannot create an instance of the "clock" object using "new". You can do it using the animation.CreateClock() method like the one in your StartAnimation() method. Anyway, a little tweak on your code should make it work. Hope the code below gives you an idea:
using System;
using System.Windows.Media.Animation;
using System.Windows;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Shapes;
namespace WpfApplication10 { /// /// Interaction logic for Window1.xaml ///
public partial class Window1: Window
{
public Window1()
{
InitializeComponent();
DoubleAnimation animate = new DoubleAnimation();
animate.To = 300;
animate.Duration = new Duration(TimeSpan.FromSeconds(5));
animate.RepeatBehavior = RepeatBehavior.Forever;
clock = animate.CreateClock();
}
AnimationClock clock;
void StartAnimation()
{
test.ApplyAnimationClock(Ellipse.WidthProperty, clock);
}
void PauseAnimation()
{
clock.Controller.Pause();
}
void ResumeAnimation()
{
clock.Controller.Resume();
}
private void button1_Click(object sender, RoutedEventArgs e)
{
StartAnimation();
}
}
}