T
The type of the resource to observe.
Intersoft ClientUI Documentation
ObservableResource<T> Class
Members  See Also  Send Feedback
Intersoft.Client.Framework Namespace : ObservableResource<T> Class






Represents an observable resource which automatically updates UI elements when the value of its resource has changed.

Object Model

ObservableResource<T> Class

Syntax

Visual Basic (Declaration) 
Public Class ObservableResource(Of T) 
   Implements IObservableResource 
Visual Basic (Usage)Copy Code
Dim instance As ObservableResource(Of T)
C# 
public class ObservableResource<T> : IObservableResource  
Delphi 
public class ObservableResource = class(IObservableResource)
JScript 
JScript does not support Generics.
Managed Extensions for C++ 
public __gc class ObservableResource<T> : public IObservableResource  
C++/CLI 
generic<typename T>
public ref class ObservableResource : public IObservableResource  

Type Parameters

T
The type of the resource to observe.

Remarks

At the heart of the ClientUI Localization Framework are the LocalizationManager and ObservableResource<T> classes. The LocalizationManager contains the core implementation that processes the culture changes and consequently notifies the active observable resources. The ObservableResource<T> class implements IObservableResource interface to provide capability to track and monitor whether a localized resource has changed, which automatically updates the source elements on which the resource was bound to.

The first step to get started with ClientUI Localization Framework is to create an observable resource that wraps the resource assets in your application. Before continuing, you will need to configure your Silverlight or WPF project to support multiple cultures. For more information on creating localizable Silverlight project, see Walkthrough: Create a Localizable Silverlight Project.

You define one observable resource for each resource asset in your application, which is generally classified as the model in an MVVM application. To define an observable resource, you create a new class that derives from ObservableResource<T> and specify the type of the resource that you would like to observe, and finally create a constructor that pass-in a new instance of the localized resource class.

The following code shows how to create a new observable resource class that encapsulates an existing resource asset.

CS Copy Code
public class MyAppResource : Intersoft.Client.Framework.ObservableResource<Resources>
{
    public MyAppResource()
        : base(new Resources())
    {
    }
}

Consuming the observable resource class in your XAML page is easy and straighforward. You create the mapping to the namespace that contains the observable resource class and define it as a static resource in the Resources of your XAML page.

The following code shows how to bind a simple TextBlock to the localized TodayText resource.

XAML Copy Code
<Intersoft:UXPage 
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:Models="clr-namespace:ClientUILocalizationManager.Models">
        
        <Intersoft:UXPage.Resources>

                <Models:MyAppResource x:Key="AppResource"/>

        </Intersoft:UXPage.Resources>

        <StackPanel>
                <TextBlock Text="{Binding Resource.TodayText, Source={StaticResource AppResource}}">
        </StackPanel>

</Intersoft:UXPage>

With the observable resource class defined as a static resource in the top most Resources of the page hierarchy, you can bind the UI elements to the desired localized string by using the {Binding} declaration. To learn more about data binding, see Data Binding Overview.

For more information about building localizable applications using ClientUI, see Localization Overview.

Inheritance Hierarchy

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.