October 2007 - Posts - Peter's Software House

October 2007 - Posts

MicroWind Generator

Wow!!!

This was sent around by Trey Guinn at work, and I was amazed. Since this is perfect for countries like the ones in Africa I just had to post about it.

Third-World Wind Power: First Look

Posted by Pieter | with no comments
Filed under:

IBindingList

Today I had a List<> that changed its items based on things that happen elsewhere in the application.

No problem there, but the list was assigned to a BindingSource that was not updating with the new/updated items. This is where IBindingList comes in. I implemented it on my list and made a call to the ListChangedEventHandler and I passed it a ListChangedEventArgs with a ListChangedType of Reset. And my BindingSource was now refreshing correctly.

 

public class SomeList : List<SomeObject>, IBindingList
{
// IBindingList Code
#region IBindingList Members
private ListChangedEventArgs resetEvent = new ListChangedEventArgs(ListChangedType.Reset, -1);

private ListChangedEventHandler onListChanged;

 

// I call this whenever my list changes
protected virtual void OnListChanged()

{

if (onListChanged != null)

{

onListChanged(this, new ListChangedEventArgs(resetEvent));

}

}

 

protected virtual void OnListChanged(ListChangedEventArgs ev)

{

if (onListChanged != null)

{

onListChanged(this, ev);

}

}

 

event ListChangedEventHandler IBindingList.ListChanged

{

add

{

onListChanged += value;

}

remove

{

onListChanged -= value;

}

}

 

// more Code …
#endregion
}

Posted by Pieter | with no comments

How to get the XAML from a WPF Visual Element

This is just so easy it is not funny:

string destXpsFile = @"c:\test.xaml";

// Delete the file if it already exists

File.Delete(destXpsFile);

using (FileStream fs = File.Create(destXpsFile))

{

XamlWriter.Save(this, fs);

fs.Close();

}

In this case the code is called from a UserControl and just prints the current UserControl.

This example saves the XAML to a file.

Posted by Pieter | with no comments

Thanks Armand

Armand has done a fantastic job in getting the server back online.

I spoke to him yesterday @4:30am South African time and he was hard at it.

A long night for him, and I just wanted him to know that we appreciate the effort. He is keeping this site running in his own free time.

Cheers Armand, hope you get some sleep soon.

Posted by Pieter | 2 comment(s)

Creating an XPS document from a XAML control

This is so simple it just isn't funny.

I needed to create a simple one page XPS document from a XAML control that I show in a form to a client and this little bit of test code works perfectly:

string containerName = @"c:\test.xps";

 

// Delete the file if it already exists

File.Delete(containerName);

 

// Create an XPS Document for saving

using (XpsDocument _xpsDocument = new XpsDocument(containerName, FileAccess.ReadWrite))

{

XpsDocumentWriter xpsdw = XpsDocument.CreateXpsDocumentWriter(_xpsDocument);

 

xpsdw.Write(this.LayoutRoot);

 

// Close the pakcage

_xpsDocument.Close();

}

 

The [this.LayoutRoot] is a Grid inside my control that has the information I want to show in the XPS file, but it can be any WPF control that inherits from System.Windows.Media.Visual.

Posted by Pieter | with no comments

Testing blog post from Word 2007

 

I've been extremely busy (still am in fact) but there has been a few things I have found that I wanted to blog about and could not do so easily as I could not install my favorite blogging tool (Windows Live Writer) as I am running win2003 on my work PC at the moment. And yes I know I could have created a VM with XP to do so, but time is not on my side at the moment. Until this morning that is when I realized I have been a bit of a fool. Yes, I have Office 2007 and you can blog from Word 2007…

So I hope to catch up in the next few weeks with some new blog posts.

Posted by Pieter | with no comments
Filed under: ,