Navigate to a xaml page from the isolated storage - windows-phone-7

I would like to know if anyone has done this before or tried to do it. I would like to navigate from my current page to a page generated and stored on the isolated storage.
Is that possible?
I already found a way of generating the xaml code and I'm working on generating the xaml.cs file but I can't seem to find a way of navigating to the newly created and existing file in the isolated storage.
I am using the "isostore" URI schema but it throws an exception in RootFrame_NavigationFailed:
[System.InvalidOperationException] = {"No XAML was found at the location '/isostore;/screenTest.xaml'."} . Thank you in advance.
Best regards,
Cipri

I think the closest you can get is:
Store usercontrols (rather than pages) in the isolated storage
Load them using XamlReader.Load
Inject the loaded UserControl inside of the current page
Drawbacks:
You can forget about the code-behind file as you can't compile it. You'll have to find another way to wire-up the events. I suggest taking a MVVM approach, by binding actions and using the same viewmodel for every usercontrol
You're not using the NavigationService, so you have to handle the navigation stuff (back button and application resuming after tombstoning)

public MainPage()
{
InitializeComponent();
this.Loaded += new RoutedEventHandler(MainPage_Loaded);
}
void MainPage_Loaded(object sender, RoutedEventArgs e)
{
string UserName;
IsolatedStorageSettings.ApplicationSettings.TryGetValue<string>("UserName", out UserName);
if (!string.IsNullOrEmpty(UserName))
{
txtUserName.Text = UserName;
txtPassword.Focus();
}
else
txtUserName.Focus();
}
private void btnLogin_Click(object sender, RoutedEventArgs e)
{
IsolatedStorageSettings.ApplicationSettings["UserName"] = txtUserName.Text;
}

Related

Windows Forms infinite loop exception

I quickly made a Windows Forms project which loads a GUI of different textboxes with float values. Some of them do have already a value initialized. All textboxes have to be updated after one of them is changed.
public Form1()
{
InitializeComponent();
initializeValues();
calculateValues();
}
public void initializeValues()
{
//textboxes are filled/initialized with default float values
}
public void calculateValues()
{
//here all textboxes are new calculated and updated
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
calculateValues();
}
private void textBox2_TextChanged(object sender, EventArgs e)
{
calculateValues();
}
Problem:
When I execute this project, it throws me a StackOverflowException which is unhandeled (infinite loop or infinite recursion). I think it's because during the calculateValues() method the text of the textBoxes will be changed and then the Eventhandlers are activated. That's the infinite loop :-(
How I have to change my code construct above to avoid this?
Thanks.
You should not using and calling "initializeValues();" (the cause of the infinite loop).
A first solution could be to put the init value of a TextBox in InitializeComponent :
MyTextBox.Text = myInitValue;
I solved the problem by changing the Event to "KeyPress". In this case, the Event is not activated by the method itself. No more infinite loops. Setting breakpoints and step through helped me to understand "the flow". Thanks CodeCaster.

Manipulation_started doesn't work on a map

Hi to all I'm trying to set a listener for the ManipulationStarted, ManipulationDelta, ManipulationCompleted of a map to detect if the user drag a map around, but looks like none of those events are launched if I drag the map. If I set a tap listener for the map ManipulationStarted is correctly launched.
What I'm doing wrong?
xaml code:
<Controls:Map x:Name="myMap"
Grid.Row="0"
Loaded="myMap_Loaded"
ManipulationDelta="myMap_ManipulationDelta"
ManipulationCompleted="myMap_ManipulationCompleted"
ManipulationStarted="myMap_ManipulationStarted"
Tap="myMap_Tap">
code behind:
private void myMap_ManipulationDelta(object sender, System.Windows.Input.ManipulationDeltaEventArgs e)
{
Debug.WriteLine("Event:: MyMap_manipulationdelta");
}
private void myMap_ManipulationCompleted(object sender, System.Windows.Input.ManipulationCompletedEventArgs e)
{
Debug.WriteLine("Event:: MyMap_manipulationcompleted");
}
private void myMap_ManipulationStarted(object sender, System.Windows.Input.ManipulationStartedEventArgs e)
{
Debug.WriteLine("Event:: MyMap_manipulationstarted");
}
private void myMap_Tap(object sender, System.Windows.Input.GestureEventArgs e)
{
Debug.WriteLine("Event:: MyMap_tap");
}
I'm on a normal page, no pivot or panorama.
I'm afraid that you won't be able to handle those events because Map control intercepts them. Although there is a property UseOptimizedManipulationRouting, but as I've tested it - it doesn't help much in this situation.
I dont't know what you are trying to achieve, but if you don't need ManipulationDeltaEventArgs then maybe you consider using different events such as: MouseEnter, ResolveCompleted and CenterChanged.
If you need them then as JustinAngel suggested here you can follow these instructions and use Touch.FrameReported event for your purpose.
EDIT - code sample
If I've understood you properly, you would like to know when the User touches the Map, MouseEnter won't be the best choice as it will work only first time, then if mouse didn't leave the Map (user touched somewhere else), it won't fire again. Better solution here (following instructions above) can be such a code:
public MainPage()
{
InitializeComponent();
Touch.FrameReported += Touch_FrameReported;
}
private void Touch_FrameReported(object sender, TouchFrameEventArgs e)
{
TouchPoint point = e.GetPrimaryTouchPoint(myMap);
if (point.Action == TouchAction.Move && point.Position.Y > 0)
{
MessageBox.Show("User is Moving Finger over the Map!");
}
}

Outlook Add-In - Enable/Disable Button during Runtime/from Code

Initial Situation:
We are developing an Add-in for Outlook 2010 in C# with VS.NET 2010 based on Framework 4.0, VSTO, DevExpress WinForm Controls. In Designer we have a Ribbon with a RibbonTab, then a RibbonGroup then a RibbonButton. We're consuming WebServices from within this Outlook Add-in.
Objective:
We need to enable/disable the RibbonButtons when the WebService is available/unavailable (from/out of the code)
we've found the following links:
Links
Ribbon Object Model Overview: http://msdn.microsoft.com/en-us/library/bb608623.aspx
Ribbon Overview: http://msdn.microsoft.com/en-us/library/bb386097.aspx
Walkthrough: Updating the Controls on a Ribbon at Run Time: http://msdn.microsoft.com/en-us/library/bb608628.aspx
After hours of trying to figure out how to implement this we deciced to post/ask this question here on SO. Does anybody have a sample code? We tried the IRibbonExtensibility and CreateRibbonExtensibilityObject => we added the RibbonTab, Group and Button and added a subscription to the Click Event => The Event is fired but not handled (in button_Click(...) => System.Diagnostics.Debugger.Break() is not breaking the code execution)
Thanks!
Christian
You'll want to invalidate the Ribbon at a fairly frequent rate in order to refresh the visibility of each tab/button. You can do this by subscribing to the Click event (as you've done) and then calling RibbonObject.Invalidate();. Then add a getEnabled="yourTestFunction" parameter to each button, with public bool yourTestFunction(Office.IRibbonControl control) (Defined in the Ribbon.cs file) returning whether the web service is available or not.
Keep in mind if the web service is down, each click could hang your application for the amount of time you set on your timeout in the web service check
Edit:
Just realized the _Click event isn't mapped in the Excel COM library, so here's a bit of code that will run each time the cell selection is changed (not as frequent as every click, but hopefully good enough).
ThisAddIn.cs:
public static Excel.Application e_application;
public static Office.IRibbonUI e_ribbon;
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
e_application = this.Application;
e_application.SheetSelectionChange += new Excel.AppEvents_SheetSelectionChangeEventHandler(e_application_SheetSelectionChange);
}
void e_application_SheetSelectionChange(object Sh, Excel.Range Target)
{
e_ribbon.Invalidate();
}
private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
{
e_application.SheetSelectionChange -= new Excel.AppEvents_SheetSelectionChangeEventHandler(e_application_SheetSelectionChange);
e_application = null;
}
Ribbon1.cs:
public void Ribbon_Load(Office.IRibbonUI ribbonUI)
{
this.ribbon = ribbonUI;
ThisAddIn.e_ribbon = ribbonUI; //Add this line
}
and
public bool getEnabledTest(Office.IRibbonControl control)
{
//Whatever you use to test your Web Service
//return false;
}
Ribbon1.xml:
<button id="WebService" label="Use The Web Service" onAction="executeWebService" getEnabled="getEnabledTest" />
The following article titled Adding Custom Dynamic Menus to the Office Fluent User Interface will point you in the right direction.
The below is an example of a dynamically created menu, you can modify the tutorial to fit your particular need.
ok, thanks for the tips. Finally i solved it like this:
i declared a static ribbon object like:
public static RibbonIet ribbon {get; set; }
in the load event of the Ribbon i assign the Ribbon (this) like:
Session.Common.ribbon = this;
now i can control the RibbonButton like:
Session.Common.ribbon.buttonCreateIncident.Enabled = true;
Since the webService call is running in a seperate thread, i had to use a MethodInvoker to change enable/disable the buttons. it goes like this:
If (InvokeRequired)
{
Invoke(new MethodInvoker(() => Session.Common.ribbon.buttonCreateIncident.Enabled = true));
}
maybe this is of help for someone else.

PhotoChooserTask.Completed not fired

I'm trying to using PhotoChooserTask for our purposes.
After calling photoChooserTask.Show() chooser is showed but when I choose a picture it's closing and event Completed not fired !
Why?
And more, after that PhotoChooserTask not showed next time when calling Show.
P.S. if i try this code in new solution - it will work fine, but why it doesn't work in our project?
PhotoChooserTask photoChooserTask;
private void button2_Click(object sender, System.Windows.RoutedEventArgs e)
{
photoChooserTask = new PhotoChooserTask();
photoChooserTask.Completed += new EventHandler<PhotoResult>(photoChooserTask_Completed);
photoChooserTask.Show();
// TODO: Add event handler implementation here.
}
void photoChooserTask_Completed(object sender, PhotoResult e)
{
//Bla bla bla
}
I solved this problem.
So, project CAN NOT have more than one photo chooser.
You can't declare PhotoChooserTask in Page1 and Page2 with different logic of processing.
Hope this will helpfull for someone.
You should make sure that you respect the guidelines for creating and initializing the object:
To ensure that your application receives the result of the
PhotoChooserTask, the object must be declared with class scope
within the PhoneApplicationPage class and you must call the chooser
constructor and assign the Completed event delegate within the page’s
constructor.
Source

Can't tombstone ItemsSource of a ListBox

I have a ListBox populated with data coming from XML.
Fine so far, the problem is that I get some errors when I try to tombstone it.
protected override void OnNavigatedFrom(System.Windows.Navigation.NavigationEventArgs e)
{
State["listbox1"] = listBox1.ItemsSource;
}
Then:
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
if (State.ContainsKey("listbox1"))
{
listBox1.ItemsSource = (IEnumerable)State["listbox1"];
}
}
When I hit the start button I already get an error. The App.xaml.cs opens and the line below becomes yellow
System.Diagnostics.Debugger.Break();
I've also used tombstoning helper but it did not return the items in my listbox.
What is the listbox bound to? And what error are you seeing?
If it's a DataServiceCollection, you may have tracking turned on & you cannot put it flatly in Isolated Storage or State dictionaries. Should be fine if using ObservableCollection.
Thanks!

Resources