Saturday, January 17, 2009

Todd Miranda is My Friend

Who is Todd Miranda? He makes tutorial videos, well, at least parttime. I like how he makes them because he always starts at the beginning and gives some explanation of what, how and why, and that is essential for bumbling idiots like me.

Thanks Todd!

Watch some here:
http://windowsclient.net/learn/videos_wpf.aspx

Todd's blog is over here:
http://www.xperimentality.com/
(he mostly does other things than educational videos)

Can .NET Go Faster than the File System?

Can .NET Go Faster than the File System? I say yes. I have one application where thousands of files are loaded and processed. Occasionally, during running in debug, the debugger stops on the file load line. It says the file is not found. I go to disk... there it is. What the hell. I continue the debugger by pushing the Go button > and it runs fine. Other times this doesn't happen... it's intermittent. Customers complain of this from time to time too. Guess I've gotta do a DoEvents() or sleep the thread or something. Yes, the file system is NTFS. Ok, ok, so I admit the computer is a laptop, not some rack mounted RAID monstrosity but is that any excuse?

What the hell?

User Control vs. Custom Control in WPF

I think I read for about 4 hours on the internet last night, looking for a clear delineation between a "User Control" and a "Custom Control" in WPF applications... I found some discussion, but no clear answer. So once again I guess I learn by doing...

First up was the User Control... < run-on sentence> It seemed the best candidate because a lot of others were making them and I didn't see very many "Custom Controls", so after many head-banging hours trying to create a User Control, I found I can do most of what I need with one, including embedding other controls into it and doing Dependency Property stuff (a topic for many posts for us beginners), so I guess "Custom Controls" are to be ignored until you can't do what you need and must resort to something else? </run-on sentence>.

Sheesh.

Friday, January 16, 2009

Referencing a WPF User Control in the Same Project

Ok, first item... Let's say you want make a user control in WPF and have it (its XAML and Code-Behind) in the same project as your application. How do you reference it so you can use it on a form? There are a lot of postings "out there" that say "just do this or that". Well, I did, but Visual Studio 2008 did NOT want to cooperate. I kept getting namespace not found errors when I was trying to reference the control in the app's window.

Let's say your user control is called "UserControl1" and your application is called "WpfApplication1". Your Window1.XAML should be like this:

<Window x:Class="WpfApplication1.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:my="clr-namespace:WpfApplication1"
Title="Window1" Height="300" Width="300">
<Grid>
<StackPanel>
<my:UserControl1 />
</StackPanel>
</Grid>
</Window>

Of course, the "my" in xmlns:my="clr-namespace:WpfApplication1" can be anything, but it should match the name in the <my:UserControl1 /> line. The namespace of your control should be the same as your application:

UserControl x:Class="WpfApplication1.UserControl1"

It works. However, it does seem to be one of those situations where I screwed around with it for about 2 hours and by creating a new project fresh and adding in a User Control from the Project menu and copying in the code for the control, it started working.

Why?

I'm "devnulloper". I chose that name because I'm pretty much a void into which software developer knowledge disappears. While I have a lot of experience writing code, it seems whenever I try something new, self-teaching, I spend a lot of time on the "error" side of "trial and error".

I started this blog because I need a place to keep notes as I repeatedly try and fail and eventually succeed while writing software for Windows. If you are like me, and doing similar things, you will find the posts useful, because I tried (failed) to find the info on the web and pulled my hair out trying to get "stuff" to work. What stuff? Well, the topics will revolve around C#, VB.NET, and WPF.

/devnulloper