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

How to implement cascading ASPxComboBoxes for editing custom fields in a custom Appointment Edit form

$
0
0

This example illustrates a server-side technique of editing hierarchical custom appointment fields using cascading ASPxComboBoxes.
The main idea of implementing cascading ASPxComboBoxes was demonstrated in the following example:
A general technique of using cascading ASPxComboBoxes
In this example, we added two custom fields for appointments (CompanyID and ContactID) and two corresponding ASPxComboBoxes onto a custom Appointment Edit form. 
An approach for customizing the Appointment Edit Form for working with custom fields was described here:
How to: Modify the Appointment Editing Form for Working with Custom Fields
Changing a value of the "CompanyID" combobox results in filtering data in the "ContactID" combobox.


How to show filter dialog before showing ListView

$
0
0

Scenario:

When a user executes a navigation item that displays a large ListView, the application should display a popup window that allows you to define a filter for this ListView before loading records in it. This filter dialog should remember the user's choice and provide the capability to select one of the stored filters.

Steps to implement:

1. Create a ListView model extender - IModelListViewExt - that adds the AdditionalCriteria property to the ListView model to store the filter selected by the user.

2. Implement the ViewFilterContainer class whose DetailView is used as a filter dialog.

3. Implement the ViewFilterObject class which is used to store filters.

4. Implement the ShowFilterDialogController which shows the filter dialog instead of displaying the ListView, and then shows the filtered ListView. To do this, subscribe to the ShowNavigationItemController.ShowNavigationItemAction.Execute event and replace the ListView from the e.ShowViewParameters.CreatedView property with the ViewFilterContainer DetailView. Then show the filtered ListView via the XafApplication.MainWindow.SetView method.

5. Implement the NewViewFilterObjectController which sets the ObjectType property of the ViewFilterObject object created by the ViewFilterContainer.Filter lookup's New action.

See Also:
How to: Use Criteria Property Editors
How to: Extend the Application Model and Schema
ShowNavigationItemController Class
Dialog Controller

Question Comments

Added By: Pablo Mazaeda 1 at: 11/13/2012 6:21:47 AM    

how do I do this for ASP.NET?

Added By: Mandeep Singh 10 at: 2/16/2014 6:57:38 AM    

Tried to download this Example. Returns the following error

Server Error in '/Support/Center' Application.

Added By: Anatol (DevExpress Support) at: 2/16/2014 11:49:17 PM    

This was likely a temporary issue. Please try to download the example once again.

Added By: Wieland Voß at: 3/4/2014 1:16:39 AM    

Hi Anatol,

how do we implement this solution for the asp.net environment? Simply importing DevExpress.ExpressApp.Web in ViewFilterContainerDetailViewController doesn't seem to meet our needs, since LookupPropertyEditor and LookupEdit are unknown.

Thank you
Wieland

Added By: Anatol (DevExpress Support) at: 3/4/2014 7:57:15 AM    

I have updated the example. Now its code is platform-independent and will work correctly in the ASP.NET project.

Added By: Wieland Voß at: 3/5/2014 7:32:50 AM    

Thank you for your quick answer!

The implementation works fine, but ,unfortunately, is way too slow in web-modus :(
It seems, that the generation of large lookup-lists (millions) during filter-creation takes a lot of time. Do you have any hint, how to prevent this behaviour?

Added By: Mauro Assis at: 9/18/2014 2:04:25 PM    

This is working great, but everytime I click a navigation item it creates a new "Default" filter. I'm using Web Application, would this matter?

Added By: Leandro Meneses 1 at: 9/21/2014 8:25:11 PM    

Hi i need filter only one listview, solutio apply for all views. thanks

Added By: Anatol (DevExpress Support) at: 9/24/2014 7:36:47 AM    Wieland, I have not reproduced any performance issue in ASP.NET applications. I have checked SQL queries sent by this example. When a navigation item is clicked, records from the ListView that is about to be displayed are not loaded until the filter dialog is closed. So, please provide a sample project reproducing the issue.

Mauro, the Default filter can be created several times in ASP.NET, because the AdditionalCriteria value stored in the View model is not stored between sessions. To solve this issue, either store the selected filter in the database rather than in the Application Model, or configure your application to store all model differences in the database, as shown in the following example: How to: Store Model Differences in Database.

Leandro, you can check the Id of the created view in the ShowNavigationItemAction_Execute event handler and show the filter dialog only for the required ListView.Added By: Mauro Assis at: 10/22/2014 6:54:34 AM    

I've got irt working now. I changed 1st line of GetFilterObject method in ShowFilterDialogController to:

CriteriaOperator criteria = CriteriaOperator.Parse("ObjectType = ?", objectType);

Because ASP.NET won't store last criteria used. But I have another request though. Now I want a Delete button to appear (like this <https://drive.google.com/file/d/0B1OV0NgtiOaXMTFkS19YaDdjRm8/view?usp=sharing&gt;) in the dialog, allowing to delete a filter. Currently it shows only "New" and "Clear".

Added By: Anatol (DevExpress Support) at: 10/23/2014 3:07:37 AM    

To process your recent post more efficiently, I created a separate ticket on your behalf: T164618: How to add a Delete button to the ASP.NET lookup editor. I will post my answer there soon.

Added By: Martin Brekhof at: 10/23/2014 3:09:05 AM    

I must be missing something: it will not load in vs2012 with 13.2.9 (something about DXCore not loading) and the unpacked example could be platform independent but I only see a winforms implementatation. Any ideas?

Added By: Anatol (DevExpress Support) at: 10/23/2014 3:29:10 AM    

This example only has the WinForms version. In theory, since the code is platform-independent, it should work fine in ASP.NET after turning on the database model difference storage. However, we have not performed thorough testing of this scenario.
Please create a separate ticket regarding the issue with the Example Runner and describe your symptoms in greater detail. In addition, check whether or not this issue occurs when downloading other examples.

Added By: Gilson Appel at: 5/25/2015 10:17:38 AM    

Hello Anatol,

This approach isn't functional in TabbedMDI Mode for WinApplications. How can I create a new tab in my MainWindow?

--
Gilson

How to create simple bars from code

$
0
0
This example shows how to create two bars from code. The first bar represents the main menu toolbar, containing one menu item. The second bar represents the main menu toolbar containing two buttons.

To learn more on how to implement similar functionality in WPF, refer to the E3057 example.

How to create simple bars from code

$
0
0

This example shows how to create two bars from code. The first bar represents the main menu toolbar, containing one menu item. The second bar represents the main menu toolbar containing two buttons.

To learn more on how to implement similar functionality in Silverlight, refer to the T246513 example.

How to modify the context menu of grid columns

$
0
0

The following example demonstrates how to customize the grid's context menu at runtime. For instance this sample demonstrates how to remove the default 'Show Column Chooser' menu item from the Column Context Menu, and add a custom item instead.

Question Comments

Added By: Sævar Kristinsson at: 2/6/2013 6:42:06 AM    

Hi, I would want to modify the column header context menu in design time. The only example I have found that touches this topic is this example or similar to it i.e. modifying the context menu in runtime. Could you guys give an example on how to do this in design time?

Added By: Thomas R Melinsky at: 5/27/2014 6:18:22 AM    

Is there a new version of this example for WPF that isn't event driven?

Added By: Ilya (DevExpress Support) at: 5/27/2014 9:08:19 AM    

Hi Thomas,
Currently, the approach demonstrated in his example is the appropriate way to customize the grid popup menu at runtime. Would you please clarify why it is not an option for you?

Added By: Adithya Kumar 1 at: 5/25/2015 10:45:03 PM    

Hi, how to add this into styles? So that the functionality is avialable to all the grids in an application.

Create Header or Field Value Templates and replicate existing look-and-feel

$
0
0

This example demonstrates how to customize the Field Header and Field Value templates, and keep automatic appearance and functionality. It is not possible to simply replace the default Header or Value element with a custom label, because these elements have a really complex layout. Ordinarily, it consists of a table including a few cells with nested items, and attached styles and scripts. These elements are generated dynamically based on the current pivot grid layout. 
This example demonstrates how to customize the templates at runtime. Using this approach, it is possible to call the CreateFieldValue and CreateHeader methods to generate the default template content. Then it is possible to replace some of default items with custom ones to introduce a required functionality. 


See Also:
E3278: How to get an object ID corresponding to a specific Field Value within a custom FieldValueTemplate
E3279: How to get a list of higher level field values corresponding to the specific Field Value or Cell and use them in custom templates
E4669: How to replace the default Filter Popup with a custom one made with ASPxGridView control
S32439: Provide the capability to replicate the original look-and-feel and functionality when a header template is set

GridView - How to use a built-in Context Menu to display summaries in Custom Binding mode

$
0
0

Having researched this scenario, we found that it's impossible to support it out of the box, since it requires implementing a separate action for the ContextMenu features. This example illustrates how to implement this scenario using custom callbacks: 
1) Handle the ASPxGridView.ContextMenuItemClick event to intercept the default logic and send a custom callback using MVCxClientGridView.PerformCallback : 

[JScript]
function OnContextMenuItemClick(s, e){if(e.objectType == "footer"){ e.handled = true; gridView.PerformCallback({ fieldName: s.GetColumn(e.elementIndex).fieldName, customCommand: e.item.name });}}

 

2) Read callback parameters (see Passing Values to a Controller Action through Callbacks) and manually modify the summary collection at the GridViewModel level using the GridViewModel.TotalSummary property. 

3) Modify the GridViewCustomBindingGetSummaryValuesHandler method's implementation to support all summary types ("Min", "Max" and "Average") 

Note that this approach will work for versions 14.2.8 and later (see GridView - It's impossible to change the summary state on a custom callback in Custom Binding mode).

How to change BarItemLink's appearance via templates

$
0
0

This example demonstrates how to change a BarItemLink's appearance by customizing templates (available via the CustomResources property)

To learn more on how to implement similar functionality in Silverlight, refer to the T246660 example.


How to change BarItemLink's appearance via templates

$
0
0
This example demonstrates how to change a BarItemLink's appearance by customizing templates (available via the CustomResources property)

To learn more on how to implement similar functionality in WPF, refer to the E2701 example.

Simple MVVM application with DXBars - Tutorial

$
0
0

This tutorial demonstrates how to implement a simple and flexible data management system by using the MVVM pattern for WPF platform.

Task
Implement a flexible data management system by using the MVVM pattern for WPF platform.

Input Data
A list of Person objects providing custom information (first name, last name, photo and email).

Additional Requirements
The management system should provide an ability to modify information on persons and add/delete persons. The system should prevent accidental modification of persons' data via visual controls.

Step 1. Creating Data Model.
First, we create a simple data model:

1. The Person class with a set of relevant fields:

[C#]
publicclassPerson{publicstringFirstName=string.Empty;publicstringLastName=string.Empty;publicUriPhoto=null;publicstringEmail=string.Empty;}

2. The Persons entity that is a collection of Person objects:

[C#]
publicclassPersons:ObservableCollection<Person>{}

3. Utility classes that help creating Person objects:

[C#]
publicstaticclassPersonCreator{publicstaticreadonlyPerson[]Person;staticPersonCreator(){Person=newPerson[4];Person[0]=newPerson(){//... };//... }}publicstaticclassPersonsCreator{publicstaticreadonlyPersonsPersons;staticPersonsCreator(){Persons=newPersons();foreach(PersonpersoninPersonCreator.Person)Persons.Add(person);}}

Step 2. Creating Form for Person Entity.
In this step we create a view model for the Person entity by using the MVVM pattern - the PersonViewModel class. This class implements the interaction between the data model and UI.

1. Create a base view-model class implementing the INotifyPropertyChanged interface

[C#]
publicclassViewModelBase:INotifyPropertyChanged{publiceventPropertyChangedEventHandlerPropertyChanged;protectedvirtualvoidOnPropertyChanged(stringpropertyName){if(PropertyChanged!=null)PropertyChanged(this,newPropertyChangedEventArgs(propertyName));}}

2. Create the PersonViewModel class by inheriting from ViewModelBase. The class declares properties which are in-sync with Person object's properties.

[C#]
publicclassPersonViewModel:ViewModelBase{publicStringFirstName{get{returnPerson.FirstName;}set{if(Person.FirstName==value)return;Person.FirstName=value;OnPropertyChanged("FirstName");}}publicPersonPerson{get;privateset;}publicPersonViewModel(Personperson){Person=person;}//... }

The PersonViewModel class also contains a non-model related property (IsReadOnly). This property prevents objects from being modified by an end-user.

[C#]
publicclassPersonViewModel:ViewModelBase{//...publicboolIsReadOnly{get{returnisReadOnly;}set{if(isReadOnly==value)return;isReadOnly=value;OnPropertyChanged("IsReadOnly");}}boolisReadOnly=false;//...}

3. Create a view form containing controls used to display and edit data.

[XML]
<UserControl...><!--...--><Grid><Grid.RowDefinitions><RowDefinitionHeight="*"/><RowDefinitionHeight="Auto"/></Grid.RowDefinitions><dxe:ImageEditSource="{Binding Photo}"IsReadOnly="True"/><StackPanelGrid.Row="1"Orientation="Vertical"HorizontalAlignment="Center"><WrapPanelHorizontalAlignment="Center"Margin="3"><TextBlockText="Fisrt Name:"VerticalAlignment="Center"/><dxe:TextEditText="{Binding FirstName, UpdateSourceTrigger=PropertyChanged}"IsReadOnly="{Binding IsReadOnly}"Margin="5,0,0,0"/></WrapPanel><WrapPanelHorizontalAlignment="Center"Margin="3"><TextBlockText="Last Name:"VerticalAlignment="Center"/><dxe:TextEditText="{Binding LastName, UpdateSourceTrigger=PropertyChanged}"IsReadOnly="{Binding IsReadOnly}"Margin="5,0,0,0"/></WrapPanel><WrapPanelHorizontalAlignment="Center"Margin="3"><TextBlockText="Email:"VerticalAlignment="Center"/><dxe:TextEditText="{Binding Email, UpdateSourceTrigger=LostFocus}"IsReadOnly="{Binding IsReadOnly}"Margin="5,0,0,0"/></WrapPanel></StackPanel></Grid><!--...--></UserControl>

4. A helper PersonViewModelCreator class creates a PersonViewModel and populates it with data:

[C#]
publicstaticclassPersonViewModelCreator{publicstaticreadonlyPersonViewModel[]PersonViewModel;publicstaticPersonViewModelDesignPersonViewModel{get{returnPersonViewModel[0];}}staticPersonViewModelCreator(){intlength=PersonCreator.Person.Length;PersonViewModel=newPersonViewModel[length];for(inti= 0;i<length;i++)PersonViewModel[i]=newPersonViewModel(PersonCreator.Person[i]){IsReadOnly=true};}}

Initialize the UserControl.DataContext property with the view-model provided by PersonViewModelCreator :

[XML]
<UserControlx:Class="DXBarsAndMVVM.Views.PersonView"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:dx="http://schemas.devexpress.com/winfx/2008/xaml/core"xmlns:dDx="http://schemas.devexpress.com/winfx/2008/xaml/core"xmlns:dxe="http://schemas.devexpress.com/winfx/2008/xaml/editors"xmlns:dxb="http://schemas.devexpress.com/winfx/2008/xaml/bars"xmlns:hlp="clr-namespace:DXBarsAndMVVM.Helpers"xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"xmlns:d="http://schemas.microsoft.com/expression/blend/2008"mc:Ignorable="d dDx"dDx:ThemeManager.ThemeName="Office2007Silver"d:DesignHeight="300"d:DesignWidth="300"d:DataContext="{x:Static hlp:PersonViewModelCreator.DesignPersonViewModel}"><!--...--></UserControl>

5. Add an additional visual control element (BarCheckItem) to the view form that will be bound to the PersonViewModel.IsReadOnly property

[XML]
<UserControl...><dxb:BarManager><dxb:BarManager.Items><dxb:BarCheckItemName="cbIsReadOnly"Content="Locked"IsChecked="{Binding IsReadOnly}"/></dxb:BarManager.Items><dxb:BarManager.Bars><dxb:Bar><dxb:Bar.ItemLinks><dxb:BarCheckItemLinkBarItemName="cbIsReadOnly"/></dxb:Bar.ItemLinks></dxb:Bar></dxb:BarManager.Bars><Grid><!--editor controls--></Grid></dxb:BarManager></UserControl>

6. To test the project, add the following code to the main window

[XML]
<Windowx:Class="DXBarsAndMVVM.MainWindow"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:vw="clr-namespace:DXBarsAndMVVM.Views"xmlns:hlp="clr-namespace:DXBarsAndMVVM.Helpers"Title="MainWindow"Height="350"Width="525"DataContext="{x:Static hlp:PersonViewModelCreator.DesignPersonViewModel}"><Grid><vw:PersonView/></Grid></Window>

Step 3. Creating Form for Persons Entity.

1. Create a PersonsViewModel object that is a collection of PersonViewModel objects. The PersonsViewModel class is inherited from the LockableCollection<PersonViewMode> class defined in the DevExpress.Xpf.Core library. This class allows you to temporarily lock change notifications by using the BeginUpdate and EndUpdate methods. The BeginUpdate method suppresses the CollectionChanged event until the EndUpdate method is called. Once the EndUpdate method is called, the CollectionChanged event is raised.

[C#]
publicclassPersonsViewModel:LockableCollection<PersonViewModel>{publicPersonsPersons{get;privateset;}publicPersonsViewModel(Personspersons){Persons=persons;}}

2. When the Persons model collection is changed, it should be synchronized with the PersonsViewModel.

[C#]
publicclassPersonsViewModel:LockableCollection<PersonViewModel>{publicPersonsPersons{get;privateset;}publicPersonsViewModel(Personspersons){Persons=persons;Persons.CollectionChanged+=newNotifyCollectionChangedEventHandler(OnPersonsCollectionChanged);SyncCollection();}protectedvirtualvoidOnPersonsCollectionChanged(objectsender,NotifyCollectionChangedEventArgse){SyncCollection();}protectedvoidSyncCollection(){BeginUpdate();Clear();foreach(PersonpersoninPersons)Add(newPersonViewModel(person));EndUpdate();}}

3. To allow a user to select a model, new Selected and SelectedIndex properties are introduced. In addition, an indexer property is added that allows you to get PersonViewModel objects by Person objects.

[C#]
publicclassPersonsViewModel:LockableCollection<PersonViewModel>{//...publicPersonViewModelSelected{get{returnthis[SelectedIndex];}protectedset{SelectedIndex=IndexOf(value);}}publicintSelectedIndex{get{returnselectedIndex;}set{value=IsValidSelectedIndex(value)?value:-1;if(selectedIndex==value)return;selectedIndex=value;OnSelectedIndexChanged();}}publicPersonViewModelthis[Personperson]{get{if(person==null)returnnull;foreach(PersonViewModelviewModelinthis)if(viewModel.Person==person)returnviewModel;returnnull;}}protectedvirtualvoidOnSelectedIndexChanged(){OnPropertyChanged(newPropertyChangedEventArgs("Selected"));OnPropertyChanged(newPropertyChangedEventArgs("SelectedIndex"));}boolIsValidSelectedIndex(intselectedIndex){returnselectedIndex>= 0 &&selectedIndex<Count;}intselectedIndex=-1;//...}

4. Now we create a view containing a ListBox control.

[XML]
<ListBoxx:Name="list"ItemsSource="{Binding}"SelectedIndex="{Binding SelectedIndex}"><ListBox.ItemTemplate><DataTemplate><StackPanelOrientation="Horizontal"><TextBlockText="{Binding FirstName}"/><TextBlockText="{Binding LastName}"Margin="15,0,0,0"/></StackPanel></DataTemplate></ListBox.ItemTemplate></ListBox>

5. A helper PersonsViewModelCreator class creates a PersonsViewModel and populates it with data:

[C#]
publicclassPersonsViewModel:LockableCollection<PersonViewModel>{publicPersonsViewModel(Personpersons):this(persons,null){}internalPersonsViewModel(Personspersons,Func<Person,PersonViewModel>creatingMethod){NewPersonCommand=newPersonsCommand(OnNewPersonCommadExecute);DeletePersonCommand=newPersonsCommand(OnDeletePersonCommadExecute,OnDeletePersonCommadCanExecute);CreatingMethod=creatingMethod;Persons=persons;Persons.CollectionChanged+=newNotifyCollectionChangedEventHandler(OnPersonsCollectionChanged);SyncCollection();}protectedvoidSyncCollection(){BeginUpdate();Clear();foreach(PersonpersoninPersons){PersonViewModelpersonViewModel;if(CreatingMethod!=null)personViewModel=CreatingMethod(person);elsepersonViewModel=newPersonViewModel(person);Add(personViewModel);}EndUpdate();if(SelectedIndex==-1 &&Count> 0)SelectedIndex= 0;}Func<Person,PersonViewModel>CreatingMethod=null;}publicstaticclassPersonsViewModelCreator{publicstaticreadonlyPersonsViewModelPersonsViewModel;staticPersonsViewModelCreator(){PersonsViewModel=newPersonsViewModel(PersonsCreator.Persons,CreatingMethod);}staticPersonViewModelCreatingMethod(Personperson){foreach(PersonViewModelpersonViewModelinPersonViewModelCreator.PersonViewModel)if(personViewModel.Person==person)returnpersonViewModel;returnnewPersonViewModel(person);}}

The following code sets a DataContext for a view.

[XML]
<UserControlx:Class="DXBarsAndMVVM.Views.PersonsView"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:dx="http://schemas.devexpress.com/winfx/2008/xaml/core"xmlns:dDx="http://schemas.devexpress.com/winfx/2008/xaml/core"xmlns:dxb="http://schemas.devexpress.com/winfx/2008/xaml/bars"xmlns:hlp="clr-namespace:DXBarsAndMVVM.Helpers"xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"xmlns:d="http://schemas.microsoft.com/expression/blend/2008"mc:Ignorable="d dDx"dDx:ThemeManager.ThemeName="Office2007Silver"d:DesignHeight="200"d:DesignWidth="200"d:DataContext="{x:Static hlp:PersonsViewModelCreator.PersonsViewModel}"><!--...--></UserControl>

6. Create a command class that implements the ICommand interface

[C#]
publicclassPersonsCommand:ICommand{publiceventEventHandlerCanExecuteChanged{add{if(canExecute!=null)canExecuteChanged+=value;}remove{if(canExecute!=null)canExecuteChanged-=value;}}publicPersonsCommand(Action<object>execute):this(execute,null){}publicPersonsCommand(Action<object>execute,Func<object,bool>canExecute){if(execute==null)thrownewArgumentNullException("execute");this.execute=execute;this.canExecute=canExecute;}publicboolCanExecute(objectparameter){if(canExecute==null)returntrue;returncanExecute(parameter);}publicvoidExecute(objectparameter){execute(parameter);}publicvoidRaiseCanExecuteChanged(){if(canExecuteChanged!=null)canExecuteChanged(this,EventArgs.Empty);}Action<object>execute;Func<object,bool>canExecute;eventEventHandlercanExecuteChanged;}

Create commands that are used to work with the Person collection:

[C#]
publicclassPersonsViewModel:LockableCollection<PersonViewModel>{publicPersonsCommandNewPersonCommand{get;privateset;}publicPersonsCommandDeletePersonCommand{get;privateset;}//...publicPersonsViewModel(Personspersons):this(persons,null){}internalPersonsViewModel(Personspersons,Func<Person,PersonViewModel>creatingMethod){NewPersonCommand=newPersonsCommand(OnNewPersonCommadExecute);DeletePersonCommand=newPersonsCommand(OnDeletePersonCommadExecute,OnDeletePersonCommadCanExecute);//...}protectedvirtualvoidOnNewPersonCommadExecute(objectparemeter){Personperson=newPerson(){FirstName="First Name",LastName="Last Name",};Persons.Add(person);Selected=this[person];}protectedvirtualvoidOnDeletePersonCommadExecute(objectparemeter){intselectedIndex=SelectedIndex;Persons.Remove(Selected.Person);if(IsValidSelectedIndex(selectedIndex))SelectedIndex=selectedIndex;elseif(selectedIndex>=Count)SelectedIndex=Count- 1;elseif(selectedIndex< 0)selectedIndex= 0;}protectedvirtualboolOnDeletePersonCommadCanExecute(objectparemeter){returnIsValidSelectedIndex(SelectedIndex);}//...}

7. Add visual elements (BarButtonItems) to the form and bind them to corresponding commands.

[XML]
<dxb:BarManager><dxb:BarManager.Items><dxb:BarButtonItemName="btNew"Content="New"Glyph="/DXBarsAndMVVM;component/Images/Icons/new-16x16.png"Command="{Binding NewPersonCommand}"/><dxb:BarButtonItemName="btDelete"Content="Delete"Glyph="/DXBarsAndMVVM;component/Images/Icons/close-16x16.png"Command="{Binding DeletePersonCommand}"/></dxb:BarManager.Items><dxb:BarManager.Bars><dxb:Bar><dxb:Bar.ItemLinks><dxb:BarButtonItemLinkBarItemName="btNew"/><dxb:BarButtonItemLinkBarItemName="btDelete"/></dxb:Bar.ItemLinks></dxb:Bar></dxb:BarManager.Bars><!--...--></dxb:BarManager>

Step 4. Building GUI

1. Add DXTabControl with two tabs to the main window. The first tab will allow a end-user to select a record (a Person object) while the second tab will be used to edit selected record's properties:

[XML]
<Windowx:Class="DXBarsAndMVVM.MainWindow"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:dx="http://schemas.devexpress.com/winfx/2008/xaml/core"xmlns:dDx="http://schemas.devexpress.com/winfx/2008/xaml/core"xmlns:dxb="http://schemas.devexpress.com/winfx/2008/xaml/bars"xmlns:vw="clr-namespace:DXBarsAndMVVM.Views"xmlns:hlp="clr-namespace:DXBarsAndMVVM.Helpers"xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"mc:Ignorable="dDx"dDx:ThemeManager.ThemeName="Office2007Silver"Title="MainWindow"Height="350"Width="525"DataContext="{x:Static hlp:PersonsViewModelCreator.PersonsViewModel}"><dx:DXTabControlSelectedIndex="0"><dx:DXTabControl.View><dx:TabControlMultiLineViewHeaderLocation="Bottom"/></dx:DXTabControl.View><dx:DXTabItemContent="{Binding}"Header="Persons"><dx:DXTabItem.ContentTemplate><DataTemplate><vw:PersonsView/></DataTemplate></dx:DXTabItem.ContentTemplate></dx:DXTabItem><dx:DXTabItemContent="{Binding Selected}"Header="{Binding Selected}"><dx:DXTabItem.HeaderTemplate><DataTemplate><StackPanelOrientation="Horizontal"><TextBlockText="Details:"/><TextBlockText="{Binding FirstName}"Margin="5,0,0,0"/><TextBlockText="{Binding LastName}"Margin="5,0,0,0"/></StackPanel></DataTemplate></dx:DXTabItem.HeaderTemplate><dx:DXTabItem.ContentTemplate><DataTemplate><vw:PersonView/></DataTemplate></dx:DXTabItem.ContentTemplate></dx:DXTabItem></dx:DXTabControl></Window>

2. Tabs contain PersonsView and PersonView objects. Each view defines its own BarManager with a Bar. So, when switching between tabs, you will see a bar within a tab page. It is handy to have a single bar at the top of the main form instead. This can be implemented by using DXBars merging features.
To accomplish this, add BarManager with a bar at the top of the main window.

[XML]
<dxb:BarManager><dxb:BarManager.Bars><dxb:Barx:Name="MainBar"Caption="Bar"/></dxb:BarManager.Bars><!--...--></dxb:BarManager>

Here is the complete code of the main window:

[XML]
<Windowx:Class="DXBarsAndMVVM.MainWindow"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:dx="http://schemas.devexpress.com/winfx/2008/xaml/core"xmlns:dDx="http://schemas.devexpress.com/winfx/2008/xaml/core"xmlns:dxb="http://schemas.devexpress.com/winfx/2008/xaml/bars"xmlns:vw="clr-namespace:DXBarsAndMVVM.Views"xmlns:hlp="clr-namespace:DXBarsAndMVVM.Helpers"xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"mc:Ignorable="dDx"dDx:ThemeManager.ThemeName="Office2007Silver"Title="MainWindow"Height="350"Width="525"DataContext="{x:Static hlp:PersonsViewModelCreator.PersonsViewModel}"><dxb:BarManager><dxb:BarManager.Bars><dxb:Barx:Name="MainBar"Caption="Bar"/></dxb:BarManager.Bars><dx:DXTabControlSelectedIndex="0"><dx:DXTabControl.View><dx:TabControlMultiLineViewHeaderLocation="Bottom"/></dx:DXTabControl.View><dx:DXTabItemContent="{Binding}"Header="Persons"><dx:DXTabItem.ContentTemplate><DataTemplate><vw:PersonsViewLoaded="PersonsView_Loaded"/></DataTemplate></dx:DXTabItem.ContentTemplate></dx:DXTabItem><dx:DXTabItemContent="{Binding Selected}"Header="{Binding Selected}"><dx:DXTabItem.HeaderTemplate><DataTemplate><StackPanelOrientation="Horizontal"><TextBlockText="Details:"/><TextBlockText="{Binding FirstName}"Margin="5,0,0,0"/><TextBlockText="{Binding LastName}"Margin="5,0,0,0"/></StackPanel></DataTemplate></dx:DXTabItem.HeaderTemplate><dx:DXTabItem.ContentTemplate><DataTemplate><vw:PersonViewLoaded="PersonView_Loaded"/></DataTemplate></dx:DXTabItem.ContentTemplate></dx:DXTabItem></dx:DXTabControl></dxb:BarManager></Window>

The code-behind class:

[C#]
publicpartialclassMainWindow:Window{publicMainWindow(){InitializeComponent();}voidPersonsView_Loaded(objectsender,RoutedEventArgse){PersonsViewpersonsView=(PersonsView)sender;MainBar.UnMerge();MainBar.Merge(personsView.ChildBar);}voidPersonView_Loaded(objectsender,RoutedEventArgse){PersonViewpersonView=(PersonView)sender;MainBar.UnMerge();MainBar.Merge(personView.ChildBar);}}

Conclusion
MVVM provides a flexible way to write complex GUI systems. This tutorial helps you understand the basic principles of writing applications by using the MVVM pattern. The use of the DXBars component will help you add an efficient navigation UI to your applications.


To learn more on how to implement similar functionality in Silverlight, refer to the T246650 example.

How to synchronize the NavBar Navigation Pane expanded width with its popup width

$
0
0

By default, Microsoft Outlook allows you to synchronize the Navigation Pane width in expanded mode with its Popup Window width.

This example illustrates how to add similar behavior to the NavBar.

To add this functionality, it is necessary to add event handlers for NavPaneExpandedChanged and NavPaneExpandedChanging events, which will keep the NavBar and Popup actual widths synchronized when they are changed.

Then it is necessary to create a NavigationPaneView descendant and override the UpdatePresenterTemplateByEnabledState method, which should set your stored width for NavBar before the latter changes its visual state.

To learn more on how to implement similar functionality in Silverlight, refer to the T246669 example.

OBSOLETE: Disable cell text wrapping during column resizing operations

$
0
0

When end-users resize columns, cell text can become word-wrapped if a column becomes too narrow to fit cell values. You can avoid this by placing cell text into the <div> tag and disable this tag's word-wrapping. You can easily implement this using the DataItem template.

This example is obsolete.
For now, set the GridViewColumn.CellStyle.Wrap property to "DefaultBoolean.False" to disable the cell wrapping. 

How to add custom Field Values (Rows/Columns) that are not present in a DataSource

$
0
0

As described in the Custom column/row values ( Show Field Values that are not present in the original data source ) ticket, PivotGridControl cannot display field values in row and column areas if these values are not represented in the underlying datasource. As a workaround you can add all required values to the original datosource or create a datasource wrapper that contains all required values on its level, and there is no need to modify original datasource.
This example illustrates how to create such a datasource wrapper. It is based on the How to create a data source wrapper that adds an empty item to the lookup list example.
To hide rows and columns with null field values, handle the CustomFieldValueCells event.

Question Comments

Added By: Pinaki Sen at: 5/26/2015 3:42:29 AM    

How should we do it for a scenario wherein we need to pass on values for multiple fields?

How to automatically generate columns with predefined settings (MVVM)

$
0
0

Update:
In version 13.2, we significantly improved Data Annotation attribute support for our controls. You can use standard Data Annotation attributes as well as custom ones provided with our MVVM Framework to specify editors and other settings for grid columns. Take a look at  the Data Annotation Attributes and Applying Data Annotations articles to learn more.


If the grid's AutoPopulateColumns option is turned on, the grid automatically generates columns for all fields in a data source. In this instance, cell editors are automatically created based on the type of column values. For instance, if a column is bound to a field that contains DateTime values, the grid creates a date editor for it. If a column is bound to a field that contains numeric data, the numeric editor is used. Otherwise, the text editor is used. Default editors are created dynamically when requested and always have the default behavior.


This example shows how to automatically generate columns with predefined settings.
Column settings are specified via templates defined within Grid Control's resources:

[XML]
<UserControl.Resources><dxg:ColumnTemplateSelectorx:Key="TemplateSelector"/><Stylex:Key="ColumnStyle"TargetType="dxg:GridColumn"><SetterProperty="MinWidth"Value="100"/></Style></UserControl.Resources><dxg:GridControlx:Name="grid"AutoPopulateColumns="True"ColumnGeneratorStyle="{StaticResource ColumnStyle}"ColumnGeneratorTemplateSelector="{StaticResource ResourceKey=TemplateSelector}"ItemsSource="{Binding Source}"><dxg:GridControl.Resources><DataTemplatex:Key="CityTemplate"><ContentControl><dxg:GridColumnx:Name="c1"Visible="True"><dxg:GridColumn.EditSettings><dxe:ComboBoxEditSettingsItemsSource="{Binding Control.DataContext.Cities}"/></dxg:GridColumn.EditSettings></dxg:GridColumn></ContentControl></DataTemplate> ...

In a model that describes a data item, use ColumnGeneratorTemplateNameAttribute to specify which column template is used to present the corresponding data field:

[C#]
[ColumnGeneratorTemplateNameAttribute("CityTemplate")]publicstringCity{get;set;}

As a result, when the Grid Control creates a column, the ColumnTemplateSelector object specified via the grid's ColumnGeneratorTemplateSelector property returns the predefined column template based on ColumnGeneratorTemplateNameAttribute applied to the data field. If this attribute is not applied, the grid creates a column with default settings.

Starting with version 2013 vol 1 the GridControl.AutoPopulateColumns property is marked as obsolete. The GridControl.AutoGenerateColumns property should be used instead.

To learn more on how to implement similar functionality in Silverlight, refer to the T246737 example.

How to automatically generate columns with predefined settings (MVVM)

$
0
0

Update:
In version 13.2, we significantly improved Data Annotation attribute support for our controls. You can use standard Data Annotation attributes as well as custom ones provided with our MVVM Framework to specify editors and other settings for grid columns. Take a look at  the Data Annotation Attributes and Applying Data Annotations articles to learn more.


If the grid's AutoPopulateColumns option is turned on, the grid automatically generates columns for all fields in a data source. In this instance, cell editors are automatically created based on the type of column values. For instance, if a column is bound to a field that contains DateTime values, the grid creates a date editor for it. If a column is bound to a field that contains numeric data, the numeric editor is used. Otherwise, the text editor is used. Default editors are created dynamically when requested and always have the default behavior.


This example shows how to automatically generate columns with predefined settings.
Column settings are specified via templates defined within Grid Control's resources:

[XML]
<UserControl.Resources><dxg:ColumnTemplateSelectorx:Key="TemplateSelector"/><Stylex:Key="ColumnStyle"TargetType="dxg:GridColumn"><SetterProperty="MinWidth"Value="100"/></Style></UserControl.Resources><dxg:GridControlx:Name="grid"AutoPopulateColumns="True"ColumnGeneratorStyle="{StaticResource ColumnStyle}"ColumnGeneratorTemplateSelector="{StaticResource ResourceKey=TemplateSelector}"ItemsSource="{Binding Source}"><dxg:GridControl.Resources><DataTemplatex:Key="CityTemplate"><ContentControl><dxg:GridColumnx:Name="c1"Visible="True"><dxg:GridColumn.EditSettings><dxe:ComboBoxEditSettingsItemsSource="{Binding Control.DataContext.Cities}"/></dxg:GridColumn.EditSettings></dxg:GridColumn></ContentControl></DataTemplate> ...

In a model that describes a data item, use ColumnGeneratorTemplateNameAttribute to specify which column template is used to present the corresponding data field:

[C#]
[ColumnGeneratorTemplateNameAttribute("CityTemplate")]publicstringCity{get;set;}

As a result, when the Grid Control creates a column, the ColumnTemplateSelector object specified via the grid's ColumnGeneratorTemplateSelector property returns the predefined column template based on ColumnGeneratorTemplateNameAttribute applied to the data field. If this attribute is not applied, the grid creates a column with default settings.

Starting with version 2013 vol 1 the GridControl.AutoPopulateColumns property is marked as obsolete. The GridControl.AutoGenerateColumns property should be used instead.

To learn more on how to implement similar functionality in WPF, refer to the E3330 example.


How to use the DXDocking and DXBars components with Prism

$
0
0

This sample demonstrates how to use the DXDocking and DXBars components with Prism.


The solution contains projects for the Silverlight platform:

1.The Infrastructure module contains common resources and the base IDocumentManager interface;

2. The Shell module - the main application module that contains the main form and module registration logic;

3. Four sub-modules - These will be injected into the main form via Prism.


The Shell module contains the basic control layout for the application:

1. The BarManger component contains a main menu with application actions;

2. DockLayoutManager contains regions for sub-modules.

The Shell module implements the IDocumentManager interface and exports this interface via the Prism Export Attribute. This interface provides basic interaction functionality between the main module and sub-modules.


Each sub-module implements a specific part of GUI (such as Grid, Text Editor, etc.) and contains a number of relative commands for this sub-module. The modules interact with the Shell module via the IDocumentManager interface, which is imported via the Prism Import attribute.


Sub-modules can be separately customized in the Visual Studio designer.


Note that when working with Prism, the bars merging feature is automatically supported: an MDI child and main menus are automatically merged when an MDI child form is activated or maximized. The DockLayoutManager.Merge event allows you to implement additional bars merging logic.

To learn more on how to implement similar functionality in WPF, refer to the E3340 example.

How to use the DXDocking and DXBars components with Prism

$
0
0

This sample demonstrates how to use the DXDocking and DXBars components with Prism.


The solution contains projects for the WPF platform with shared code:

1.The Infrastructure module contains common resources and the base IDocumentManager interface;

2. The Shell module - the main application module that contains the main form and module registration logic;

3. Four sub-modules - These will be injected into the main form via Prism.


The Shell module contains the basic control layout for the application:

1. The BarManger component contains a main menu with application actions;

2. DockLayoutManager contains regions for sub-modules.

The Shell module implements the IDocumentManager interface and exports this interface via the Prism Export Attribute. This interface provides basic interaction functionality between the main module and sub-modules.


Each sub-module implements a specific part of GUI (such as Grid, Text Editor, etc.) and contains a number of relative commands for this sub-module. The modules interact with the Shell module via the IDocumentManager interface, which is imported via the Prism Import attribute.


Sub-modules can be separately customized in the Visual Studio designer.


Note that when working with Prism, the bars merging feature is automatically supported: an MDI child and main menus are automatically merged when an MDI child form is activated or maximized. The DockLayoutManager.Merge event allows you to implement additional bars merging logic.

To learn more on how to implement similar functionality in Silverlight, refer to the T246698 example.

How to add a menu item that allows hiding all tab items

$
0
0

Handle the TabShown event. In this event handler, call the DXTabControl.HideTabItem method, and call the internal PopupClose method via reflection.

MVVM - How to bind GridColumn properties to properties in a ViewModel

$
0
0
This example shows how to bind column properties and properties of column's EditSettings to properties in the ViewModel in a MVMM-based application. Additionally, the sample demonstrates how to manipulate these properties in XAML using binding by element name.

To learn more on how to implement a similar functionality in WPF, refer to the E3166 example.

How to hide a BarEditItem's caption

$
0
0
This example shows how to hide a BarEditItem's caption even if the control is not empty.

To learn more on how to implement a similar functionality in WPF, refer to the E3774 example.

Viewing all 7205 articles
Browse latest View live


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