Getting Started with Coding4Fun Button Controls
published on: 1/11/2012 | Views: N/A | Tags: C4FToolkit
by WindowsPhoneGeek
In this article I am going to talk about the Coding4fun Toolkit button controls in details. I will explain everything about the main features, available public API, and will give lots of examples in different scenarios.
NOTE: About an year ago we posted the "WP7 RoundToggleButton and RoundButton in depth" article, however this post is not relevant any more since things have changed significantly during the last few releases of the toolkit!
Basically Coding4Fun toolkit offers RoundButton and RoundToggleButton controls. RoundToggleButton is an UI component that derives from CheckBox and exposes several additional dependency properties. As its name says it is some kind of extended toggle button with round shape and automatic inverted image support. RoundButton is a kind of extended button which derives from Button, has a round shape and offers automatic inverted image support.
Getting Started
To begin using RoundButton and RoundToggleButton first add a reference to the Coding4Fun.Phone.Controls.dll assembly.
NOTE: You can download this assembly from here: Coding4Fun Toolkit .
The next step is to add the "c4f" prefix declaration. Make sure that your page declaration includes the "c4fToolkit" namespace:
xmlns:c4f="clr-namespace:Coding4Fun.Phone.Controls;assembly=Coding4Fun.Phone.Controls"
The sample code should looks like:
<c4f:RoundButton/> <c4f:RoundToggleButton/>
Key Properties
The RoundToggleButton control derives all properties and events from the CheckBox class. The RoundButton control derives all properties and events from the Button class.
- Content
This property comes from the parent class and is used to set the content of the RoundToggleButton / RoundButton.
Both button controls expose the following additional public properties:
- ImageSource
ImageSource is a dependency property of type ImageSource. It gets or sets the Image of the RoundToggleButton / RoundButton controls.
- Orientation
Orientation is a dependency property of type Orientation. It gets or sets the content orientation of the RoundToggleButton / RoundButton.
- Examples
In the below examples we will use the following two icons:
NOTE: Icons will automatically change appropriately in Light theme, you do not need to do anything else!
Example1: RoundButton sample usage
This example demonstrates how to set the common RoundButton properties.Just add the following code in the XAML part of your page:
<StackPanel Orientation="Horizontal">
<c4f:RoundButton
FontSize="18"
Content="OK"
BorderBrush="CornflowerBlue" />
<c4f:RoundButton
FontSize="48"
Content="48"
Background="CornflowerBlue" />
<c4f:RoundButton
Foreground="CornflowerBlue"
FontSize="36"
Content="36" />
<c4f:RoundButton
ImageSource="Images/appbar.delete.rest.png"
Content="Delete" />
</StackPanel>
Here is how the result should look like in Dark and Light themes:
Example2: RoundButton Orientation and ImageSource usage.
<c4f:RoundButton Orientation="Horizontal" ImageSource="Images/appbar.feature.search.rest.png" Content="horizontal text" />
Example3. RoundToggleButton sample usage
This example demonstrates how to set the common RoundToggleButton properties. Just add the following code in the XAML part of your page:
<StackPanel Orientation="Horizontal">
<c4f:RoundToggleButton
FontSize="18"
Content="ok"
BorderBrush="CornflowerBlue" />
<c4f:RoundToggleButton
FontSize="48"
Content="48"
Background="CornflowerBlue" />
<c4f:RoundToggleButton
Foreground="CornflowerBlue"
FontSize="36"
Content="36" />
<c4f:RoundToggleButton
ImageSource="Images/appbar.delete.rest.png"
Content="DELETE" />
</StackPanel>
Example4: RoundToggleButton Orientation and ImageSource usage.
<c4f:RoundToggleButton Orientation="Horizontal" ImageSource="Images/appbar.feature.search.rest.png" Content="horizontal text" />
Example5: RoundButton and RoundToggleButton disable.
<c4f:RoundButton x:Name="btn" IsEnabled="False" Orientation="Horizontal" ImageSource="Images/appbar.delete.rest.png" Content="disabled button" />
That was all about the RoundButton /RoundToggleButton controls from the Coding4fun Toolkit in depth. You can find the full source code here:
I hope that the article was helpful.
You can also follow us on Twitter @winphonegeek
Comments
Thanks you for the updated post
posted by: J. Karhan on 1/11/2012 3:57:13 PM
Thanks you for the updated post. Really appreciate it. Cheers!
Custom images
posted by: Atley on 5/5/2012 1:45:02 PM
Finding it hard to render the round button with any custom images.
I have tried setting them as Resource and as Content. coud you perhaps post an example of using a non-standard button of a non-icon size?
Thanks, Atley
New! WindowsPhoneGeek Component Marketplace
Our Top Articles & Free books
- Our FREE e-book: "Windows Phone Toolkit In Depth" 2nd edition
- 400+ Windows Phone Development articles in our Article Index
- 21 WP7 Toolkit in Depth articles covering all controls
- 12 WP7 Coding4Fun Toolkit in Depth articles covering all controls
- Performance Tips when creating WP7 apps
- Creating a WP7 Custom Control in 7 Steps
- WP7 working with VisualStates: How to make a ToggleSwitch from CheckBox
- What makes a WP7 App successful
- Creating theme friendly UI in WP7 using OpacityMask
- Implementing Windows Phone 7 DataTemplateSelector and CustomDataTemplateSelector
Our Top Tips & Samples
- All about WP7 Isolated Storage series
- WP7 Dynamically Generating DataTemplate in code
- 5 tips for a successful WP7 Marketplace submission
- WP7: Navigating to a page in different assembly
- WP7 ContextMenu: answers to popular questions
- WP7 ListBox: answers to popular questions
- WP7 working with Images: Content vs Resource build action
- WP7 Element Binding samples
- WP7 working with XML: reading, filtering and databinding
- Drawing in WP7: #2 Drawing shapes with finger
- WP7 TextBox Light theme problems - the solution
- Changing the WP7 Panorama Background Image dynamically with Animation
