Back to Devexpress

DependencyPropertyBehavior Class

wpf-devexpress-dot-mvvm-dot-ui-e36834a5.md

latest4.0 KB
Original Source

DependencyPropertyBehavior Class

Allows you to bind a ViewModel property to a control’s non-dependency property.

Namespace : DevExpress.Mvvm.UI

Assembly : DevExpress.Xpf.Core.v25.2.dll

NuGet Package : DevExpress.Wpf.Core

Declaration

csharp
public class DependencyPropertyBehavior :
    Behavior<DependencyObject>
vb
Public Class DependencyPropertyBehavior
    Inherits Behavior(Of DependencyObject)

Remarks

To bind a ViewModel property to a control’s non-dependency property, specify the following DependencyPropertyBehavior properties:

PropertyDescription
BindingGets or sets the binding that should be applied to the specified property. This is a dependency property.
EventNameGets or sets the name of the event the DependencyPropertyBehavior handles to update the binding.
PropertyNameGets or sets a control’s property name (the binding’s target).

The following code sample binds the ViewModel’s SelectedTextBoxText property to the TextBox.SelectedText non-dependency property:

xaml
<UserControl x:Class="Example.View.MainView"
<!-- ... -->
    xmlns:dxmvvm="http://schemas.devexpress.com/winfx/2008/xaml/mvvm"
    <!-- ... -->
        <StackPanel Orientation="Horizontal" VerticalAlignment="Top">
            <!--The TextBox.SelectedText property is not a dependency property-->
            <TextBox Width="200" Text="Select some text in this box">
                <dxmvvm:Interaction.Behaviors>
                    <dxmvvm:DependencyPropertyBehavior PropertyName="SelectedText" EventName="SelectionChanged" Binding="{Binding SelectedTextBoxText, Mode=TwoWay}"/>
                </dxmvvm:Interaction.Behaviors>
            </TextBox>
            <TextBox Width="200" Text="{Binding SelectedTextBoxText}" IsReadOnly="True"/>
        </StackPanel>
        <!-- ... -->
</UserControl>
csharp
using DevExpress.Mvvm;

namespace Example.ViewModel {
    public class MainViewModel : ViewModelBase {
        public virtual string SelectedTextBoxText { get; set; }
    }
}
vb
Imports DevExpress.Mvvm

Namespace Example.ViewModel

    Public Class MainViewModel
        Inherits ViewModelBase

        Public Overridable Property SelectedTextBoxText As String
    End Class
End Namespace

Run Demo: Behaviors Module in the WPF MVVM Demo

Inheritance

Object DispatcherObject DependencyObject Freezable Animatable DevExpress.Mvvm.UI.Interactivity.AttachableObjectBase DevExpress.Mvvm.UI.Interactivity.Behavior DevExpress.Mvvm.UI.Interactivity.Behavior<DependencyObject> DependencyPropertyBehavior

See Also

DependencyPropertyBehavior Members

Behaviors

DevExpress.Mvvm.UI Namespace