ApplicationView does not contain a definition for GetForCurrentView? - c#

I'm currently following a tutorial from the MSDN which isn't very clear on somethings the issue that i am having is that the method that they are suggesting that i use is apparently not available to that class
Here is the link to the tutorial : http://msdn.microsoft.com/en-us/library/windows/apps/dn495655.aspx
Here is the code that i am using
In my App.Xaml.cs not my Main page i have an event handler
public App()
{
this.InitializeComponent();
Window.Current.SizeChanged += Current_SizeChanged;
this.Suspending += OnSuspending;
}
Underneath this the stub method
void Current_SizeChanged(object sender, Windows.UI.Core.WindowSizeChangedEventArgs e)
{
// Get the new view state but its not allowing me to use getforcurrent state
// almost like it doesn't exist
string CurrentViewState = ApplicationView.GetForCurrentView().Orientation.ToString();
// Trigger the Visual State Manager
VisualStateManager.GoToState(this, CurrentViewState, true);
}
If anyone else has followed this tutorial can they tell me what is going wrong ?
Have i put the code in the wrong page
Am i missing a library
I am following this microsoft tutorial word for word and it giving me the error which is the title of my post i have done research and i am using the latest version of visual studio and it's still not letting me use this method because it do not exist apparently

Try using Windows.UI.ViewManagement; at the top of the program.

The minimum supported version of this API is Windows 8.1. So you can't use it with the Windows 8 API.
MSDN reference

Related

.NET client library for Watson Assistant what is an _assistant object?

I am trying to communicate with my chatbot via a Windows Form App (using C#). I have installed the SDK into Visual Studio, but I am having trouble using it. I have read through all the documentation, including on GitHub, however, because this is my first time using the SDK, I am quite confused about how to get it to work. At this point, I simply want to be able to send a "Message" and read the chatbot's response.
Which namespaces do I have to include (i.e. "using IBM.Watson...")? Because I have tried authenticating but am getting the error: "namespace AssistantService could not be found", as per the IAM authentication in dotnet guide on GitHub. Also, what is an "_assistant" object and how to I create one, the docs don't explain this so I keep getting the error "_assistant does not exist in the current context..."
This is the link that to the SDK I am following: https://github.com/watson-developer-cloud/dotnet-standard-sdk
I am trying to authenticate with the instructions at that link but am not succeeding. I am trying to use these instructions to call the Watson Assistant: https://github.com/watson-developer-cloud/dotnet-standard-sdk/tree/development/src/IBM.WatsonDeveloperCloud.Assistant.v1
****************UPDATE*****************
using System.Windows.Forms;
using IBM.WatsonDeveloperCloud.Assistant.v1.Model;
using IBM.WatsonDeveloperCloud.Assistant.v1;
using IBM.WatsonDeveloperCloud.Util;
namespace Watson_Assistant_Test
{
public partial class Form1 : Form
{
AssistantService _assistant;
string[] _questionArray = { "Hello there" };
public Form1()
{
TokenOptions iamAssistantTokenOptions = new TokenOptions()
{
IamApiKey = "Y....H",
IamUrl = "https://gateway-syd.watsonplatform.net/assistant/api"
};
_assistant = new AssistantService(iamAssistantTokenOptions, "2018-07-10");
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
MessageRequest messageRequest = new MessageRequest()
{
Input = new InputData()
{
Text = _questionArray[0]
}
};
var result = _assistant.Message("d...5", messageRequest);
label1.Text = result.ResponseJson.ToString();
}
}
}
I think I am still not creating the AssistantObject correctly. I am getting this error: ServiceResponseException: The API query failed with status code NotFound: Not Found.
Thanks, Harry
[I am not a C# developer and have not used that SDK, but... :)]
There is a small sample as part of the SDK that works with the car dashboard example. Because of the renaming of Watson Conversation to Watson Assistant it is still using the old object names (both work).
The code uses this namespace:
using IBM.WatsonDeveloperCloud.Assistant.v1.Model
Based on the code itself it checks for the following parts of TokenOptions:
IamApiKey
IamAccessToken
ServiceUrl
My guess is that you have to rename IamUrl to ServiceUrl in your code.

Reference to the right "System" in c# project

I am new to c# and visual studio and have run into some trouble.
I have created a project with references to "Windows" and ".Net" in visual studio because I want to test a little with smart cards.
The code:
using System;
using Windows.Devices.Enumeration;
using Windows.Devices.SmartCards;
class HandleSmartCard
{
public async void checkNumberOfSmartCards()
{
string selector = SmartCardReader.GetDeviceSelector();
DeviceInformationCollection devices = await DeviceInformation.FindAllAsync(selector);
// return "2";
}
}
So far it looks fine. However I also want the project to be able to use
System.Windows.Forms; which I have used in a previos test.
I add reference to System.Windows.Forms; and try to create a form. However in that form when I try this:
Form prompt = new Form();
System.Windows.Forms.Button confirmation = new System.Windows.Forms.Button() { Dock = DockStyle.Bottom };
confirmation.Click += (sender, e) => { prompt.Close(); };
I get a red line under "Close" with the message:
Reference to type component claims it is defined in system but could
not be found.
System is referenced at top of file, but I am guessing it is the wrong type of system right?
Can I somehow use "both Systems" in one project so to speak?
I hope someone understands what I mean and can help me understand this.
You're most likely working on a UWP app. The API for UWP apps is a very small subset of the full .NET framework. You can find more information here
https://msdn.microsoft.com/en-us/library/windows/apps/mt185501.aspx
You're attempting to reference System.Windows.Forms which is not allowed in UWP applications.
Looks like you're trying to create a popup to ask the user something. For this, use the MessageDialog class.
https://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.popups.messagedialog.aspx

ILNumerics and Visual Studio Tools for Office (VSTO)

I've been experiemnting with the community version of ILNumerics 3.2.1.0 with .Net 4.0 in Visual Studio 2010 pro on Windows 7, and going through the documentation I succesfully get a windows form project to display a chart, using the code below.
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void ilPanel1_Load(object sender, EventArgs e)
{
ILSurface mySurface = new ILSurface(ILSpecialData.sincf(100, 200));
ILPlotCube myCube = new ILPlotCube(twoDMode: false);
myCube.Add(mySurface);
ilPanel1.Scene.Add(myCube);
}
}
If I try exactly the same code but from inside a VSTO Excel 2010 application all that is displayed in the form is the designer view of the ILPanel, blue circle on white background. I don't get any error messages. Am I missing something obvious? or does anyone have a solution of how to get the chart to display in VSTO?
Update
Thanks to Philliproso for pointing out the IsDesignMode() method. As pointed out in various places, including this question, Detecting design mode from a Control's constructor , the following method is not ideal, but for me is has provided a quick fix to allow me to evaluate ILNumerics.
public static bool IsDesignMode() {
if (System.Windows.Forms.Application.ExecutablePath.IndexOf("devenv.exe", StringComparison.OrdinalIgnoreCase) > -1)
{
return true;
}
return false;
}
This is the same issue as here:
Ilnumerics Ilpanel not activating when compiled in a winform into a dll when loaded into matlab
in-a-winform-into-a-dll-when-loa
Using VSTO as host for ILNumerics lets the panels assume, it was loaded in a designer. We are currently collecting possible workarounds and solutions. One solution might be to introduce a flag in the Settings of ILNumerics:
Hosted [default: false]
Your situation would require the flag to be enabled. In hosted mode, a blacklist of common designers could be checked at runtime and compared to the current entry assembly. Any other suggestions?

Silverlight C# - ComponentOne Spellchecker not loading dictionary

This may be a long shot, but I'm using ComponentOne's Spellchecker control for Silverlight. I made a test project, added a plain textbox and a button to it, added the references to the C1.Silverlight and C1.Silverlight.SpellChecker bits, and added the dictionary file to my project.
In the code, I called up the spellchecker on button1's click event and it worked SPLENDIDLY. The spellchecker dialog shows up, and works exactly as it should.
Since that test was successful, I then tried to implement this into my existing project. I've had no success for absolutely NO reason that I can determine, since I used the EXACT SAME code.
Here's the code I use to call the component:
using C1.Silverlight;
using C1.Silverlight.SpellChecker;
using C1.Silverlight.Resources;
public partial class MainPage : UserControl
{
C1SpellChecker spellChecker = new C1SpellChecker();
public MainPage()
{
InitializeComponent();
spellChecker.MainDictionary.LoadAsync("C1Spell_en-US.dct");
}
private void btnSpelling_Click(object sender, RoutedEventArgs e)
{
var dlg = new C1SpellDialog();
spellChecker.CheckControlAsync(txtArticle, false, dlg);
}
The references to C1.Silverlight and C1.Silverlight.Spellchecker are added to this project as well, and the dictionary as been added in the same fashion as well. The issue seems to be that for whatever reason the dictionary is not loading, because the spellChecker.Enabled method returns whether or not the main dictionary has been loaded. If I call MessageBox.Show("SpellChecker Enabled = " + spellChecker.Enabled.ToString()); it shows false, even though the call to load the dictionary is there (as you can see).
What would cause the dictionary to not load? Have I added it to my project incorrectly somehow?
EDIT: I suspect that I have added the dictionary to the project incorrectly, because the ComponentOne reference states:
If C1SpellChecker cannot find the
spelling dictionary, it will not throw
any exceptions. The Enabled property
will be set to false and the component
will not be able to spell-check any
text.
I just don't know what's wrong though because it was added in the same way that it was in the test project (Right clicked on the project.web->Add->Existing Item)
As always, thank you!
-Sootah
You could add the dictionary to the Silverlight app as an embedded resource and then load it using this code:
public MainPage()
{
InitializeComponent();
// load C1SpellChecker dictionary from embedded resource
var asm = this.GetType().Assembly;
foreach (var res in asm.GetManifestResourceNames())
{
if (res.EndsWith(".dct"))
{
using (var s = asm.GetManifestResourceStream(res))
{
sc.MainDictionary.Load(s);
break;
}
}
}
}
I think this post is duplicated in our forum as well, but will answer first here. Please try this:
1) Try to access the .dct file using your browser. If you cannot see it, it's probably because your web server is not serving that type of files. You need ton configure the web server to allow it.
2) verify the URL you are using is correct.http://helpcentral.componentone.com/CS/silverlight_161/f/78/p/86955/241328.aspx#241328
3) Check you are setting everything correctly: http://helpcentral.componentone.com/CS/silverlight_161/f/78/p/81924/227790.aspx#227790
Hope this helps!

learning monodevelop and am having trouble getting a messgae box to appear

I am working in monodevelop and learning c#....
I am trying to get a message box to appear but I can't get it to function correctly ...
Here is my code:
using System;
using Gtk;
using GtkSharp;
public partial class MainWindow : Gtk.Window
{
public MainWindow () : base(Gtk.WindowType.Toplevel)
{
Build ();
}
protected void OnDeleteEvent (object sender, DeleteEventArgs a)
{
Application.Quit ();
a.RetVal = true;
}
protected virtual void OnButton11ResizeChecked (object sender, System.EventArgs e)
{
System.Windows.Forms.MessageBox.Show("Hello World Again!!");
}
}
What am i missing?
You cannot mix the GTK# and System.Windows.Forms UI toolkits. You need to use a GTK dialog, something like this:
void ShowMessage (Window parent, string title, string message)
{
Dialog dialog = null;
try {
dialog = new Dialog (title, parent,
DialogFlags.DestroyWithParent | DialogFlags.Modal,
ResponseType.Ok);
dialog.VBox.Add (new Label (message));
dialog.ShowAll ();
dialog.Run ();
} finally {
if (dialog != null)
dialog.Destroy ();
}
}
See also this question.
You are referencing GTK which is the bundled graphical toolkit in mono but are trying to use Windows.Forms which, although included in mono too, is a different toolkit:
System.Windows.Forms: This is the toolkit used in windows, the implementation on mono "emulates" how this controls are drawn and behave under platforms that mono runs on.
Gtk: This is a toolkit used in many OpenSource applications (Firefox, Pidgin, etc) and GTKSharp is simply the implementation of this same library but exposed to the .Net languages available on mono although you could use it directly with Visual Studio or a Microsoft compiler too.
So summarizing, as Mike said, you cannot use them both, you have to choose either one. If you are just learning .Net I would greatly advice to learn GTK instead of Windows Forms. Windows forms is kind of poor and basic toolkit, and soon you'll find that you'll need to learn a new API from a third party to do stuff that windows forms cant do (DevExpress, Infragistics) and Gtk can be easily extended and adjusted to your needs.

Categories