Adding Observable Collection to class

Posted on

If you’re not following along while going through the book or aren’t already ahead of my knowledge curve, this post may possible just shoot way over you head. I’ll try to keep it from shooting too far, but I can’t guarantee anything.

Chapter 9 has us creating a c# based class file.

Quite a few posts ago I’d written a blog regarding classes – superclasses, parent, and children. Well at the very beginning of the C# documents, the first thing specified are the classes which each document is referencing – inheriting.

In regard to this set, Victor’s book says that I should see the following collection:

using System;
using System.Collections.Generic;
using System.Text;
using System.Collections.ObjectModel;

But that’s not how Visual Studio 9 (final release plus SP1) created my C# class file.  It created it like this:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.ObjectModel;

I was in the middle of writing that I was hoping that it wouldn’t be a problem that I don’t have something which is displayed in a later portion where the author is having us add an item – but now that I’m typing it and flipping back and forth between the pages, I’ve discovered something odd.

Look at the first set of classes in this post.  Now check this out – page 194 of Chapter 9 has him directing us to add something called, “System.Collections.ObjectModel;”  But wait – that’s already there.  Or well – it has been the entire time he’s showing us what our code should look like.  He’s even bolded it.  What I AM seeing is soemthing else which is quite interesting.  An addition which is not mentioned and not previously shown.

Excerpt from the book –

… (see the following bolded code).

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.ObjectModel;
using System.ComponentModel;

I’m not so concerned regarding the bolded – because it was placed there by Visual Studio. What I want to know about is where the heck did using System.Linq and using System.ComponentModel; come from?  My Visual Studio already had .Linq but I don’t have the “ComponentModel”.

I’m going to add it to my code but… what the heck?

Edit: Page 196 he shows us what the code is supposed to look like entirely.  System.Linq is not a part of this example!

The actual C# the author steps you through adding – I wouldn’t have been able to get myself through that on my own.  As I work with C# more, I believe that I could, but at this point, I comprehend what the code is doing, but I know that I wouldn’t have been able to engineer it from “thin air”.

Rollovers

Posted on

Somewhere in chapter 8, Victor Guadioso, the author of the Blend 2 book that I’m going through, talks about MouseEnter and MouseLeave events and says:

“In Flash and HTML, this is commonly known as Rollover and RollOut states”

Sorry to correct the author, but HTML coders – unless you’re talking about the mid-90s, stopped using Rollovers in favor of CSS hovers. Just the mention of Rollovers makes me cringe inside in the way that the movie Hollow man makes me cringe when the guy is running and you can see his body moving, fully in tact save for his skin which is invisible. (Note: That’s about one of the only things where I become squeamish.)

Twitter followers – merchant spam

Posted on

On a completely side topic, all of these blogs auto-populate to my twitter which feeds my status message to facebook.

The last week or so I have received several messages daily of new people following me on twitter. I click to view who the heck they are just to discover that they’re people who JUST created themselves a new account and from what I can tell, they’re just going through and “following” people so these people will visit them and hopefully obtain a few clicks. These are businesses.

I hope the people who work on twitter give the ability for people to decline or approve the act of following.

Naming a URI a uri?

Posted on

In chapter 8, the book guides you through creating a window which allows you to drag a movie into the window, it displays the path, and when you click “ok” to make the window which displayed the path disappear, the video starts playing.

To do this, we set in the C# a URI variable, named it uri, and did a few other things. The application ran as intended – the video played.

But besides making it easy for the readers of the book, I could see quite quickly where naming a URI the name “uri” would get confusing when trying to debug something.

What if you’re jamming (which is what I call it when I’m on a roll and making things work the way I’m wanting w/o any hitch) and you’re just needing to modify something, and woopsy – modified the wrong one because you have the same dang thing written one after the next? Or what if you’re trying to find where you’d inadvertently modified the URI, and because you’re seeing the name “uri”, you don’t initially realize that its the name, not the variable.

*shakes head* Seems like something that might be considered as “preparing one’s self to shoot self in the foot.” Like taking your shoes and socks off so as to give yourself a clear shot.

Perhaps there’s more of a reason for naming a URI uri, or perhaps its just not an issue as its such common practice. This would be the first time that I’m working with C# that’s being put into place by me as opposed to locating someone else’s example code or modifying something that I’d used in the past or seen used in a previous project that worked.

Events and Event Handlers

Posted on

Chapter 8 of Victor Guadioso’s book on Blend 2 talks about Events and Event Handlers.

For those who are beginning to feel as though the stuff here in this blog is way over your head, I’ll just give a basic example of what these are.

Most don’t ever think about what has to go into a program when they’re using it. They get frustrated when a certain feature isn’t exactly what they were looking for, but the thought put towards the existing functionality and the specific elements are often overlooked.

Something most everyone is familiar with: Logging into something. You typically have 2 fields, a field for your username and a field for your password, and then a button for logging in. There are often other elements, but we’ll ignore those as they’ll make this go into the realm of “convoluted”.

So you enter your username, then you enter your password, and you click on the button.

Events and Event Handlers are the things which look for your action and interaction with that button. They “listen” for your click along with a few other things, and when you do click, they are able to execute whatever it is that the button is coded to execute.

Get it?

Most people I know don’t think about the UI when the UI is built well. They just use it. Ever come to a DVD player? Likely you have. How do you use it? Well, you hit the button which tells it to eject. How does it know to eject when you hit that button? Why someone told it to do that. How does it know to play or pause when you hit the button? Well – someone told it to do those functions. Now how did the communication get from the button to the… thing that tells it to do those things?

Anyway – One of the first things that Victor goes over is DragEnter.

As in, when you have something that you’ve clicked upon and you drag it over – as your mouse enters the area of the application, it detects that you’re dragging something into the region of the application.

My application would build, but it wouldn’t do anything when I dragged an item into it – in fact, it shows me the little icon on my mouse pointer which signified that what I was doing as an illegal action. I checked and double checked my c# but couldn’t find the issue.

I couldn’t find it, so I took a break. When I came back, the issue stuck out like a sore thumb. I neglected to add into my XAML the property AllowDrop=”True”. Ran the application and vwalla. It functioned the way it was designed.

InsideButton property not found

Posted on

Trying to figure out what the heck it is that is causing the issue.

I’m at the tail end of chapter 7 and it isn’t seeing the reference to InsideButton and so therefore won’t run.

I’ve downloaded the example which is provided as support for the book and have compared and besides a few uncircumstancial changes, such as a difference in width and height or the source of an image, I’m not finding where it was that I’ve overlooked my xaml or C#.

I swear it has to be something just staring me RIGHT in the face.

Update: I discovered what my problem was – and this actually was an interesting find. There were 2 instances of my custom created item within the asset library. There was a custom control and a custom button. I’d used the custom button – and that is why I ran into the problem. It wasn’t actually referencing the custom control which had the x:Name set to InsideButton – so obviously, it wasn’t going to see the information necessary as there was no reference to the User Control asset!