Entries:
Comments:
Posts:

Loading User Information from Channel 9

Something went wrong getting user information from Channel 9

Latest Achievement:

Loading User Information from MSDN

Something went wrong getting user information from MSDN

Visual Studio Achievements

Latest Achievement:

Loading Visual Studio Achievements

Something went wrong getting the Visual Studio Achievements

Part 9: Data Binding to the RecipeDataSource.cs

Embed code for this video

Copy the code above to embed our video on your website/blog.

Close

Video format

Option selected may change based on video formats available and browser capability.

Close

Download

Right click “Save as…”

In this lesson we follow the instructions of the Hands On Lab to add and wire up the RecipeDataSource.cs and its images and data to make sweeping changes to the app.
 

Tags:

Follow the Discussion

  • How difficult would it be to separate the recipes.txt into separate files like Chinese.txt, French.txt etc... and connect each group to the corresponding .txt file?  What would have to be done?

  • @chilero: It would be pretty easy to do what you want to do.  You would have to make a few decisions up front, such as how you'll introduce your data files to the app ... ex. you could put them in a single folder, and use WinRT API to iterate through all files in that folder, open each up, create new items and group using something akin to the RecipeDataSource.cs' approach.  Besides that, and designing the JSON to contain your object's properties, the RecipeDataSource.cs provides a nice template that will get you 80% of the way where you need to go.  Hope that helps!

  • Hey Bob!  When I try to build the program I get this error :

    Error 1 The type or namespace name 'Common' does not exist in the namespace 'ContosoCookbook' (are you missing an assembly reference?) C:\Users\Matija\Desktop\New folder\Problem1\WinStoreAppDev_CS\CS_24\App1\App1\RecipeDataSource.cs 51 62 App1

     

    What do you thin I did wrong?

  • @matija4444: Hmm... I think you're missing a using statement.  Can you share out: (1) your using statements at the top of that code file, and (2) the exact line of code that it's complaining about?  That might help me help you further.  DON'T GIVE UP!  When you run into stuff like this, you learn a lot!

  • @BobTabor   it seems like I´m missing something in RecipeDataSource.cs.

    public abstract class RecipeDataCommon : ContosoCookbook.Common.BidingData

     

    It shows error on .BidingData. And after that it shows error on this part of code:

     public string UniqueId 
           {            
    get { return this._uniqueId; }           
     set { this.SetProperty(ref this._uniqueIdvalue);        
          }

     

    and using statements are:

    using System; 
    using System.Linq;
    using System.Collections.Generic;
    using System.Collections.ObjectModel;
    using System.ComponentModel;
    using System.Runtime.CompilerServices;
    using Windows.ApplicationModel.Resources.Core;
    using Windows.Foundation;
    using Windows.Foundation.Collections;
    using Windows.UI.Xaml.Data;
    using Windows.UI.Xaml.Media;
    using Windows.UI.Xaml.Media.Imaging;
    using System.Net.Http;
    using Windows.Data.Json;
    using Windows.ApplicationModel;
    using Windows.Storage.Streams;
    using System.Threading.Tasks;
    using Windows.Storage;
    using ContosoCookbook.Data;
  • @matija4444: First ... shouldn't it be binding, not biding?  (Emphasis on the 'n' in 'binding')

    Second ... can you make sure (Ctrl + F) that there's a class called BindingData defined in the project, and that it belongs to the ContosoCookbook.Common namespace?



  • I am getting the same error as @matija4444 

    Error 1 The type or namespace name 'Common' does not exist in the namespace 'ContosoCookbook' (are you missing an assembly reference?) K:\ContossoCookBook\ContossoCookBook\DataModel\RecipeDataSource.cs 51 62 ContossoCookBook

     

  • It shows an error in :  public abstract class RecipeDataCommon : ContosoCookbook.Common.BindableBase..at common 

  • also it shows an error in all the set property saying contosocookbook.data.recipe data doesnot contain any definition for set property 

  • error solved there are 2 contosocookbook files ..one has a common clas the other one just has a data class ...so to remove the error just delete that statement and rewrite it using intellisense 

     

  • @ambar007

    Can you give me some more details?

  • just remove that line manually and then retype it 

    public abstract class RecipeDataCommon : ContosoCookbook.Common.BidingData 


    this line ..using telesense ..my error just got removed like this make sure you use telesense to
    invoke the common.bindablebase method
  • @ambar007: I folow your direction and solve the error but to me code is little diferent

    public abstract class RecipeDataCommon : ContosoCookbook.Common.BindableBase


    we will see is it corect!
  • I was getting the same error. If you have named your project other then the actual name of "ContosoCookbook" ( may you using  lower case first letter style ) then you need to change it to that exact name.

    public abstract class RecipeDataCommon : Foo.Common.BindableBase

     

  • @gerdi:Does the program imports pictures when you use this code? That is a problem to me!

  • @matija4444 just chnage your ContosoCookbook to your project name, and it's case sensitive

    public abstract class RecipeDataCommon : [LabProjectName].Common.BindableBase

     
  • miltoncabmiltoncab

    Excellent! I have the same error and immediately change the [LabProjectName] in the same way that @santra2641384 said, they problem solved. Thanks guys,

    @BobTabor great tutorial....

  • I have a problem here. It tells me that i don't have a method GetGroups in RecipeDataSource

  • @danncoba: Did you solve this?  Can you explain more ... at what step did you experience this?  Can you point to the time marker in the video (example: 4:15) where what YOU see in your code and what I see in my code are different?

  • MustansirMustansir

    Hi bob, i have been following up your tutorials pretty closely
    and i'm stuck at the data part of app, unlike in the video i want to use a database to connect to the app and display the data in the database using sqlite, as i'm new to the app development or pretty much any kind of development can you point me or suggest me anything about the problem i'm facing

  • @Mustansir: Sorry, SQLite is outside of my sphere of knowledge.  You have the bones of the application, you would just need to replace the implementation specific to grabbing data from the text file with your SQLite code.  I would have to do the same as you ... look for a few examples online, etc.

  • MR Bob Tabor ı am watching your tutorials  ı wanted to tell  you  your tutorials very helpful thx  for  your help  I  want ask  you question  I am Using bing map in ItemDetailPage.xaml  in Flipview my map is in templated in flipview  ok. question is  How ı can send diferent  location for each page in ItemdetailPage  because  ı  am using  SampleDataSource  so  I am confuse   NavigationParameter  how  will  know it  thx for your hellp     

  • @cakmak: You can pass any object of any type as the NavigationParameter.  Create a new type with the kind of data you want to pass.  If you just need to pass a string, that's cool too ... no need to create a whole type for it.  In the click event of the grid, you figure out what it is you want to send to the ItemDetailPage (using the name of the item, or some property of the item, or the class the item is associated with).  Check this out:

     

    http://stackoverflow.com/questions/13917303/how-to-pass-a-complex-object-between-pages-in-a-windows-store-app

  • Hi Bob, besides only reading from the json file i also want to store or update data in the recipe.txt file e.g. updating whether the recipe is user favorite or not and also allowing the user to store their own recipes. how can this all be done with json or should i adopt some other way to do this (which way)?

  • @ANAS55: Here's a few links that should get you oriented in the right direction.  This looks like a job for the JavaScriptSerializer Class:

    http://msdn.microsoft.com/en-us/library/system.web.script.serialization.javascriptserializer.aspx

    Here's a StackExchange post that might also be helpful:

    http://stackoverflow.com/questions/8569855/reading-from-writing-and-appending-to-json-files

    Good luck!

  • @BobTabor: Thanks, that really helped.

  • aka17aka17

    suddenly groupdetailpage.xaml.cs and groupitempage.xaml.cs both r opening in notepad n they r empty plzz hlp me..

  • @aka17: Yikes!  That's not good.  You must have the file associations incorrect.  Have you done anything recently like attempted to open any C# files in Notepad?  Or has anyone tried this on the computer you're using?  I think it's easily remedied ... I would start here:

    http://winsupersite.com/article/windows8/windows-8-tip-change-file-associations-144102

  • aka17aka17

    its nt working ,do i hv to do it al over again , ahhh plzz suggest.

  • aka17aka17

    i only tried to use simulator and that hanged the system and i had to restart the system may be that is the problem...

  • @aka17: Hmm... that's a tough one.  You might try to re-install Visual Studio to re-create that association for the .cs files.  If that doesn't work?  I'm not sure what to try next.  What you described has never happened to me before.  

    You might need to contact support or someone on Visual Studio's forums.  This is where I would post it.  MAKE SURE YOU PUT AS MUCH DETAIL AS POSSIBLE IN YOUR FORUM POST to get the best results.

    http://social.msdn.microsoft.com/Forums/en-US/winappswithcsharp/threads

    Good luck!

  • Coolrw3Coolrw3

    How to hide all items, but not Group name and group box.. I have too many items and i do want all item to this page. When click group box or title, find groupdetail page and there is all this group items.<br><br>

  • @Coolrw3: I believe you can limit the number of items you display.  The Windows Store (C#) Grid App Template does this by default ... see the SampleDataSource.cs, beginning in line 133 ... here they create a public property that will ONLY reveal 12 items, and spend a lot of code managing which 12 items will be displayed (you may not need all of that complexity).  You could limit that to just 6 or 1 if you like.

  • Coolrw3Coolrw3

    Is that possible what chilero asked before? Is there any nice sample?

    Grid template is huge mess in default

  • @Coolrw3: I'm sure there are some examples out there, but I don't know of any.  I would have to spend some time on Bing.com and pour over a lot of code to find what I needed.  If you're a C# developer, chances are, you already have the skills to do this ... you simply need to decide HOW you'll do it ... how will you store the data?  How will you dynamically add the data to the project?  How will you retrieve the data and deserialize it into objects in your app.  I'll bet you could figure it out if you don't have an example to pull from.

  • This class has gotten me further then any other I've taken, as most want to show how to bind with hardcoded data and brush over the data file aspect all together, but I too am looking to link up to some kind of SQL DB, don't care if it is SQL compact, SQL express, or sounds like there is now a SQL local..  I have found a piece & part on each, but not the whole enchilada on any..  Which is best (or pros & cons) How to hook up the DB to VS, how to read & update, how to deploy, how to update with changes to DB or without wiping out the users data..  Now with the change to async reading & writing, I fear the mystery will keep mystifying and still no one will tackle it with a training video.

    It would be great for a video on that in LearnVisualStudio, once you are done creating videos for channel 9..

  • @moosetracker: Great feedback.  re: data ... I think you haven't seen much about databases and Windows Store apps because Microsoft is hoping you'll use Azure for large data needs.  If your needs are small, then serializing an object graph out to JSON may suit most small data needs.  I suppose SQL Lite is available or perhaps SQL local (although I'm not sure you can use that for Windows Store apps .. not sure, really), but I've not touched that scenario yet ... just haven't needed to.

Remove this comment

Remove this thread

close

Comment on the Post

Already have a Channel 9 account? Please sign in