Example

  • 5 minutes to read

This example demonstrates cases of the DXBinding, DXCommand, and DXEvent markup extensions.

<UserControl x:Class="DXBindingExample.View.RelativeSourcesView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:v="clr-namespace:DXBindingExample.View"
             xmlns:vm="clr-namespace:DXBindingExample.ViewModel"
             xmlns:dxmvvm="http://schemas.devexpress.com/winfx/2008/xaml/mvvm"
             xmlns:sys="clr-namespace:System;assembly=mscorlib"
             mc:Ignorable="d" d:DesignHeight="600" d:DesignWidth="800"
             d:DataContext="{dxmvvm:ViewModelSource vm:RelativeSourcesViewModel}">
    <StackPanel Orientation="Vertical">
        <StackPanel Style="{StaticResource groupPanelStyle}">
            <TextBlock Text="ElementName Binding" Style="{StaticResource headerDescriptionStyle}"/>
            <TextBlock Text="DXBinding Expr: '@e(slider).Value'." Style="{StaticResource descriptionStyle}"/>
            <Slider x:Name="slider" Minimum="0" Maximum="100" Value="50" Margin="4,2,4,2"/>
            <TextBox Text="{DXBinding '@e(slider).Value', UpdateSourceTrigger=PropertyChanged}" Style="{StaticResource valueStyle}"/>
        </StackPanel>
        <StackPanel Style="{StaticResource groupPanelStyle}">
            <TextBlock Text="Self Binding" Style="{StaticResource headerDescriptionStyle}"/>
            <TextBlock Text="DXBinding Expr: '@s.Width'." Style="{StaticResource descriptionStyle}"/>
            <TextBox Text="{DXBinding '@s.Width', UpdateSourceTrigger=PropertyChanged}" Style="{StaticResource valueStyle}" Width="80" HorizontalAlignment="Left"/>
        </StackPanel>
        <StackPanel Style="{StaticResource groupPanelStyle}">
            <TextBlock Text="FindAncestor Binding" Style="{StaticResource headerDescriptionStyle}"/>
            <TextBlock Text="DXBinding Expr: '@a($UserControl).DataContext.Value'." Style="{StaticResource descriptionStyle}"/>
            <TextBox Text="{DXBinding '@a($UserControl).DataContext.Value', UpdateSourceTrigger=PropertyChanged}" Style="{StaticResource valueStyle}"/>
        </StackPanel>
        <StackPanel Style="{StaticResource groupPanelStyle}">
            <StackPanel.Resources>
                <sys:Int32 x:Key="resourceValue">42</sys:Int32>
            </StackPanel.Resources>
            <TextBlock Text="StaticResource Binding" Style="{StaticResource headerDescriptionStyle}"/>
            <TextBlock Text="DXBinding Expr: '@r(resourceValue)'." Style="{StaticResource descriptionStyle}"/>
            <TextBox Text="{DXBinding '@r(resourceValue)', Mode=OneTime}" IsReadOnly="True" Style="{StaticResource valueStyle}"/>
        </StackPanel>
    </StackPanel>
</UserControl>