Skip to main content
All docs
V25.1
  • UIObjectService Class

    Allows you to write View Model code that can access UI objects in a View and does not reference the object’s type.

    Namespace: DevExpress.Mvvm.UI

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

    NuGet Package: DevExpress.Wpf.Core

    Declaration

    [TargetType(typeof(FrameworkElement))]
    public class UIObjectService :
        ServiceBase,
        IUIObjectService

    Remarks

    Run Demo: UIObjectService

    The UIObjectService implements the IUIObjectService interface that has the following declaration:

    public interface IUIObjectService {
        dynamic Object { get; }
    }
    

    The Object property returns the associated object of the dynamic type to not reference the object’s real type in the View Model and maintain a clean MVVM pattern.

    Example

    The following code sample uses the UIObjectService to access the GridControl and TableView objects:

    <dxg:GridControl ItemsSource="{Binding Source}" AutoGenerateColumns="AddNew">
        <dxmvvm:Interaction.Behaviors>
            <dxmvvm:UIObjectService x:Name="gridControlService"/>
        </dxmvvm:Interaction.Behaviors>
        <dxg:GridControl.View>
            <dxg:TableView ...>
                <dxmvvm:Interaction.Behaviors>
                    <dxmvvm:UIObjectService x:Name="tableViewService"/>
                </dxmvvm:Interaction.Behaviors>
            </dxg:TableView>
        </dxg:GridControl.View>
    </dxg:GridControl>
    <Button Content="Export to PDF" Command="{Binding ExportToPdfCommand}"/>
    <Button Content="Filter" Command="{Binding ApplyFilterCommand}"/>
    
    using DevExpress.Mvvm;
    using DevExpress.Mvvm.DataAnnotations;
    
    public class MainViewModel : ViewModelBase {
        // ...
        public IUIObjectService GridService { get { return GetService<IUIObjectService>("gridControlService"); } }
        public IUIObjectService TableViewService { get { return GetService<IUIObjectService>("tableViewService"); } }
    
        [Command]
        public void ApplyFilter() {
            GridService.Object.FilterString = "[Quantity] >= 50";
        }
        [Command]
        public void ExportToPdf() {
            TableViewService.Object.ExportToPdf(@"C:\Work\Documents\GridExport.pdf");
        }
    }
    

    Refer to the following help topic for more information: UIObjectService.

    Inheritance

    Show 11 items
    Object
    DispatcherObject
    DependencyObject
    Freezable
    Animatable
    DevExpress.Mvvm.UI.Interactivity.AttachableObjectBase
    DevExpress.Mvvm.UI.Interactivity.Behavior
    DevExpress.Mvvm.UI.Interactivity.Behavior<FrameworkElement>
    DevExpress.Mvvm.UI.ServiceBaseGeneric<FrameworkElement>
    ServiceBase
    UIObjectService
    See Also