I try to make a simple weather aplication but i get an exception.
I have location activated. I try to run in emulator for phone, not working
the exception
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
namespace TryToMakeWeatherApp
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
}
private async void Button_Click(object sender, RoutedEventArgs e)
{
var pos = await LocationManage.GetLocation(); //Here i'm geting the error
var lat = pos.Coordinate.Latitude;
var lon = pos.Coordinate.Longitude;
var weather = WeatherMap.GetWeather(lat, lon).ToString();
WeatherTxt.Text = weather;
}
}
}
This is code from MainPage.
And this is the LocationManage class
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.Devices.Geolocation;
namespace TryToMakeWeatherApp
{
class LocationManage
{
public async static Task<Geoposition> GetLocation()
{
var accessStatus = await Geolocator.RequestAccessAsync();
var geolocator = new Geolocator { DesiredAccuracyInMeters = 0 };
var position = await geolocator.GetGeopositionAsync();
return position;
}
}
}
in your package.manifest file have to turn on this capability too
Related
Is there any way to detect upi:// URL in Xamarin forms PCL? I have tried below code but no success yet.
Note: Not looking for android and iOS based solution in this case.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
namespace xamaringformwithIntentUPI
{
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
MyWebview.Source = "https://payment1.atomtech.in/paynetz/epi/fts?login=1191&pass=NCA#1234&ttype=NBFundTransfer&prodid=NCA&amt=1.00&txncurr=INR&txnscamt=0&clientcode=007&txnid=T2&custacc=1234567890&date=26/06/2018&ru=https://payment.atomtech.in/paynetzclient/ResponseParam.jsp&signature=b8f1c0972cd5f664a5fb41e0b3e5860a3c3bfd66835e5635940cf38245b234063090669ad691b6d6265491bf0510ea07d890530bd5b6309d31c81294b8f122ce&udf2=sagar#gmail.com&udf3=8888888888";
MyWebview.Navigating += Webview_Navigating;
}
private void Webview_Navigating(object sender, WebNavigatingEventArgs e)
{
var url = e.Url;
Console.WriteLine("url detected = " + url);
if (url.StartsWith("upi://"))
{
Console.WriteLine("upi url detected = ");
Console.WriteLine(url);
}
}
}
}
I have two forms in a Windows Forms project: Form1 and aCurso.
I'm trying to send a List with objects of a class called curso (I mean: List<curso>) from Form1 to aCurso.
But Visual Studio show this:
Accessibility inconsistency: The type of parameter List<curso> is less accessible than the method aCurso.aCurso(List<curso>).
So, here is the code from Form1:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace _18_05_18
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
List<curso> cursos = new List<curso>();
private void btnAC_Click(object sender, EventArgs e)
{
Form f = new aCurso(cursos);
f.Show();
}
}
}
Here's code from aCurso:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace _18_05_18
{
public partial class aCurso : Form
{
List<curso> cursos = new List<curso>();
public aCurso(List<curso> cursos)
{
InitializeComponent();
this.cursos = cursos;
}
}
}
Here's code from class curso:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace _18_05_18
{
class curso
{
private string nombre;
public curso(string nombre)
{
this.nombre = nombre;
}
}
}
You cannot expose a public method signature where some of the parameter types of the signature are not public. It wouldn't be possible to call the method from outside since the caller couldn't construct the parameters required.
All you have to do is make curso class public
public class curso
{
private string nombre;
public curso(string nombre)
{
this.nombre = nombre;
}
}
When I keep clicking any ListViews rapidly, the app will eventually freeze and become inaccessible. Any Idea how to prevent this from happening?
to generate the bug:
1. run the app
2. keep clicking the listview randomly as fast as possible
3. the app will then freeze
this is my code:
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
namespace DragDropCF
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
SetupListView(lv1, new ObservableCollection<String> { "VarOne", "VarTwo", "VarThree" });
SetupListView(lv2, new ObservableCollection<String> { "VarFour", "VarFive", "VarSix", "VarSeven" });
SetupListView(lv3, new ObservableCollection<String> { "VarEight", "VarNine", "VarTen", "VarEleven", "VarTwelve" });
}
private void SetupListView(ListView listView, ObservableCollection<String> itemsSource)
{
listView.ItemsSource = itemsSource;
listView.AllowDrop = true;
listView.CanDrag = true;
listView.CanDragItems = true;
listView.CanReorderItems = true;
listView.DragItemsStarting += ListView_DragItemsStarting;
lv1.DragEnter += Lv1_DragEnter;
lv1.Drop += Lv1_Drop;
}
private void Lv1_Drop(object sender, DragEventArgs e)
{
}
private void Lv1_DragEnter(object sender, DragEventArgs e)
{
}
private void ListView_DragItemsStarting(object sender, DragItemsStartingEventArgs e)
{
}
}
}
The structure of my application
Content mainpage
using MyBD;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.ApplicationModel.Background;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
namespace MyApp
{
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
this.NavigationCacheMode = NavigationCacheMode.Required;
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
}
private void button_Click(object sender, RoutedEventArgs e)
{
historyBD HBD = new historyBD("history");
}
}
}
Content MyBD
using SQLitePCL;
namespace MyBD
{
public class historyBD
{
public SQLiteConnection con;
private string mynull = "0";
public historyBD(string dbname)
{
con = new SQLiteConnection(dbname);
}
}
}
when you press the button , the line "con = new SQLiteConnection(dbname);"
gives an error message : "A SQLite Wrapper assembly for the current platform was not found. Ensure that the current project references both SQLitePCL and the following platform-specific assembly: SQLitePCL.Ext."
What am I doing wrong?
I have created a WCF service which sends an sms by using the supplied values. This then return XML in a string variable. I have managed to get the string loaded into an XmlDocument but then when I try and load it onto a Webform control I get an error because the XmlDocument is in memory and does not have a physical path. How can I get this loaded into my webform control(WB_XMLOut). Please see my code below what I have tried.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using LeadProcessTest.LeadProcessor;
using System.Xml;
namespace LeadProcessTest
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void BT_Process_Click(object sender, EventArgs e)
{
LeadProcessorClient LP = new LeadProcessorClient();
string UName = Convert.ToBase64String(Encoding.UTF8.GetBytes(TB_UName.Text));
string PWord = Convert.ToBase64String(Encoding.UTF8.GetBytes(TB_Pass.Text));
string XMLIn = Convert.ToBase64String(Encoding.UTF8.GetBytes(TB_XMLin.Text));
LP.Open();
string Result = LP.Lead_Processing(UName, PWord, XMLIn);
LP.Close();
XmlDocument XML = new XmlDocument();
XML.LoadXml(Result);
WB_XMLOut.Url = new Uri(XML);
}
}
}