Has anyone ran into problem where you just can't use the PageOrientation property in your C# WPF project? I have tried everything, put it still says:
"The name 'PageOrientation' does not exist in the current context".
I have all usings included, just can't figure it out.
Here's my printing method:
private void btnPrindi_Click(object sender, RoutedEventArgs e)
{
PrintDialog prtDlg = new PrintDialog();
if (prtDlg.ShowDialog() == true)
{
**prtDlg.PrintTicket.PageOrientation = PageOrientation.Landscape;**
Size pageSize = new Size(prtDlg.PrintableAreaWidth - 30, prtDlg.PrintableAreaHeight - 30);
gridKaart.Measure(pageSize);
gridKaart.Arrange(new Rect(15,15,pageSize.Width,pageSize.Height));
prtDlg.PrintVisual(gridKaart,"Patsiendikaart");
}
}
The error actually refers to the enumeration (PageOrientation.Landscape) on the right hand side of your assignment.
If the property did not exist you would receive (try compiling "".Y and you'll see what I mean):
'string' does not contain a definition for 'Y' and no extension method 'Y' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?)
Compare this to Aoeui.Dhtns:
The name 'Aoeui' does not exist in the current context
You are likely missing a namespace reference required, like System.Printing:
// ...
using System.Printing;
// ...
The other possibility is you have not referenced ReachFramework.
If you have, your code compiles as-is:
Related
I am trying to program a app for chain letters.
This is my Template: https://learn.microsoft.com/en-us/previous-versions/office/troubleshoot/office-developer/automate-word-create-file-using-visual-c
This is my code: https://github.com/440z/2021-07-01_WindowsFormsAppFuerKettenBriefMitWord
The error occurs in file Form1.cs in line 171.
Word._Document oDoc;
// ...
object oBookMark = "MyBookmark";
oDoc.Bookmarks.Item(ref oBookMark).Range.Text = "Some Text Here"; // L171
error CS1061: 'Bookmarks' does not contain a definition for 'Item' and no accessible extension method 'Item' accepting a first argument of type 'Bookmarks' could be found (are you missing a using directive or an assembly reference?)
I set a using directive and made a assembly reference how described in the template.
Add a reference to Microsoft Word Object Library. To do this, follow these steps:
On the Project menu, click Add Reference.
On the COM tab, locate Microsoft Word Object Library, and then click Select.
and
using Word = Microsoft.Office.Interop.Word;
using System.Reflection;
I just don't get it!!!
It looks like Bookmarks has an indexer, so: try one of
oDoc.Bookmark[ref oBookMark].Range.Text = "Some Text Here";
or
oDoc.Bookmark[oBookMark].Range.Text = "Some Text Here";
However, I would expect this to now complain that you're trying to access an invalid key, meaning: there is no existing bookmark keyed by "MyBookmark"
So I am using the Plugin.SpeechRecognition Nuget Package and following the exact code on line and its not working.
I have tried adding the "Plugin.Permissions" Nuget Package and that hasn't helped and i have tried googling the problem but there isn't anyone getting this issue and it seems to work fine for everyone. I have also tried removing the "await" keyword and it just says
Operator '==' cannot be applied to operands of type 'IObservable' and 'bool'
Here is my code:
private async void GetSpeechPermission()
{
var granted = await CrossSpeechRecognition.Current.RequestPermission();
if (granted == true)
{
// go!
}
}
so what should happen is there is no error what so ever and the code should run fine but the line of code
await CrossSpeechRecognition.Current.RequestPermission();
has a red underline saying
IObservable' does not contain a definition for 'GetAwaiter' and no extension method 'GetAwaiter' accepting a first argument of type 'IObservable' could be found (are you missing a using directive or an assembly reference?)
when I am using the EXACT code provided by the creator of the plugin from here https://github.com/aritchie/speechrecognition
Any help is MUCH appreciated!!
The Solution to this was to add
using System.Reactive.Linq
in the using section of the code and instead of using a bool value as the code example for the plugin suggests, instead, in the if statement, convert the "granted" variable to a string and then check for "Available", Code:
private async void GetSpeechPermission()
{
var granted = await CrossSpeechRecognition.Current.RequestPermission();
if (granted.ToString() == "Available")
{
//GO
}
}
Hope this helps some one! :D
My question is about how to get a stack out of a queue. The program should work by generating stacks (shown below), having those stacks stuffed with data (also shown below), then unloading and displaying the data in them. Right now it just throws a CS1061 exception at me. The 5 is there for example, the actual code is picking a random string from an array.
public void newCustomers()
{
var customer = new Stack();
store.Enqueue(customer);
}
public void Shop()
{
var customer = store.Dequeue();
customer.Push(5);
//^currently this doesn't work. I'm assuming the typing for customer is wrong.
store.Enqueue(customer);
}
CS1061
Severity Code Description Project File Line Suppression State
Error CS1061 'object' does not contain a definition for 'Push' and no accessible extension method 'Push' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?)
You're using the non-generic Queue class. The Dequeue() method returns an object that you would have to cast to Stack:
var customer = (Stack)store.Dequeue();
customer.Push(5);
I would suggest using the generic queue class Queue<T> instead.
I am working on a UWP application and I am trying to do something with the values of a SelectedItem in a GridView. So as I usually do with WPF I went into the XAML and Typed my event name in the XAML and let VS create the event in code for me.
<GridView x:Name="DataGrid1"
ItemClick="dg_ItemClick">
<!-- Just -->
<!-- Some -->
<!-- Normal -->
<!-- XAML -->
</GridView>
and the VS created event looks like this
private void dg_ItemClick(object sender, Windows.UI.Xaml.Controls.ItemClickEventArgs e)
{
Biz.Customer cust = e.ClickedItem as Biz.Customer;
var messageDialog2 = new MessageDialog(cust.Code, cust.Company);
messageDialog2.ShowAsync();
}
Right away I get a red squiggly line under the UI in the Windows.UI.Xaml.Controls part. There is a using at the top of the page to include that and VS wouldn't let add any other UWP references.
I can get the error to go away as I have in other parts of the application by changing the ItemClickEventArgs to RoutedEvenArgs but in this case I really need the ClickedItem as an argument to be passed to the code behind.
I have just talked to someone else getting started with UWP and they said they are having the same issue on other cLick events. So are we both doing something wrong or is there something missing from our application that is needed for the UI to be recognized?
The full error I am getting is this: Error CS0234 The type or namespace name 'UI' does not exist in the namespace 'app name' (are you missing an assembly reference?)
The type or namespace name 'UI' does not exist in the namespace 'app name'
That means you have a namespace in your app that contains Windows.
Either change your namespace, or prefix the UWP one:
global::Windows.UI.Xaml.Controls
See also How to: Use the Global Namespace Alias (C# Programming Guide).
One of bugs I can see is that your handler should be marked async, also you should use await operator when you call async method:
private async void dg_ItemClick(object sender, Windows.UI.Xaml.Controls.ItemClickEventArgs e)
{
Biz.Customer cust = e.ClickedItem as Biz.Customer;
var messageDialog2 = new MessageDialog(cust.Code, cust.Company);
await messageDialog2.ShowAsync();
}
I have been following this tutorial about "How to: Preserve and Restore Page State for Windows Phone" found at http://goo.gl/ct7ui and one of the lines of code is this:
protected override void OnNavigatedFrom(System.Windows.Navigation.NavigationEventArgs e)
{
// If this is a back navigation, the page will be discarded, so there
// is no need to save state.
if (e.NavigationMode != System.Windows.Navigation.NavigationMode.Back)
{
// Save the ViewModel variable in the page's State dictionary.
State["ViewModel"] = _viewModel;
}
}
However visual studio does not seem to like this bit of code giving me the error below:
'System.Windows.Navigation.NavigationEventArgs' does not contain a definition for 'NavigationMode' and no extension method 'NavigationMode' accepting a first argument of type 'System.Windows.Navigation.NavigationEventArgs' could be found (are you missing a using directive or an assembly reference?)
Any ideas on what i've messed up with here. Now considering 'e' is System.Windows.Navigation.NavigationEventArgs and the bit after the if statement shows System.Windows.Navigation.NavigationMode.Back, i don't for the life of me see how this is giving an error
NavigationMode is an enum in System.Windows.Navigation. Try adding
using System.Windows.Navigation;