Skip to main content
A newer version of this page is available. .

DependencyPropertyBehavior Class

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

Namespace: DevExpress.WinUI.Core

Assembly: DevExpress.WinUI.Core.v22.1.dll

NuGet Package: DevExpress.WinUI

Declaration

public class DependencyPropertyBehavior :
    Behavior<DependencyObject>

Remarks

Run Demo: Behaviors Module in the WinUI MVVM Demo

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

Property Description
Binding Gets or sets the binding that should be applied to the specified property. This is a dependency property.
EventName Gets or sets the name of the event the DependencyPropertyBehavior handles to update the binding.
PropertyName Gets or sets a control’s property name (the binding’s target).

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

<UserControl ...
    xmlns:dxc="using:DevExpress.WinUI.Core">
    <Grid>
        <!-- ... -->
        <TextBox Grid.Row="1" Text="{x:Bind ViewModel.Text}" TextWrapping="Wrap">
            <dxc:Interaction.Behaviors>
                <dxc:DependencyPropertyBehavior EventName="SelectionChanged" PropertyName="SelectedText"
                                                Binding="{x:Bind ViewModel.SelectedText, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
            </dxc:Interaction.Behaviors>
        </TextBox>
        <!-- ... -->
        <TextBlock Grid.Row="3" TextWrapping="Wrap"
                   Text="{x:Bind ViewModel.SelectedText, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" />
    </Grid>
</UserControl>
using DevExpress.Mvvm;
using DXSample.Common;

namespace DXSample.ViewModel {
    public class MainViewModel : ViewModelBase {
        public string SelectedText {
            get { return GetValue<string>(); }
            set { SetValue(value); }
        }
        public string Text {
            get { return GetValue<string>(); }
            set { SetValue(value); }
        }
        public MainViewModel() {
            Text = DataHelper.GetData();
        }
    }
}
using DXSample.ViewModel;
using Microsoft.UI.Xaml.Controls;

namespace DXSample.View {
    public sealed partial class MainView : UserControl {
        public MainViewModel ViewModel { get; } = new MainViewModel();
        public MainView() {
            this.InitializeComponent();            
        }
    }
}

Inheritance

See Also