<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>BlackBerry Developer Blog &#187; property alias</title>
	<atom:link href="http://devblog.blackberry.com/tag/property-alias/feed/" rel="self" type="application/rss+xml" />
	<link>http://devblog.blackberry.com</link>
	<description></description>
	<lastBuildDate>Thu, 23 May 2013 19:58:12 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='devblog.blackberry.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://1.gravatar.com/blavatar/9ef0a66c09615fa946c4179662398878?s=96&#038;d=http%3A%2F%2Fs2.wp.com%2Fi%2Fbuttonw-com.png</url>
		<title>BlackBerry Developer Blog &#187; property alias</title>
		<link>http://devblog.blackberry.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://devblog.blackberry.com/osd.xml" title="BlackBerry Developer Blog" />
	<atom:link rel='hub' href='http://devblog.blackberry.com/?pushpress=hub'/>
		<item>
		<title>QML/Cascades tip of the day – Property Aliases</title>
		<link>http://devblog.blackberry.com/2012/07/qml-tip-property-aliases/</link>
		<comments>http://devblog.blackberry.com/2012/07/qml-tip-property-aliases/#comments</comments>
		<pubDate>Wed, 18 Jul 2012 13:06:48 +0000</pubDate>
		<dc:creator>Alex Kinsella</dc:creator>
				<category><![CDATA[Cascades]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[property alias]]></category>
		<category><![CDATA[QML]]></category>
		<category><![CDATA[tip]]></category>

		<guid isPermaLink="false">http://devblog.blackberry.com/?p=10246</guid>
		<description><![CDATA[This week's QML/Cascades tip focuses on creating property aliases and why they'll be your friend when creating custom components in QML.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=devblog.blackberry.com&#038;blog=17235680&#038;post=10246&#038;subd=rimdevblog&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p><em>Here&#8217;s <a href="https://twitter.com/marioboikov">Mario</a> with another handy QML/Cascades tip &#8211; Ed.</em></p>
<p>In today&#8217;s post, I&#8217;ll talk about <em>property aliases</em> and why they&#8217;ll be your friend when creating custom components in QML. I&#8217;ll give you an introduction to the topic by creating a Header component, which consists of a Label and a Divider wrapped inside a Container.</p>
<p>I assume that you already know how to create custom components in QML. Basically you create a new file and name it to whatever the name of your component is, for example &#8216;Header.qml&#8217;. So say we have a file &#8216;Header.qml&#8217; with the following content:</p>
<pre>import bb.cascades 1.0

Container {

    Label {
        id: titleLabel
        text: "Sample Title"
        textStyle.base: SystemDefaults.TextStyles.TitleText
    }

    Divider {
    }
}</pre>
<p><span id="more-10246"></span></p>
<p>To create a Header instance from another QML file, we simply write the following lines:</p>
<pre>...

Header {
}

...</pre>
<p>Looks good, but I assume that we also want to set the title to something more appropriate for the context where the header is to be used. Because we don&#8217;t have direct access to the Label&#8217;s text property from outside the Header component (you can only access top level properties), we need to add a new property to the Container in the Header component:</p>
<pre>import bb.cascades 1.0

Container {
    property string titleText: “Sample Title”

    Label {
        id: titleLabel
        text: titleText
        textStyle.base: SystemDefaults.TextStyles.TitleText
    }

    Divider {
    }
}</pre>
<p>The Label&#8217;s text property binds to the newly added <em>titleText</em> property. Now we can specify a title by setting the titleText property:</p>
<pre>Header {
    titleText: “My Header”
}</pre>
<p>Looks nice and works great, but I&#8217;m still not satisfied. I had to introduce a new property just to be able to specify a title text. What I actually want is to expose the Label&#8217;s <em>text</em> property to users of the Header component. Fortunately there&#8217;s a solution for this, and the name is <em>property alias</em>:</p>
<pre>import bb.cascades 1.0

Container {
    property alias titleText: titleLabel.text

    Label {
        id: titleLabel
        text: “Sample Title”
        textStyle.base: SystemDefaults.TextStyles.TitleText
    }

    Divider {
    }
}</pre>
<p>Much better. We got rid of the <em>titleText</em> property by simply making it an alias to the titleLabel&#8217;s <em>text</em> property instead. Even the instance of the Label can be exposed as an alias, which gives you access to all of the Label&#8217;s properties, if that&#8217;s what you need:</p>
<pre>import bb.cascades 1.0

Container {
    property alias titleLabel: titleLabel

    Label {
        id: titleLabel
        text: “Sample Title”
        textStyle.base: SystemDefaults.TextStyles.TitleText
    }

    Divider {
    }
}</pre>
<p>Now that we have access to all of the Label&#8217;s properties, we can also change the text style:</p>
<pre>Header {
    titleLabel {
        text: “My Title”
        textStyle.base: SystemDefaults.TextStyles.TitleText
    }
}</pre>
<p>Handy, right?</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/rimdevblog.wordpress.com/10246/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/rimdevblog.wordpress.com/10246/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=devblog.blackberry.com&#038;blog=17235680&#038;post=10246&#038;subd=rimdevblog&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://devblog.blackberry.com/2012/07/qml-tip-property-aliases/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/7d0e94a7e96e80d5911732d43f31a39c?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Alex K.</media:title>
		</media:content>
	</item>
	</channel>
</rss>
