i'm working on a windows phone 7 emulator. I have a web browser which navigates to local host. So my problem i faced was that when i tilt the windows phone 7 emulator 90% right, the screen doesn't. Could there be any advice on how to do so?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
namespace DSP
{
public partial class MainPage : PhoneApplicationPage
{
// Constructor
public MainPage()
{
InitializeComponent();
}
private void ContentPanel_Loaded(object sender, RoutedEventArgs e)
{
MessageBox.Show("Loading website. This might take a few seconds...");
webBrowser1.Navigate(new Uri("http://localhost/Liweiyi_fyp_082648y/homepage.html", UriKind.Absolute));
}
private void webBrowser1_Loaded(object sender, RoutedEventArgs e)
{
}
}
}
Check your SupportedOrientations is PortraitOrLandscape in your xaml.
Also check your emulator isn't orientation locked due to hardware keybaord emulation. Restart it if you're not sure how to fix that.
I believe you're looking for how to handle orientation changes on the phone?
You're looking to change the following in the .xaml for the appropriate page - most likely MainPage.xaml:
Change the highlighted line to read
SupportedOrientations="PortraitOrLandscape"
And in case that wasn't enough information, here's a helpful blogpost.
Related
I’m trying to establish a connection with a Web Service already running with Visual Studio 2019 community. The connection is already establish on Visual Studio but when trying to use it I got CS0119 error ‘UsuariosSoap’ is a type, which is not valid int given context.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
using System.Net;
using UsuarioWS;
namespace XamarinWSMobile
{
// Learn more about making custom code visible in the Xamarin.Forms previewer
// by visiting https://aka.ms/xamarinforms-previewer
[DesignTimeVisible(false)]
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
}
private void AnadirUsuario(object sender, EventArgs e)
{
//establece la conexion con el web service
UsuarioWS.UsuariosSoap usuarioWS = UsuarioWS.UsuariosSoap;
usuarioWS.GuardarUsuarioAsync(this.Nombre.Text, this.Apellidos.Text,this.Direccion.Text, this.Pueblo.Text, this.ZipCode.Text, this.FechaNac.Text);
}
}
}
That error is telling UsuariosSoap is a Type so this is wrong:
UsuarioWS.UsuariosSoap usuarioWS = UsuarioWS.UsuariosSoap;
In order to use it, you need to create an instance of the service, the UsuariosSoap class, before using it.
Replace the line above with this:
UsuarioWS.UsuariosSoap usuarioWS = new UsuarioWS.UsuariosSoap();
Hope this helps.-
I created a c program which has infinite loop.It runs fine.I also created c# program which has infinite loop.While the form ran,latter program process stopped responding.Why does both behaves differently?
Below are the codes
#include<stdio.h>
int main()
{
int i;
for(i=0;i>=10;i++){
printf("%d",i);
}
return 0;
}
c# program:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
int i=10;
while (i > 1)
{
//do nothing
}
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
}
My question is how infinite loops work in these two programs?
Your C# program is in a form. Windows expects the form to be able to process events (e.g. telling it to close) but it can't because it's in the infinite loop.
If the infinite loop was in its own thread, or you wrote a C# console application instead of a form-based one, I think it would behave more like your C.
I use Visual Studio 2005 to develop a "Windows Service" using c#.net. My code requires to access the MS office Clipboard. But on trying to access the Clipboard class, the debugger throws an error
"Current thread must be set to single thread apartment (STA) mode before OLE calls can be made. Ensure that your Main function has STAThreadAttribute marked on it."
during the run-time. On checking for the solutions, I found that this could be solved by adding "[STAThread]" before the main method. But on adding this, I get a compilation error
"The type or namespace name 'STAThread' could not be found (are you missing a using directive or an assembly reference?)"
Is it possible to access the clipboard with my current version of .NET(.NET 3.0)?
The main method is in a file titled "program.cs" and the logic is in a file titled "Service.cs". Clipboard is used by Service.cs.
/* Program.cs */
using System.Collections.Generic;
using System.ServiceProcess;
using System.Text;
using System.Media;
using System.Threading;
namespace WindowsService1
{
static class Program
{
[STAThread]
static void Main(string[] args)
{
#if DEBUG
Service1 serv = new Service1();
serv.onDebug();
System.Threading.Thread.Sleep(System.Threading.Timeout.Infinite);
#else
ServiceBase[] ServicesToRun;
ServicesToRun = new ServiceBase[] { new Service1() };
ServiceBase.Run(ServicesToRun);
#endif
}
}
}
/* Service.cs */
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.ServiceProcess;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Threading;
using System.Timers;
namespace WindowsService1
{
public partial class Service1 : ServiceBase
{
public Service1()
{
InitializeComponent();
}
public void onDebug()
{
OnStart(null);
}
protected override void OnStart(string[] args)
{
clear_cb();
}
protected void clear_cb()
{
Clipboard.Clear(); // This is the line where I get the exception
}
protected override void OnStop()
{
// TODO: To clear the back up Database
}
}
}
I'm writing my first app for windows phone, which will be a sound board, using XNa's soundeffect object.
The project is a Windows phone Silverlight and Xna Application c#
I got some sample code from the book, 101 phone 7 apps.
The linbe to load in the sound gives me a
"the type StreamResourceInfo namespace could not be found"
StreamResourceInfo info = Application.GetResourceStream(new Uri("Audio/cowbell.wav", UriKind.Relative));
the code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using Microsoft.Xna.Framework.Audio;
namespace SlXnaApp4
{
public partial class MainPage : PhoneApplicationPage
{
SoundEffect cowbell;
// Constructor
public MainPage()
{
// Load sound file
StreamResourceInfo info = Application.GetResourceStream(new Uri("Audio/cowbell.wav", UriKind.Relative));
// create xna sound
cowbell = SoundEffect.FromStream(info);
// Sub to per frame call back
CompositionTarget.Rendering += CompositionTarget_Rendering;
// requred for xna sound effects to work
Microsoft.Xna.Framework.FrameworkDispatcher.Update();
// testb sound
cowbell.Play();
InitializeComponent();
}
void CompositionTarget_Rendering(object sender, EventArgs e)
{
Microsoft.Xna.Framework.FrameworkDispatcher.Update();
}
// Simple button Click event handler to take us to the second page
private void Button_Click(object sender, RoutedEventArgs e)
{
NavigationService.Navigate(new Uri("/GamePage.xaml", UriKind.Relative));
}
private void button1_Click(object sender, RoutedEventArgs e)
{
}
}
}
Add a using directive for System.Windows.Resources:
using System.Windows.Resources;
Hi I'm working to develop a solution to creating a toolbar in Outlook 2010 using VSTO 2012 and the microsoft outlook 2010 addin. In a nutshell I am able to create the Outlook ribbon and a button but I am unable to get the button to open an .oft file. In Visual Studio I get the following error "The name 'application' does not exist in the current context". I have added a reference to the Microsoft Office 14.0 Object Library also. Below is the code...
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using Outlook = Microsoft.Office.Interop.Outlook;
using Office = Microsoft.Office.Core;
using Microsoft.Office.Tools.Ribbon;
namespace OutlookAddIn8
{
public partial class Ribbon1
{
private void Ribbon1_Load(object sender, RibbonUIEventArgs e)
{
}
private void CreateItemFromTemplate()
{
Outlook.Folder folder =
Application.Session.GetDefaultFolder(
Outlook.OlDefaultFolders.olFolderDrafts) as Outlook.Folder;
Outlook.MailItem mail =
Application.CreateItemFromTemplate(
#"c:\ivy.oft", folder) as Outlook.MailItem;
mail.Subject = "Congratulations";
mail.Save();
}
private void button1_Click(object sender, RibbonControlEventArgs e)
{
}
}
}
Thanks any help is appreciated it is probably something simple thats been missed.
An instance of Application can be accessed using Globals.ThisAddIn.Application. If you renamed your AddIn class to something different e.g. MyAddIn then the command will be: Globals.MyAddIn.Application.
Here is a link with more details: http://msdn.microsoft.com/en-us/library/vstudio/bb157876(v=vs.100).aspx
Finally got there in the end, heres the code.....
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Office.Tools.Ribbon;
using Outlook = Microsoft.Office.Interop.Outlook;
namespace OutlookAddIn3
{
public partial class Ribbon1
{
private void Ribbon1_Load(object sender, RibbonUIEventArgs e)
{
}
private void button1_Click(object sender, RibbonControlEventArgs e)
{
Outlook.Application Application = Globals.ThisAddIn.Application;
Outlook.MailItem mail =
Application.CreateItemFromTemplate(
#"Z:\Transfer\Outlook 2010 Templates\testsubject.oft") as Outlook.MailItem;
mail.Display(true);
}