[This is preliminary documentation and is subject to change.]

Represents a markup extension that binds the Text property of a WPF TextBox, to the Source property of a view (usually a WebControl), manipulates the bound TextBox and manages its relationship with the source IWebView instance.

Namespace: Awesomium.Windows.Data
Assembly: Awesomium.Windows.Controls (in Awesomium.Windows.Controls.dll) Version: 1.7.0.5 (1.7.0.5)

Syntax

C#
public class SourceBinding : MarkupExtension, 
	IWeakEventListener
Visual Basic
Public Class SourceBinding _
	Inherits MarkupExtension _
	Implements IWeakEventListener
Visual C++
public ref class SourceBinding : public MarkupExtension, 
	IWeakEventListener

Remarks

Besides binding the Text property of a WPF TextBox, to the Source property of a web-view, the SourceBinding class significantly simplifies your code by monitoring user input and maintaining the proper relationship of the bound TextBox with the source IWebView instance.

The following list summarizes the features provided by SourceBinding, when applied to the Text property of a WPF TextBox:

  • Keeps the contents of the TextBox updated with the textual representation of the current Source.
  • When the user updates the contents of the TextBox, SourceBinding explicitly updates the source Source property, only when the Return key is being pressed.
  • Applies proper value conversion. For example, a null Source property will be presented as about:blank and any string will be properly parsed before passed to the IWebView instance.
    Note
    Value conversion is provided through the UriValueConverter, that can also be used with other bindings in your application.
  • Monitors the appropriate events and applies the required logic so that your TextBox behaves as an address-box. For example, when the TextBox gets keyboard focus, all contents are automatically selected; when it looses keyboard focus, the contents are updated to reflect the current value of Source.
  • Manages focus toggling of the bound TextBox and the source IWebView instance, whenever necessary.
Note
The SourceBinding utilizes the WPF weak event model to monitor events. This prevents potential memory leaks.

Weak event handling support is provided through the InputEventManager and the implementation of IWeakEventListener. The InputEventManager is available for you to use anywhere else in your project.

Examples

The following example presents the usage of SourceBinding, in XAML.
CopyXAML
<Window 
    x:Class="WpfApplication1.MainWindow" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:awe="http://schemas.awesomium.com/winfx"
    xmlns:data="http://schemas.awesomium.com/winfx/data"
    Height="480" 
    Width="640">
    <Window.Title>
        <Binding 
            Path="Title" 
            ElementName="webControl" 
            StringFormat="Awesomium Simple WPF Sample - {0}"/>
    </Window.Title>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition />
        </Grid.RowDefinitions>
        <Grid 
            x:Name="toolbarContainer" 
            MinHeight="30">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition />
            </Grid.ColumnDefinitions>
            <Button 
                Margin="2" 
                Padding="3"
                Command="BrowseBack" 
                CommandTarget="{Binding ElementName=webControl}">
                Back
            </Button>
            <Button 
                Grid.Column="1" 
                Margin="2" 
                Padding="3"
                Command="BrowseForward" 
                CommandTarget="{Binding ElementName=webControl}">
                Forward
            </Button>
            <Button 
                Grid.Column="2" 
                Margin="2" 
                Padding="3"
                Command="Refresh" 
                CommandParameter="False" 
                CommandTarget="{Binding ElementName=webControl}">
                Refresh
            </Button>
            <Button 
                Grid.Column="3" 
                Margin="2" 
                Padding="3"
                Command="BrowseHome" 
                CommandTarget="{Binding ElementName=webControl}">
                Home
            </Button>
            <!-- Address box. -->
            <TextBox 
                x:Name="addressBox" 
                Grid.Column="4"
                Margin="3"
                VerticalContentAlignment="Center" 
                Text="{data:SourceBinding webControl}"/>
        </Grid>
        <!-- WebControl -->
        <awe:WebControl 
            x:Name="webControl" 
            Grid.Row="1" 
            BorderThickness="0,1,0,0" 
            BorderBrush="Gray"
            Source="http://www.awesomium.net"/>
    </Grid>
</Window>

Inheritance Hierarchy

System..::..Object
  System.Windows.Markup..::..MarkupExtension
    Awesomium.Windows.Data..::..SourceBinding

See Also