Intersoft ClientUI Documentation
PropertyBinding Class
Members  See Also  Send Feedback
Intersoft.Client.Framework Namespace : PropertyBinding Class






Describes the members for property binding operation in BindingFramework.

Object Model

PropertyBinding Class

Syntax

Visual Basic (Declaration) 
<ContentPropertyAttribute("Values")>
Public Class PropertyBinding 
Visual Basic (Usage)Copy Code
Dim instance As PropertyBinding
C# 
[ContentPropertyAttribute("Values")]
public class PropertyBinding 
Delphi 
public class PropertyBinding 
JScript 
ContentPropertyAttribute("Values")
public class PropertyBinding 
Managed Extensions for C++ 
[ContentPropertyAttribute("Values")]
public __gc class PropertyBinding 
C++/CLI 
[ContentPropertyAttribute("Values")]
public ref class PropertyBinding 

Remarks

PropertyBinding is one of many functionality provided in ClientUI Advanced Binding Framework. To learn more about this see Data Binding Overview.

The XAML binding that uses {Binding ...} syntax cannot be defined in the Setter markup of Style because the Setter is not a dependency objeect. ClientUI Binding Framework provides a solution to address this limitation by introducing PropertyBinding.

PropertyBinding enables you overcome the Silverlight limitation so that you can define XAML data binding inside the Style. To understand how the property binding works, see the following example. 

Model Copy Code
using System.ComponentModel;
using System.Windows.Media;

namespace ClientUI.Samples.Models
{
    public class Product : INotifyPropertyChanged
    {
        private string _name;
        private string _category;
        private SolidColorBrush _categoryBrush;
      
        public string Name
        {
            get { return this._name; }
            set
            {
                if (this._name!= value)
                {
                    this._name= value;
                    this.OnPropertyChanged("Name");
                }
            }
        }

        public string Category
        {
            get { return this._category; }
            set
            {
                if (this._category != value)
                {
                    this._category = value;

                    switch (value)
                    {
                        case "Red":
                            this.CategoryBrush = new SolidColorBrush(Color.FromArgb(255, 255, 0, 0));
                            break;
                        case "Green":
                            this.CategoryBrush = new SolidColorBrush(Color.FromArgb(255, 0, 255, 0));
                            break;
                        case "Blue":
                            this.CategoryBrush = new SolidColorBrush(Color.FromArgb(255, 0, 0, 255));
                            break;
                        default:
                            this.CategoryBrush = new SolidColorBrush(Color.FromArgb(0, 0, 0, 0));
                            break;
                    }
                    this.OnPropertyChanged("Category");
                }
            }
        }

        public SolidColorBrush CategoryBrush
        {
            get { return this._categoryBrush; }
            set
            {
                if (this._categoryBrush != value)
                {
                    this._categoryBrush = value;
                    this.OnPropertyChanged("CategoryBrush");
                }
            }
        }

        protected void OnPropertyChanged(string propertyName)
        {
            if (this.PropertyChanged != null)
            {
                this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;
    }
}
View Model Copy Code
using System.Collections.ObjectModel;
using System.ComponentModel;
using ClientUI.Samples.Models;

namespace ClientUI.Samples.ViewModels
{
    public class MainPageViewModel : INotifyPropertyChanged
    {
        public MainPageViewModel()
        {
            this.Products = new ObservableCollection<Product>();
            this.Products.Add(new Product() { Category = "Red", Name = "Product 1" });
            this.Products.Add(new Product() { Category = "Red", Name = "Product 2" });
            this.Products.Add(new Product() { Category = "Blue", Name = "Product 3" });
            this.Products.Add(new Product() { Category = "Blue", Name = "Product 4" });
            this.Products.Add(new Product() { Category = "Green", Name = "Product 5" });            
        }

        private ObservableCollection<Product> _products;

        public ObservableCollection<Product> Products
        {
            get { return this._products; }
            set
            {
                if (this._products != value)
                {
                    this._products = value;
                    this.OnPropertyChanged("Products");
                }
            }
        }

        protected void OnPropertyChanged(string propertyName)
        {
            PropertyChangedEventHandler handler = PropertyChanged;

            if (handler != null)
            {
                handler(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;
    }
}
View Copy Code
<Intersoft:UXListBox ItemsSource="{Binding Products}" HorizontalAlignment="Center" VerticalAlignment="Center" Width="100">                  
    <Intersoft:UXListBox.ItemContainerStyle>
        <Style TargetType="Intersoft:UXListBoxItem">
            <Setter Property="Intersoft:BindingFramework.PropertyBinding">
                <Setter.Value>
                    <Intersoft:PropertyBinding>
                        <Intersoft:PropertyBinding Property="BorderBrush" Binding="{Binding CategoryBrush}"/>
                        <Intersoft:PropertyBinding Property="Content" Binding="{Binding Name}"/>
                    </Intersoft:PropertyBinding>
                </Setter.Value>
            </Setter> 
            <Setter Property="BorderThickness" Value="1"></Setter>
            <Setter Property="HorizontalContentAlignment" Value="Stretch"></Setter>
        </Style>
    </Intersoft:UXListBox.ItemContainerStyle>
</Intersoft:UXListBox>

This sample binds the UXListBox to a collection of products. Each product has a category that has different border coloring that bound to the BorderBrush of UXListBoxItem.

Inheritance Hierarchy

System.Object
   Intersoft.Client.Framework.PropertyBinding

Requirements

Target Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, Windows Vista, Windows Server 2008 family

See Also

© 2012 All Rights Reserved.