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.
Related
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 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}">
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.
After being advised that the native ComboBox was not the way to go I was told to look at the Silverlight Toolkit ListPicker. So I did and have got a problem.
I opened a new project and pulled a new ListPicker onto the MainPage. The ListPicker looks like:
<toolkit:ListPicker x:Name="Result">
<toolkit:ListPickerItem Content="Win" />
<toolkit:ListPickerItem Content="Place" />
<toolkit:ListPickerItem Content="Lose" />
</toolkit:ListPicker>
When trying to run this I get an XamlParseException with InnerException of InvalidProgramException. All I did was drag the control on, and add some ListPickerItem. Removing the items still results in the error, removing the ListPicker control completely allows the page to be shown with no error.
I'm sure I've missed something, but any documentation I have read seems to point towards this markup being fine, including http://windowsphonegeek.com/articles/listpicker-for-wp7-in-depth
I can provide any other info required.
ListPickerItem is a class used internally by the ListPicker and should not be used directly.
If you just want to add a list of items, you can use strings to do it, like this:
Add a new namespace on top of the Page to access the String class:
xmlns:sys="clr-namespace:System;assembly=mscorlib"
Then, just change the ListPicker code to this:
<toolkit:ListPicker>
<sys:String>Win</sys:String>
<sys:String>Place</sys:String>
<sys:String>Lose</sys:String>
</toolkit:ListPicker>
The problem was that the wrong dlls had been registered, i.e. 7 and not 7.1. I had to uninstall and reinstall to get it to update correctly and it worked.
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