I am going through the Contoso Cookbook examples from the Microsoft Virtual Academy Windows Jumpstart for Windows Phone 8. In trying to run any of the sample code, I get 3 deployment errors.
"The parameter is incorrect"
The member "Instance" is not recognized or is not accessible
The property "Instance was not found in type "DesignDataExtension"
In the xaml code on the mainPage.xaml line 35, it is not recognizing "Instance". but I cannot figure out the cause.
Can anyone tell me why?
Code samples link
Video Series Link
It seems there's two problems.
The first one (parameter is incorrect) is preventing the application from being deployed. To fix it, remove the "%2c" from the folder name (the default folder name is "Windows Phone 8 JumpStart Contoso Cookbook Step 1%2c Initial Layout", it seems to make the deploy process bug somehow). Then delete the ContosoCookbook.suo and ContosoCookbook.v11.suo files located in the C# subfolder.
The second error doesn't prevent the application from working, but crashes the designer. In the attributes of the grid (MainPage.xaml, line 38) :
<Grid x:Name="LayoutRoot" Background="Transparent" d:DataContext="{d:DesignData /SampleData/RecipeDataSourceSampleData.xaml, Instance={x:Null}}">
Remove the , Instance={x:Null} part and it'll work just fine:
<Grid x:Name="LayoutRoot" Background="Transparent" d:DataContext="{d:DesignData /SampleData/RecipeDataSourceSampleData.xaml}">
Related
I am trying to create a new page to my solution but I can't run the emulator because when I try to build the app I get the error CS0103: The name 'InitializeComponent' does not exist in the current context.
I tried what is in this
https://forums.xamarin.com/discussion/62671/initializecomponent-does-not-exist-in-the-current-context-error
which basically says change the the "Build Action" to "Embeded Source". I tried it and the red squiggly line bellow the "Initialize Component" disappears but when i try to reference to that page for example when i want to open the page when a button is clicked I can't reference the page, the name doesn't come up with the intelliscence as it type the word "page1" an I get an error when i try to build the solution because it says " the type or namespace named page1 can not be found, are you missing using a directive or an assembly reference.
also another page suggests changing the page1.xaml build action to embeded source and making the page1.xaml.cs build action to compile. I can't do this because the page1.xaml doesn't get added to he solution explorer when I create a new page. so I can't select property and change the build action for page1.xaml.
also this page doesn't work because it is about wpf not xamarin.
The name 'InitializeComponent' does not exist in the current context.
this link sais that the project runs fine although he has a red squigly line under the initialize component which isn't my case.
https://github.com/UXDivers/Grial-UI-Kit-Support/issues/154
this one sais clean and rebuild solves the build erro but it is not true in my case.
https://github.com/xamarin/Xamarin.Forms/issues/2863
This issue occurs if the xaml and xaml.cs page is not connected properly.
Xaml Page
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:controls="EmployeeApp.PettyCashListPage" x:Class="EmployeeApp.PettyCashListPage">
x:Class="EmployeeApp.PettyCashListPage"
Xaml.cs
public partial class PettyCashListPage : ContentPage
Both class name should match, if not 'InitializeComponent' issue occurs. Hope this helps.
The Problem was that I hadn't included the Universal Windows Platform tools for Xamarin package when I installed the application. After installing that package , it now works perfectly.
A little side note: when I tried creating a new page before installing the package mentioned I used to get only the page.xaml.cs in the solution explorer. But after installing it , I now get both the page.xaml and the page.xamal.cs in the solution explorer and the problem is solved.
I tried solutions from the following links but none worked.
where-to-put-images-for-xamarin-froms-application
developer.xamarin.com/guides/xamarin-forms/user-interface/images/#Local_Images
image-not-showing-in-xamarin-forms-app.html
I used below syntax
<Image Source="lock.png" HeightRequest="20" WidthRequest="20" HorizontalOptions="Center" VerticalOptions="Center" Grid.Row="0" Grid.Column="0"></Image>
Here is the image for where i've kept image
No image displays
Edit
These are the only things in my XAML page.
In my case the issue was of assembly.
when trying all the possible solutions like
1.) Changing Build Action
2.) Adding Image to all the folders within Resources
3.) Naming Convention should not include - in File/Image Name.
4.) Changing Background Color
I also got one solution while searching for embedded Images that assembly was missing here.
This change worked for me in using Local Images.
Got that solution from this link
Right click the lock.png image and see if there is an option "include in project"
If there is, project cannot find image
In my case I need to use method Forms.Init(Context activity, Bundle bundle), in my SplashScreen OnCreate method and Activity class OnCreate method. But it also important that images build action properties is set on AndroidResource.
I am new to Windows 8 development. i am following the tutorial provided by the Windows 8 team and i have run across some problem.
Can someone please tell me where i should insert the following code block explained in the tutorial. (In step 2)
Windows.Storage.ApplicationDataContainer roamingSettings =
Windows.Storage.ApplicationData.Current.RoamingSettings;
roamingSettings.Values["userName"] = nameInput.Text;
I was looking at MainPage.xaml.cs but it doesn't have any definition of a TextField. So where should i add this code block.
The definition is found in MainPage.xaml rather than MainPage.xaml.cs:
<TextBox x:Name="nameInput" Width="300" HorizontalAlignment="Left"
TextChanged="NameInput_TextChanged"/>
The MainPage.xaml.cs is a partial class of the xaml, so any controls declared in the xaml are available from the .cs file.
See the completed example here.
I'm new to WP7 programming but have XP with other platforms, I am just running through all the basics so I can get to know the language but I have hit a roadblock I've entered a source for my background image:
<Grid x:Name="LayoutRoot">
<Grid.Background>
<ImageBrush ImageSource="C:/users/hypernova/pictures/Background1.jpg">
</ImageBrush>
</Grid.Background>
</Grid>
And the image shows up as a background in the design tab that is next to the XAML but when I debug and the emulator starts its just a black screen no background image, what have I missed? I have tried other ways of setting a background like:
<Grid x:Name="LayoutRoot">
<Canvas>
<Canvas.Background>
<ImageBrush ImageSource="C:/users/hypernova/pictures/Background1.jpg">
</ImageBrush>
</Canvas.Background>
</Canvas>
</Grid>
but the same thing happens I've tried a few other ways also but again nothing, I'm sure I've missed something I should have caught.
The path
C:/users/hypernova/pictures/Background1.jpg
exists on your dev machine, not on any Windows Phone 7+ device.
Remember, users will be downloading your app from the store, then running it on their phones. How would they possibly access your hard drive and get that image?
Unfortunately, since the design surface allows you to do this, it can of course be confusing to a new developer.
What you should do is add your image to your project as a Resource, then reference the resource via a pack URI (don't click on that link unless you want to scare yourself silly).
To add it as a resource, simply add the image to the root of your WP7 project, right click on it, select Properties, and then change the build action to Resource (not Embedded Resource, mind you).
Next, you have to construct a pack URI for this resource. This is ... not easy. You can use the tools in Visual Studio to do this, by editing the properties of your ImageBrush in the designer. This is the simplest, and recommended, route. All you have to do is edit the ImageSource of your ImageBrush in the Properties tool window, and select the image from the list of available images in the solution.
The other way is to manually construct the pack URI. For example, you could take the following
/[project assembly name];component/Background1.jpg
replace [project assembly name] with the name of your assembly (no extensions), and use it as your ImageSource value. You can find the correct project assembly name by looking at the Assembly Name under the Application section of the project properties.
<ImageBrush ImageSource="/MyWp7Application;component/Background1.jpg"/>
Note, depending on how your project folder structure is constructed, this URI may be different. Constructing the correct URI outside of the tools provided is a task deserving of another question.
Im in the sticky problem of in need to localize the app for different languages. Googling the topic gave me a lot of sites on the same
http://msdn.microsoft.com/en-us/library/ff637520(v=vs.92).aspx
I'm using the msdn as the reference. I've created the AppResource .resx file, made changes in the .csproj file..
Created a new class called Localizedstrings. but im not able to create an instance
private static LoveCycles.AppResources localizedResources
infact the AppResources is not recognised by the intellisense. I get an error sayin type or namespace name AppResource does not exist in the namespace. How can i access this resource file?
Im tryin to replace the strings which displays message in the messagebox and not the UI elements?
Where have i gone wrong? no bindings have been used in the app.
Alfah
I have done the localization :) and it works like magic.
all you gotta do is to follow the msdn links for localization.
In most of the sites, they have not mentioned how to replace the variables. Jus in case somebody wants to know, I've done it the following way
For strings in msg boxes,
ResourceManager rm = new ResourceManager("LoveCycles.AppResources", Assembly.GetExecutingAssembly());
msgResult = MessageBox.Show(rm.GetString("msgBoxStartMonitoringDescription") + "\n" + dtSelDate.ToString("dd - MMM - yyyy"), rm.GetString("msgBoxStartMonitoringHeader"), MessageBoxButton.OKCancel);
msgBoxStartMonitoringDescription and msgBoxStartMonitoringHeader are defined in my resx file.
and for the UI defined in the xaml
<TextBlock x:Name="Average" Height="30" TextWrapping="Wrap" Text="{Binding Path=LocalizedResources.statsAvgLengthTBlock, Source={StaticResource LocalizedStrings}}" Width="215"/>
statsAvgLengthTBlock is defined in the resx file
:)
happy coding all :D
Alfah