Home arrow XML arrow Page 2 - An Introduction to XUL Part 6

Stylesheet - XML

Learn about XUL, a subset of XML used to describe user interfaces, that helps you to make rich user interfaces with nothing more complicated than a text editor. In the sixth part of this series learn about XBL, another of XMLs many faces and a partner in crime with XUL, also called XML Binding Language.

TABLE OF CONTENTS:
  1. An Introduction to XUL Part 6
  2. Stylesheet
  3. Customization
  4. Adding the Code to our XUL
By: Dan Wellman
Rating: starstarstarstarstar / 10
June 27, 2005

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

Next up, you need to create the stylesheet that will point to the binding:

menubar.mymenu { 
    -moz-binding: url('example.xml#defaultmenu');
}

This simply defines a class of a menubar pointing at the binding id.  This is done with the filename of the binding file followed by the # symbol followed by the id of the binding element you wish to use.  The moz-binding: prefix is a special CSS property that tells the stylesheet file that youre binding to an XBL file.  Because the binding file we are using is very basic and contains only one binding element, this could be omitted.  Save this file as bindingexample.css in the same location that the first file was saved.

Finally, create the XUL file that references the binding style sheet:

<?xml version="1.0"?>
<?xml-stylesheet href="example.css" type="text/css"?>
<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/
  there.is.only.xul">
  <menubar id="xblmenu" class="mymenu"></menubar>
</window>

The xml-stylesheet reference points at the CSS file, which in turn points to the binding.  Save this file as bindingexample.XUL, again in the same location as the above two.  You neednt open this via a chrome URL (although for real-world XBL usage it is advisable), so revert to the command line call used in the first couple of articles.  You should get a very small window containing the default menubar at the top.  As the class has been assigned specifically to the menubar tag, you are free to define menubars in the XUL file that will not inherit the menu items defined in the binding tag.  Add another menubar element to the XUL file without declaring the style class and it should appear as normal beneath the XBL menu:

<menubar id="nonxblmenu">
    <menu label="special"/>
</menubar>

However, if you then assign the second menu to the mymenu class, the menu you have added manually will override the menu elements defined in the XBL file and they will not appear in the second menu.  You can get around this by using the <children/> element in the XBL file.  Add the element beneath the <XUL:menu> elements and then execute the file again.  Now the menus defined in the XBL will be there, with the special menu in the location that the children element appears (i.e. after the other menus).  The power this gives you when designing applications is phenomenal; you can define a default menu set that you want to appear in all of your applications, and then just tweak the XUL files to add any additional menus relevant to the application youre building.  This promotes code reuse, which is something pushed by all modern programming languages.



 
 
>>> More XML Articles          >>> More By Dan Wellman
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

XML ARTICLES

- Google Docs and Xpath Data Functions
- Flex Array Collection Sort and Filtering
- The Flex Tree Control
- Flex List Controls
- Working with Flex and Datagrids
- How to Set Up Podcasting and Vodcasting
- Creating an RSS Reader Application
- Building an RSS File
- An Introduction to XUL Part 6
- An Introduction to XUL Part 5
- An Introduction to XUL Part 4
- An Introduction to XUL Part 3
- An Introduction to XUL Part 2
- An Introduction to XUL Part 1
- XML Matters: Practical XML Data Design and M...

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: