DK Development

The random output of a Windows developer.

DK Development

The random output of a Windows developer.




Fluid.NET controls for Windows Mobile 6

Lately I have been making an application for Windows mobile but I am pretty bad with design so I was looking for a control toolkit and came across the Fluid.NET controls, which is an open source control toolkit for Windows Mobile. Now there wasn't too much documentation on the site and it hadn't been updated for a while but they had a pretty decent looking example application which they offered the source for.

Screenshot1I based my project off their example, took me a while to figure out how to use some of their controls but now i have a bit more of an idea and i thought I'd share it.

Basically I'm trying to use the Fluid.NET listbox control to display the file system (so i can select a folder).

I started by using the ListBoxBase class from PasswordSafe, this class handles the general list type stuff, like changing the colour of selected list items etc.

Then I created a new Fluid Template this is the class used by the ListBox to populate the items in the list. Item layout goes in the InitControl() method then the actual content of the Item (In my case its based off a DirectoryInfo object) goes in the OnBindValue() method.

public class AddFolderTemplate : FluidTemplate
{
    private FluidLabel nameLabel;
    private FluidLabel secondaryLabel;

    protected override void InitControl()
    {
        base.InitControl();
        this.Bounds = new Rectangle(0, 0, 240, 64);
        nameLabel = new FluidLabel("", 3, 0, 228, 64 - 3);
        Controls.Add(l);
        secondaryLabel = new FluidLabel("", 8, 62 - 12, 224, 12);
        Controls.Add(l);
    }
    protected override void OnBindValue(object value)
    {
        var folder = value as DirectoryInfo;
        if (folder != null)
        {
            nameLabel.Text = folder.Name;
            secondaryLabel.Text = folder.FullName;
        }
    }
}

After I had the Template done I then created my listbox class (inheriting from the ListBoxBase) This class didnt need to do too much as most of the work is done in its base and the panel it goes in.

public class AddFolderListBox : ListBoxBase
{
    private NotifyList folders;
    public event EventHandler FolderSelected;

    protected override void InitControl()
    {
        base.InitControl();
        ItemHeight = 32;

        ItemTemplate = new AddFolderTemplate();
    }
    public NotifyList Folders
    {
        get { return folders; }
        set
        {
            if (folders != value)
            {
                folders = value;
                DataSource = value;
            }
        }
    }
    ...
}

Now that we’ve got the classes done, time to put them to use. I have created a panel for browsing through the file system. All we need to do here is create an instance of our Listbox control and add a list of folders to the Folders Property.

Controls.Add(lsbFolders);
CurrentDir = new DirectoryInfo("/");
lsbFolders.Folders = MakeDirList(CurrentDir.GetDirectories());

This then loads all the folders in the devices root into the listbox. I have also added to the OnItemClick event to go deeper into the file system and a back button to go back to the parent directory.

blog comments powered by Disqus