Quantcast
Channel: DevExpress Support Center (Examples)
Viewing all 7205 articles
Browse latest View live

How to embed a bar into a dock panel

$
0
0

This example shows how to embed a bar from the DXBars library into a dock panel.

Dock panels embed bar containers at their top edges, allowing bars to be displayed in these containers. To add a bar to a dock panel's bar container, the name of the target bar container is assigned to the Bar.DockInfo.ContainerName property. This name matches the name of the LayoutPanel.HeaderBarContainerControlName property's value.


How to customize a panel's context menu via actions

How to associate a command provided by the DXDocking library with a button

$
0
0

The DXDocking library provides a set of commands on dock panels. These are declared in the DockControllerCommand class. For instance, the Close command allows you to close a specific dock panel. The Activate command activates a dock panel.
This example shows how to associate the Close command with a button. When an end-user clicks the button, the active dock panel is closed.

How to load an external Window/UserControl into a DocumentPanel

$
0
0

You can define a Window, Page or UserControl in external XAML files and then, with DXDocking, load their contents into DocumentPanel objects.

This example demonstrates how to load an external Window and UserControl into DocumentPanels.

In the example three approaches are demonstrated:

1) The contents of MyWindow.xaml is loaded into a DocumentPanel at design time (in XAML) via the DocumentPanel.Content property. The Content property accepts a Uri object, which must refer to a XAML file defining a Window, Page or UserControl.

[XAML]
<dxdo:DocumentPanelx:Name="docPanel2"Caption="Panel 2"Content="{dxdo:RelativeUri UriString=CustomWindows\\MyWindow.xaml}"/>


2) The DocumentPanel.Content property is set with a Uri object at runtime:

[C#]
docPanel1.Content=newUri(@"CustomWindows\MyWindow1.xaml",UriKind.Relative);

 

3) The DockLayoutManager.DockController.AddDocumentPanel method creates a new DocumentPanel object and loads the contents of an external XAML file into the created panel.

[C#]
panel1=dockLayoutManager1.DockController.AddDocumentPanel(documentGroup1,newUri(@"CustomWindows\UserControl1.xaml",UriKind.Relative));panel1.Caption="Document "+(ctr++).ToString();

In the example, the XAML file defines a UserControl object. The loaded UserControl is accessed via the DocumentPanel's Control property and then a method on the UserControl is invoked.

[C#]
//...(panel1.ControlasUserControl1).SetDataContext(imageInfo);

You can see this in action by clicking the "Set DataContext for UserControl" button in the example.

Question Comments

Added By: Sudha Raman at: 10/22/2013 9:21:47 AM    

Hi,

 I am following the same approach in my project. My question is how to close the Usercontrol from Button click event of it.(not using the 'X' on right corner- usercontrol unloaded event).

Thanks
Sudha.

Added By: Alex Zeller (DevExpress) at: 10/23/2013 1:00:47 AM    

Hi,
If you have a button within a UserControl displayed within a DocumentPanel, you can use the Button.Click event to close the current DocumentPanel:
private void button1_Click(object sender, RoutedEventArgs e) {
    DockLayoutManager dm = DockLayoutManager.GetDockLayoutManager(this);
    dm.DockController.Close(dm.ActiveDockItem);
}
Thanks, Alex.

Added By: Cotza Andrea at: 11/20/2013 1:56:14 AM    

Hi,

 I've a windows (MDI) with buttons (save, new ecc.) and document panel with loaded windows at runtime. I need to send commands from child windows to MDI window (enable/disable buttons). How can I do?

Thanks, Andrea.

How to: Customize items in the Property Menu

How to serialize DockLayoutManager when TabbedDocumentUIService is used

$
0
0

Some of DockLayoutManager’s panel groups can contain documents that were created from ViewModel with IDocumentManagerService. To serialize and restore them correctly, it is necessary to perform these steps:

1. Create a style and set a name for DocumentPanel. To do this, bind DocumentPanel.BindableName to a unique property.

2. Apply this style to all documents that will be created from ViewModel.

3. Before serializing DockLayoutManager, serialize all documents created from ViewModel.

4. Before restoring DockLayoutManager, recreate all documents created from ViewModel.

SpellChecker - Customizing built-in dialogs

$
0
0
In this example you can learn how to customize spell checking dialogs of ASP.NET  MVC Spell Checker.
ASP.NET  MVC Spell Checker provides two built-in forms - one form allows the end-user to accept or reject spelling suggestion and update a custom dictionary with a new word (SpellCheckForm), the other enables changing spell checking options (SpellCheckOptionsForm). 

To render a custom SpellCheckForm,  use the SpellCheckerSettings.SettingsForms.SpellCheckFormAction property to specify a custom controller action CustomSpellCheckFormPartial. The action CustomSpellCheckFormPartial renders a partial view which contains a custom dialog. In this example the custom dialog is the same as the default built-in dialog, to illustrate the method.  Subsequently you can modify it as your needs dictate.

When modifying the CustomSpellCheckFormPartial view, you should follow the guidelines below.
1. Use the private client-side Javascript event handlers to interact with the SpellChecker object. Their names are shown in the following picture.


2. Do not change ID of any element on the form (editors, buttons, the <div> element). They should be the same as the names in this example.
3. The <div> element in the dialog (the element that displays the original text with misspelled words underlined) should have the ID conforming to the pattern <SpellCheckerExtensionName>_SpellCheckForm_SCCheckedDiv
4. Themed <div> element is of the dxwscCheckedTextContainer class to use the Default theme. The dxwscCheckedTextContainer_<themename> class specifies the theme themename.

To render a custom SpellCheckOptionsForm,  use the SpellCheckerSettings.SettingsForms.SpellCheckOptionsFormAction property to specify a custom controller action CustomSpellCheckOptionsFormPartial. The action CustomSpellCheckOptionsFormPartial renders a partial view which contains a custom dialog. In this example the custom dialog is the same as the default built-in dialog.  Subsequently you can modify it as your needs dictate.
When modifying the CustomSpellCheckOptionsFormPartial view, use the private client-side Javascript event handlers as shown in the following picture.




OBSOLETE - How to allow Link/Unlink objects for a ManyToMany collection property when an end-user doesn't have permissions to modify the associated objects

$
0
0

==============================
This solution can be applied only to the old Security System.
Starting with v13.2, you can configure member permissions to grant access to the associated collections (see Security - Provide the capability to link/unlink objects in non-aggregated collections if they have the corresponding permissions while the master object is restricted ). You should not use this example in a new project.
==============================

Suppose, I have the Organization and Person classes. Each Person object can be associated with a number of Organization objects, and each Organization object can be associated with a number of Person objects (a many-to-many relationship, see the BusinessClasses.cs file):

[C#]
publicclassPerson:XPObject{publicPerson(Sessionsession):base(session){}publicstringName{get{returnGetPropertyValue<string>("Name");}set{SetPropertyValue<string>("Name",value);}}[Association("Organizations-Persons2")]publicXPCollection<Organization>Organizations{get{returnGetCollection<Organization>("Organizations");}}}publicclassOrganization:XPObject{publicOrganization(Sessionsession):base(session){}publicstringFullName{get{returnGetPropertyValue<string>("FullName");}set{SetPropertyValue<string>("FullName",value);}}[Association("Organizations-Persons")]publicXPCollection<Person>Persons{get{returnGetCollection<Person>("Persons");}}}

And, an end-user needs to modify any Person object, including its "Organizations" collection ('Link' or 'Unlink' organization objects), but he or she should not modify any property of an Organization object.

To accomplish this, I grant all operations under the Person objects and grant only the Read operation over the Organization objects (see the Updater.cs file):

[C#]
userRole.AddPermission(newObjectAccessPermission(typeof(object),ObjectAccess.AllAccess,ObjectAccessModifier.Allow));userRole.AddPermission(newObjectAccessPermission(typeof(Person),ObjectAccess.AllAccess,ObjectAccessModifier.Allow));userRole.AddPermission(newObjectAccessPermission(typeof(Organization),ObjectAccess.ChangeAccess,ObjectAccessModifier.Deny));

With these permissions, I have achieved the necessary behavior, except for that an end-user cannot modify the Organizations collection property. This is a restriction of the current implementation of the XAF Security system.

To avoid it, I introduce a new class and manually allow modifying the "Organizations" property in the code (see the AllowManyToMany_ObjectAccessComparer.cs file):

[C#]
publicclassAllowManyToMany_ObjectAccessComparer:ObjectAccessComparer{publicoverrideboolIsSubsetOf(ObjectAccessPermissionsourcePermission,ObjectAccessPermissiontargetPermission){if(sourcePermission.AccessItemList.Count== 1){ParticularAccessItemsourceAccessItem=sourcePermission.AccessItemList[0];if(typeof(Organization).IsAssignableFrom(sourceAccessItem.ObjectType)&&sourceAccessItem.Access==ObjectAccess.Write&&sourceAccessItem.Modifier==ObjectAccessModifier.Allow){if(sourcePermission.Contexts!=null&&sourcePermission.Contexts.CollectionPropertyContext!=null&&sourcePermission.Contexts.CollectionPropertyContext.CollectionPropertyName=="Organizations"&&typeof(Person).IsAssignableFrom(sourcePermission.Contexts.CollectionPropertyContext.MasterObjectType)){returntrue;}}}returnbase.IsSubsetOf(sourcePermission,targetPermission);}}

and set this class as the current ObjectAccessComparer in the main.cs and global.aspx.cs files:

[C#]
ObjectAccessComparerBase.SetCurrentComparer(newAllowManyToMany_ObjectAccessComparer());

Thanks,
Dan


How to: Edit dynamic properties in the PropertyGridControl

$
0
0
The PropertyGridControl supports the standard ICustomTypeDescriptor interface. To be able to display dynamic properties, you can implement this interface in the data source class and pass the instance of this class to PropertyGridControl.SelectedObject.

In this example, this interface is implemented in the DictionaryWrapper<T> class. In the GetProperties methods, it returns a collection of custom PropertyDescriptor descendants.

RibbonControl - How to show a hint on hovering the mouse over the BarItem's glyph and execute a certain action when the glyph is clicked

How to: Validate data in PropertyGridControl

$
0
0

The DXPropertyGrid supports several ways to check if the value entered by a user is correct.

First, this functionality can be implemented at the View level by handling the ValidateCell event. This event is raised when a user has modified a cell value and is trying to save changes (either by pressing the Enter key or switching to another property grid cell).
Here is a code snippet demonstrating how to handle this event.


[C#]
voidOnPropertyGridControlValidateCell(objectsender,DevExpress.Xpf.PropertyGrid.ValidateCellEventArgse){if(e.NewValue==null||string.IsNullOrEmpty(e.NewValue.ToString()))e.ValidationException=newSystem.Exception("A cell cannot be empty");}

 

Another way is to implement validation at the data source level using Data Annotation Attributes (assigning attributes using the DevExpress FluentAPI is also supported) or by implementing the IDataErrorInfo interface.

How to create custom shapes with custom connection points for DiagramDesignerControl

$
0
0

The Diagram control supports a special language for defining shapes. The main element that contains shape description is ShapeTemplate. This element describes a shape contour and may contain several segments:
- Start. Specifies the start point
- Line. Defines a line with start and end points
- Arc. Defines an arc with start and end points

To specify connection points, use the ShapeTemplate.ConnectionPoints property.
Shapes may contain parameters. Parameters may be used to dynamically calculate an end point, row height and other properties. To specify parameters, use the ShapeTemplate.Parameters property.
To register custom shapes, use the DiagramToolboxRegistrator.RegisterShapes method.

How to: Specify editors for displayed properties

$
0
0

Cell editors can be specified at the PropertyGridControl level as well as in a ViewModel/Model.

In the first case, we will need to create PropertyDefinition objects for required properties. There are several ways to map definitions to properties, please refer to Property Definitions for detailed information.
To assign an editor, you can use either of the following properties:
- EditSettings;
- CellTemplate. Pay special attention that CellTemplate should be defined in a specific manner in order not to break navigation, validation, and synchronizing values. These requirements are listed described at PropertyDefinition.CellTemplateProperty.

On the ViewModel/Model level, use the DefaultEditorAttribute (it is used by GridControl, PropertyGridControl, and DataLayoutControl) and PropertyGridEditorAttribute.

Custom XtraTabbedMdiManager - How to add a button showing MDI child windows list to the XtraTabbedMdiManager's header

$
0
0

This sample shows how to add a button showing MDI child windows list to the XtraTabbedMdiManager's header. A button like "Active Files" in Visual Studio. To accomplish this, we've created an XtraTabbedMdiManager descendant along with descendants of other classes like the TabHeaderViewInfo and TabButtonsPanel. Also, since we cannot make changes to the Enums, we cannot extend the buttons set available in the HeaderButtons property. So, a separate property controlling this button's visibility has been added - HeaderShowActiveFilesButton. It has the bool type and by default is set to false.

Question Comments

Added By: Mike Liu at: 11/1/2013 11:35:55 AM    

Hi I downloaded this example, and ran it, but I didn't see the button on the tab manager header. Where is the button?

Added By: JJDX at: 9/21/2014 11:12:23 AM    

Same here, dl, run but no buttons, i search for HeaderShowActiveFilesButton , change it to true but there is no button still.

Added By: Yaroslav (DevExpress Support) at: 9/22/2014 6:24:58 AM    

Hi Roman,
This example was created long time ago, so some internal methods have been changed since that time. I slightly updated the target project (both C# and VB.NET versions) in order to fix the aforementioned issue. Now an additional button is displayed as expected under the latest 14.1 version.
Don't hesitate to contact us in case of any difficulty. 

Added By: Christian Tüber at: 12/7/2015 11:50:34 PM    

I modified the example to have a feature toggle button. I set a super tool tip for the EditorButton but it is not shown.
Do i have to assign it to the RibbonControl on the XtraForm to get it running?

Here my code example:
     protected override TabButtonInfo CreateButton(TabButtonType button)
     {
        if ( button == TabButtonType.User )
        {
            ButtonPredefines predefine = ButtonPredefines.Glyph;
               Boolean selectedPageIsAFavorite = false;
               if (this.TabViewInfo.SelectedTabPage != null && this.TabViewInfo.SelectedTabPage is XtraMdiTabPage)
               {
                   XtraMdiTabPage mdiTabPage = (XtraMdiTabPage)this.TabViewInfo.SelectedTabPage;
                   if (    mdiTabPage.MdiChild != null &&
                           mdiTabPage.MdiChild.ParentForm != null &&
                           mdiTabPage.MdiChild.ParentForm is MainForm)
                   selectedPageIsAFavorite = ((MainForm)mdiTabPage.MdiChild.ParentForm).IsSelectedPageAFavorite((Form)mdiTabPage.MdiChild);
               }
               SuperToolTip superToolTipForFavoriteToggleButton = new SuperToolTip();
               SuperToolTipSetupArgs args = new SuperToolTipSetupArgs();
               args.Title.Text = "Favorit setzen/löschen";
               Image favoriteGlyph = null;

               if (selectedPageIsAFavorite)
               {
                   // page is a favorite
                   args.Contents.Text = "Anklicken zum Löschen des Favoritenstatus";
                   favoriteGlyph = Properties.Resources.ov_favorite_active;
               }
               else
               {
                   // page is NOT a favorite
                   args.Contents.Text = "Anklicken zum Setzen des Favoritenstatus";
                   favoriteGlyph = Properties.Resources.ov_favorite_non_active;
               }

               superToolTipForFavoriteToggleButton.Setup(args);
               EditorButton favoriteButton = new EditorButton(predefine, favoriteGlyph, superToolTipForFavoriteToggleButton);
               TabButtonInfo tabBtn = new TabButtonInfo(favoriteButton, button);
           return tabBtn;
        }

        return base.CreateButton(button);
     }

Added By: Dimitros (DevExpress Support) at: 12/9/2015 3:00:02 AM    

Hello Christian,

Currently, our XtraTabbedMdiManager can show tooltips only for tab pages. As a possible solution, you can handle the ToolTipController.Default.GetActiveObjectInfo event and manually show a tooltip. For example:

[C#]
publicMyTabbedMdiManager(IContainercontainer):base(container){ToolTipController.DefaultController.GetActiveObjectInfo+=DefaultController_GetActiveObjectInfo;}



[C#]
privatevoidDefaultController_GetActiveObjectInfo(objectsender,ToolTipControllerGetActiveObjectInfoEventArgse){if(e.SelectedControlisMdiClient){varargs=CreateDXMouseEventArgs(newMouseEventArgs(MouseButtons.None, 0,e.ControlMousePosition.X,e.ControlMousePosition.Y, 0));DevExpress.XtraTab.Buttons.TabButtonInfomyButton=((MyTabButtonsPanel)ViewInfo.HeaderInfo.Buttons).MyButton;//expose your button info to access it from MyTabbedMdiManagerif(myButton.Bounds.Contains(args.Location)){//show your SuperTip here...}}}




Let me know if you have additional questions.



Added By: Christian Tüber at: 12/14/2015 11:21:29 PM    

Hello Dimitros,

many thanks for your code parts. I got it running with following additions :-)
       private void DefaultController_GetActiveObjectInfo(object sender, ToolTipControllerGetActiveObjectInfoEventArgs e)
       {
           if (e.SelectedControl is MdiClient)
           {
               var args = CreateDXMouseEventArgs(new MouseEventArgs(MouseButtons.None, 0, e.ControlMousePosition.X, e.ControlMousePosition.Y, 0));
               DevExpress.XtraTab.Buttons.TabButtonInfo favoriteToggleTabBtnInfo = ((MyTabButtonsPanel)ViewInfo.HeaderInfo.Buttons).FavoriteToggleTabBtnInfo;
               if (favoriteToggleTabBtnInfo.Bounds.Contains(args.Location))
               {
                   ToolTipController.DefaultController.ShowHint(favoriteToggleTabBtnInfo.Button.ToolTip);
               }
           }

       }

Added By: Dimitros (DevExpress Support) at: 12/15/2015 1:29:07 AM    

Hello Christian,

I am happy to hear that you have successfully implemented tooltips for your custom buttons.

Thank you for sharing your code with us! It may be helpful to other users who need this functionality.

How to: Show object properties

$
0
0

The PropertyGridControl is the control designed to edit object properties. It can be bound to a specific object as well as a collection of objects.


To browse and manage properties of a specific object, set the  PropertyGridControl.SelectedObject property to this object.

[C#]
publicpartialclassMainWindow{publicMainWindow(){DataContext=newContact("Carolyn","Baker");InitializeComponent();}}publicclassContact{publicstringFirstName{get;set;}publicstringLastName{get;set;}publicContact(stringfirstName,stringlastName){FirstName=firstName;LastName=lastName;}}
[XAML]
<dxprg:PropertyGridControlSelectedObject="{Binding Path=.}"/>

To edit properties of multiple objects simultaneously, use PropertyGridControl.SelectedObjects.

[C#]
publicpartialclassMainWindow{publicMainWindow(){DataContext=newList<Contact>{newContact("Carolyn","Baker"),newContact("Amber","Seaman")};InitializeComponent();}}
[XAML]
<dxprg:PropertyGridControlSelectedObjects="{Binding Path=.}"ExpandCategoriesWhenSelectedObjectChanged="True"/>


DiagramControl - How to create a custom shape

$
0
0
This example illustrates how to create custom shapes.

How to create a custom theme for shapes in DiagramDesignerControl

$
0
0

Shapes in the Diagram control are colored according to an applied theme. To create a custom theme, add a resource dictionary into your application and add the Theme element into it. 
Each theme should contain a color palette which defines main colors used in a theme. To specify a color palette, add the ColorPalette element into Theme. 

To specify how colors are used in a theme, set the Theme.Effects property. This property accepts the EffectCollection object. EffectCollection defines colors shown in the following gallery:


EffectCollection has the following properties:
-ThemeEffects. Influences colors in the "Theme Styles" group.
-VariantEffects. Influences colors in the "Variant Styles" group. When a shape is created its default color scheme is taken from this group.
-ConnectorEffects. Influences connector colors.
 
To register a custom theme, use the ThemeRegistrator.RegisterThemes method. 

How to create a ToolbarListItem

$
0
0

This example shows how to create a ToolbarListItem, used to provide access to available toolbars. The ToolbarListItem object is added to the sub-menu displayed within the main menu.

Editing an in-memory dataset

$
0
0

This example is an illustration of the KA18686: ASPxGridView - How to implement CRUD operations with a custom data source KB Article. Refer to the Article for an explanation.

See Also:
How to insert, edit and delete data in a data table by ASPxGridView at runtime

Question Comments

Added By: Wayne Stoner at: 12/15/2015 7:59:20 AM    

This example isn't showing any of the code-behind.

Added By: Helen (DevExpress Support) at: 12/15/2015 9:53:42 AM    

Hello,

I tried to open the example on my side and it displays the code behind for all versions, both VB.NET and C#. See the video. Try to reload the page by pressing Ctrl+F5 and check the example again. If the problem persists, specify your browser family and version. 

How to merge MainMenuControls

$
0
0
This example demonstrates the merging behavior of MainMenuControls.

The example creates a TabControl in which a Tab contains three MainMenuControls: 1) an empty menu called 'elementHost', 2) a menu with 'Cut', 'Copy' and 'Paste' commands, 3)a menu with 'Left', 'Center' and 'Right' commands.
The second and third MainMenuControls will be merged to the first MainMenuControl.

The merging feature is enabled with the ElementMergingBehavior property attached to the Tab. This property is set to 'InternalWithInternal', which means that the Tab's internal elements are merged with other internal elements that are defined in parent name scopes. 
The 'elementHost' MainMenuControl belongs to the name scope inherited from the Window object (a name scope is implicitly created for each Window object). The IsScopeOwner properties set for the second and third MainMenuControls define child name scopes. Thus, these MainMenuControls will be merged to the 'elementHost' MainMenuControl (defined in the parent name scope).

Note:
If you want to merge the Tab's second and third MainMenuControls to the Window's topmost MainMenuControl (the one that contains 'File', 'Settings' and 'Exit' commands), replace the Tab's property setting:
dxb:MergingProperties.ElementMergingBehavior="InternalWithInternal"
with:
dxb:MergingProperties.ElementMergingBehavior="InternalWithExternal"

Viewing all 7205 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>