Award for best C# article January 2008

I Havent written anything for a while at my blog, as I have working on putting the finishing touches to my beginners series on WPF.

I am proud to say that this series has gone down well over at codeproject and has won me the 1st place prize for the January 2008 C# compeition for beginners series on WPF : Part1

Advertisements

8 thoughts on “Award for best C# article January 2008

  1. Kevin says:

    Hey, Sacha…I’ve been reading your stuff for a bit, and you’re quite the talent. For someone that’s “just learning” WPF, you seem to have a very good grasp on it. I consider myself an infant with WPF. I’ve yet to create my first app with it. Like you, I prefer C#, so it only made sense I should come to you with a couple WPF/C# questions.

    My first WPF app is going to be a simple one. Or, it would be if it were all C#. It will have images on the left, and buttons on the right. I want to be able to click on an image, and have the buttons related to that image loaded from a database on the right. In Flex, I think I would use a repeater, and grab the data from an XML file to create the buttons. But in this case, I need to query a SQL database and have WPF create the buttons on the fly. I have searched the world over for some examples, but have come up short. Do you have any suggestions, or know of some good resources I can use to get some guidance?

    Thanks,
    Kevin

    P.S. Congrats on your engagement. Wives are awesome. And, kids are even more fun.

  2. sacha says:

    Hi Kevin

    There are a couple of different approaches, I think the easiest by far would be to use these steps

    1. Create a DockPanel with lastChildFill=true.
    2. put a StackPanel vertical align, in the DockPanel, and set it to be Dock left
    3. Create a listbox in the DockPanel (as this is last child it will fill all remaining DockPanel space)
    4. wire up the image mouseDown events (you could do this at StackPanel level something like

    <StackPanel Image.MouseDown=”GetButtonsForImage” Orientation=”Vertical”>
    <Image Source=”blah.png”/>
    <Image Source=”blah2.png”/>
    </StackPanel>

    5. In the GetButtonsForImage event handler, use the e.OrigiginalSource property to see which image was clicked, and then possible use some LINQ to SQL to get the names of the related buttons from the DB
    6. For all related buttons obtained from DB, add new object of some type (basically whatever class you like, 1 per DB row found) to the listbox
    7. create a DataTempate for the class you are using in the listbox.

    You can find all these answers in my series. Part1 will help with layout, I think Part6 will help with the Templates/Styles. For LINQ to SQL see other sites, there are loads of example.

  3. Kevin says:

    Thank you very much. If I have any more questions, I’ll post them in the relevant articles.

  4. Kevin says:

    Sacha,

    Sorry to bother you again. The e.OriginalSource gives me an error. Perhaps I am using it wrong. Also, Image.MouseDown in StackPanel would let the Designer load in VS 2008. It compiled and ran, however. I removed that, and placed a MouseDown=”GetButtonsForImage” in each , and it worked fine. If you can help me figure out how to get the image name in my code behind, I I’ll just have the DB stuff to figure out (I’m using a MessageBox for the MouseDown event to show the image name for now).

  5. Kevin says:

    Sorry, that didn’t come out right. Let me try that again:

    The e.OriginalSource gives me an error. Perhaps I am using it wrong. Also, Image.MouseDown in StackPanel wouldn’t let the Designer load in VS 2008. However, it did compile and run. I moved the MouseDown, and placed it in each <Image />, and that worked fine. If you can help me figure out how to get the image name in my code behind, I’ll just have the DB stuff to figure out (I’m using a MessageBox for the MouseDown event to show the image name for now).

  6. sacha says:

    Kevin,

    If you send me an email (using this blog entry with your personal email in the blg comment somewhere Ill contact you and get your code of you and have a look.

  7. Kevin says:

    Sacha, here’s my email kevin(at)rodenhofer.com

  8. ok says:

    good site camnix

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: