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

DevExpress Blazor Components - A way to set predefined settings for the specific component

$
0
0

In the case of a large Web application, it's often necessary to use controls with the same settings on numerous pages. It's quite annoying to specify the same settings many times.
In this example, we show how to specify some default settings for all DevExpress Blazor components in your application.

Inherit from our Blazor component and override the SetParametersAsync method. In this method, set the necessary default values for the public properties before calling the base method. Since the base method is called after your custom settings, you can initialize properties with custom default values in markup.

In this example, the MyDataGrid component contains an inherited DxDataGrid component whose PageSize, ShowFilterRow, and ShowGroupPanel properties contain new default values. Compare these components with the default DxDataGrid component on the Index page: they should have the same settings in markup.

This approach has the following limitation: it's not possible to use it with the DxChartXXXSeries components and specify the ValueField, ArgumentField, NameField, and PaneField properties.

Note: We don't recommend you override any other members of our components and change values of any protected properties.


Grid Control - How to implement the pagination functionality using SQL queries

$
0
0

.NET, WinForms, XtraGrid Suite

XtraGrid - How to implement a pager using Embedded Navigator 1. Enable Embedded Navigator using the GridControl.UseEmbeddedNavigator property.
2. Access Embedded Navigator using the GridControl.EmbeddedNavigator property and add two custom buttons - NextPage and PrevPage. Then, specify Tag for each button to distinguish buttons in code.
3. Handle the GridControl.EmbeddedNavigator.ButtonClick event. In this event handler, increment/decrement the current page index, retrieve a new data source, and assign it to the GridControl.DataSource property.
[C#]
privatevoidEmbeddedNavigator_ButtonClick(objectsender,NavigatorButtonClickEventArgse){if(e.Button.ButtonType!=NavigatorButtonType.Custom)return;e.Handled=true;stringtag=(string)e.Button.Tag;switch(tag){case"NextPage":this.CurrentPageIndex=Math.Min(this.CurrentPageIndex+ 1,this.MaxPageIndex);break;case"PrevPage":this.CurrentPageIndex=Math.Max(0,this.CurrentPageIndex- 1);break;}this.GridControl.DataSource=GetData(this.CurrentPageIndex);}
Private Sub EmbeddedNavigator_ButtonClick(ByVal sender As Object, ByVal e As NavigatorButtonClickEventArgs)
    If e.Button.ButtonType <> NavigatorButtonType.Custom Then
        Return
    End If
    e.Handled = True
    Dim tag As String = CStr(e.Button.Tag)
    Select Case tag
        Case "NextPage"
            Me.CurrentPageIndex = Math.Min(Me.CurrentPageIndex + 1, Me.MaxPageIndex)
        Case "PrevPage"
            Me.CurrentPageIndex = Math.Max(0, Me.CurrentPageIndex - 1)
    End Select
    Me.GridControl.DataSource = GetData(Me.CurrentPageIndex)
End Sub

ASPxFormLayout - How to get an item using FindItemByPath method

How to Customize the Save As and Open Dialogs in the Web End-User Report Designer

$
0
0

This example demonstrates how to use the End-User Report Designer client-side API to customize the Save As and Open dialogs.

• To customize the Save As dialog, handle the CustomizeSaveAsDialog event and call the e.Customize method.

• To customize the Open dialog, handle the CustomizeOpenDialog event and call the e.Customize method.

Customize the Save As Dialog

Report files in this example are arranged in folders in the root Reports folder. Folder names correspond to the report's Category. The customized dialog displays report names and categories and allows the user to do the following:

Custom Save As Dialog

• select the existing category and file name, and save the report
• enter the category name and create a new category
• enter the file name and save a report with a new name.

The dialog also displays reports that do not fall in any category - reports created by the ReportsFactory static class and reports in the root Reports folder.

Dialog Template

The Save As dialog is defined in a HTML template. The template contains the following widgets:

• the TextBox editor is bound to the model's inputValue property and displays the report's name
• the SelectBox editor is bound to the model's categories property and displays the category name
• the List widget is bound to the model's categories property and displays reports grouped by category. The categories data is an array of keys (category names) associated with multiple values (report names). The dxListBox requires this structure to display grouped values.
Dialog Model

The dialog model defines the properties used in the dialog template and binds them to Knockout observables. The model specifies the following functions:

• to set the current report URL
• to get the current report URL
• to update the model's properties when the dialog is displayed. The updateCategories JavaScript function is used.

The updateCategories function calls the client-side DevExpress.Reporting.Designer.ReportStorageWeb.getUrls method to obtain report names and categories. This method uses the ReportStorageWebExtension.GetUrls method of a server-side report storage to get a dictionary that contains report names and categories. The code processes the dictionary and fills the categories data array.

The model defines the dialog buttons and their actions. The Save button's action calls the e.Popup.save method and the Cancel button's action calls the e.Popup.cancel method.

The dialog HTML template and dialog model are passed to the e.Customize method to modify the Report Designer's Save As dialog. This method is available in the CustomizeSaveAsDialog event handler.

CustomizeSaveAsDialog event

The customizeSaveAsDialog function is the CustomizeSaveAsDialog event handler. The function uses the event handler argument’s Popup property to specify the dialog’s width, height, and title. The function defines variables used in the dialog model and defines the dialog model. Finally, the function calls the e.Customize method to modify the dialog based on the specified model and template.

The ReportDesignerClientSideEventsBuilder.CustomizeSaveAsDialog method is used to set the name of the JavaScript function that handles the CustomizeSaveAsDialog event (the customizeSaveAsDialog function in this example).

Customize the Open Dialog

The custom Open dialog allows the user to find a report in a list grouped by category, select the report, and open it. The user can type in the text box to filter the list and find report and category names that contain the input string.

Custom Open Dialog

The Open dialog is customized in the same way as the Save As dialog. The ReportDesignerClientSideEventsBuilder.CustomizeOpenDialog method specifies the name of the JavaScript function that handles the CustomizeOpenDialog event - the customizeOpenDialog function in this example.

The Open dialog template and the dialog model are defined and passed to the e.Customize method to modify the dialog.

How to Print and Export a Report in a React Application without Displaying the Report

$
0
0

This example prints and exports a report in a browser without previewing it on a web page.

Print

On the server side, a controller performs the following actions:

creates a report;
exports the report to PDF with the XtraReport.ExportToPdfAsync method;
• send the PDF file back to the client.

On the client-side, a user can do one of the following:

• Print a report in a new tab.
Click a button to call the client-side window.Open(url, "_blank") method to open a new window that contains a PDF file and print the window content.

• Print a report in iFrame.
Click a button to load a PDF file in the HTMLIFrameElement and print its content.

NOTE: We don't recommend printing with an invisible iFrame element because it's not guaranteed to work reliably across all browsers.

For more information review the following help topic:

Web Reporting

Export

The user selects the format and clicks a button to send the format to the server-side controller. The controller calls the export method for the selected format and sends the file back to the browser.

For more information review the following help topic:

Export Reports.

RichEdit for ASP.NET Core - How to integrate the control into a Blazor server application

$
0
0
Requirements • To use the RichEdit control in a Blazor application, you need to have a Universal, DXperience, or ASP.NET subscription.
• Versions of devexpress npm packages should be identical (their major and minor versions should be the same).

This example illustrates a possible way to integrate the client part of ASP.NET Core RichEdit into a Blazor server application. This can be done as follows:

1. Create a new Blazor application using recommendations from the following topic: Get started with ASP.NET Core Blazor.
2. Install necessary NPM packages.

The devexpress-richedit npm package references devextreme as peerDependencies. These peerDependencies packages should be installed manually. This allows developers to control the version of peerDependencies packages and guarantees that the package is installed once.

Install the RichEdit package with required peerDependencies:

• If the package.json file does not exist, create a new NPM configuration file by executing the following command: npm init -y.
• Add the following dependencies to this file:
{  
    ...  "dependencies": {  "devextreme": "<:xx.x.x:>",  "devexpress-richedit": "<:xx.x.x:>"  
  }  
}  
• Call npm i.

You can find all libraries in the node_modules folder once installation is completed.

1. Create a rich edit bundle using recommendations from this help topic: Create a RichEdit Bundle.
cd node_modules/devexpress-richedit  
npm i --save-dev  
npm run build-custom  
cd ../..
1. Copy rich edit scripts
• Copy the bundled script from node_modules/devexpress-richedit/dist/custom/dx.richedit.min.js to wwwroot/js
• Copy bundled css resources from node_modules/devexpress-richedit/dist/custom/dx.richedit.css and icons from node_modules/devexpress-richedit/dist/custom/icons to wwwroot/css
1. Register scripts in the tag of Pages/_Host.cshtml
<link href="css/dx.richedit.css" rel="stylesheet" />  <script src="js/dx.richedit.min.js"></script>  
1. Create a JavaScript rich edit initializing function. For this, create a wwwroot/js/richedit-creator.js file and place the following content in it:
function createRichEdit(documentAsBase64) {  
    const options = DevExpress.RichEdit.createOptions();  
    options.confirmOnLosingChanges.enabled = false;  
    options.exportUrl = 'api/RichEdit/SaveDocument';  
    options.width = '1400px';  
    options.height = '900px';  
    var richElement = document.getElementById("rich-container");  
    window.richEdit = DevExpress.RichEdit.create(richElement, options);  
    if (documentAsBase64)  
        window.richEdit.openDocument(documentAsBase64, "DocumentName", DevExpress.RichEdit.DocumentFormat.Rtf);  
}

Register the created script in the <head> tag of Pages/_Host.cshtml

<script src="js/richedit-creator.js"></script>

1. Override the OnAfterRenderAsync method and call the function created in the previous step:
[C#]
protectedoverrideasyncTaskOnAfterRenderAsync(boolfirstRender){if(firstRender){vardocumentAsBase64="e1xydGYxXGRlZmYwe1xmb250dGJse1xmMCBDYWxpYnJpO319e1xjb2xvcnRibCA7XHJlZDB"+"cZ3JlZW4wXGJsdWUyNTUgO1xyZWQyNTVcZ3JlZW4yNTVcYmx1ZTI1NSA7fXtcKlxkZWZjaHAgXGZzMjJ9e1xzdHl"+"sZXNoZWV0IHtccWxcZnMyMiBOb3JtYWw7fXtcKlxjczFcZnMyMiBEZWZhdWx0IFBhcmFncmFwaCBGb250O317XCp"+"cY3MyXGZzMjJcY2YxIEh5cGVybGluazt9e1wqXHRzM1x0c3Jvd2RcZnMyMlxxbFx0c3ZlcnRhbHRcdHNjZWxsY2J"+"wYXQyXHRzY2VsbHBjdDBcY2x0eGxydGIgTm9ybWFsIFRhYmxlO319e1wqXGxpc3RvdmVycmlkZXRhYmxlfXtcaW5"+"mb31cbm91aWNvbXBhdFxzcGx5dHduaW5lXGh0bWF1dHNwXGV4cHNocnRuXHNwbHRwZ3BhclxkZWZ0YWI3MjBcc2V"+"jdGRcbWFyZ2xzeG4xNDQwXG1hcmdyc3huMTQ0MFxtYXJndHN4bjE0NDBcbWFyZ2JzeG4xNDQwXGhlYWRlcnk3MjB"+"cZm9vdGVyeTcyMFxwZ3dzeG4xMjI0MFxwZ2hzeG4xNTg0MFxjb2xzMVxjb2xzeDcyMFxwYXJkXHBsYWluXHFse1x"+"mczIyXGNmMFxjczEgRG9jdW1lbnQgdGV4dH1cZnMyMlxjZjBccGFyfQ==";awaitJSRuntime.InvokeVoidAsync("createRichEdit",documentAsBase64);}}

Files to look at:

_Host.cshtml
Index.razor
richedit-creator.js
RichEditController.cs
package.json

Diagram - How to integrate the widget into Blazor applications

$
0
0
Requirements • To use the RichEdit control in an Blazor application, you need to have a Universal, DXperience, ASP.NET or DevExtreme subscription.
• Versions of the devexpress npm packages should be identical (their major and minor versions should be the same).

This example illustrates a possible way to integrate the Diagram widget into Blazor applications. This can be done as follows:

1. Create a new Blazor application using recommendations from the following topic: Get started with ASP.NET Core Blazor.
2. Install the necessary DevExtreme and Diagram resources by following steps from the following help topic: Getting Started with Diagram.
3. Register the resources from the previous step. In Blazor server applications, use the Pages/_Host.cshtml file's HEAD section. In Blazor WebAssembly, use the wwwroot/index.html file's HEAD section.
[HTML]
<head><!--...--><linkrel="stylesheet"href="https://cdn3.devexpress.com/jslib/20.1.4/css/dx.common.css">; <linkrel="stylesheet"href="https://cdn3.devexpress.com/jslib/20.1.4/css/dx.light.css">; <scriptsrc="https://code.jquery.com/jquery-3.5.1.min.js"></script>; <linkrel="stylesheet"href="https://cdn3.devexpress.com/jslib/20.1.4/css/dx-diagram.min.css">; <scriptsrc="https://cdn3.devexpress.com/jslib/20.1.4/js/dx-diagram.min.js"></script>; <scripttype="text/javascript"src="js/diagram-init.js"></script><scripttype="text/javascript"src="https://cdn3.devexpress.com/jslib/20.1.4/js/dx.all.js"></script>; </head>
1. Create the *wwwroot/js/diagram-init.js file and implement the logic to initialize the Diagram widget:
window.JsFunctions = {  
    InitDiagram: function () {  
        var diagram = $("#diagram").dxDiagram()  
            .dxDiagram("instance");  

        $.ajax({  
            url: "https://js.devexpress.com/Demos/WidgetsGallery/JSDemos/data/diagram-flow.json";,  
            dataType: "text",  
            success: function (data) {  
                diagram.import(data);  
            }  
        });  
    }  
};
1. Invoke the created InitDiagram method in the OnAfterRender lifecycle event handler:
[C#]
protectedoverridevoidOnAfterRender(boolfirstRender){JSRuntime.InvokeAsync<object>("JsFunctions.InitDiagram");}

Files to look at:

Index.razor
index.html
diagram-init.js

How to implement the distinct count summary type within the PivotGrid

$
0
0

For version 20.1+:

In the latest version (v20.1), we added new summary types including CountDistinct. Please refer to the following What's new topic - What's New 20.1 PivotGrid. You can also find helpful information in this help article - SummaryType.

For older versions:

This example handles the PivotGridControl.CustomSummary event that occurs when the control calculates a summary for a field whose SummaryType is PivotSummaryType.Custom. The event handler calls the e.CreateDrillDownDataSource method to retrieve the underlying data rows for the current cell, counts distinct values and returns the result to the e.CustomValue property.

screenshot

API in this example:

PivotGridControl.CustomSummary event
PivotGridField.SummaryType property
PivotGridCustomSummaryEventArgs.CreateDrillDownDataSource method
PivotDrillDownDataRow class
PivotGridCustomSummaryEventArgs.CustomValue property

See also:

Summarization
Pivot Grid Expression Syntax
Unbound Fields
Binding to Excel Data Source

Examples for other platforms:

WPF - How to Create a Custom Summary Type to Display the Distinct Value Count

Files to look at:

Form1.cs (VB: Form1.vb)

Server Mode - How to implement a Distinct Count Aggregation Function

$
0
0

For version 20.1+:

In the latest version (v20.1), we added new summary types including CountDistinct. Please refer to the following What's new topic - What's New 20.1 PivotGrid. You can also find helpful information in this help article - SummaryType.

For older versions:

This example demonstrates how to define and register the Distinct Count function that allows calculating the count of unique field values if the Server Mode is enabled. This concept is described in the Implementing Custom Functions help topic. A custom function class should implement the following interfaces:
ICustomFunctionOperator
ICustomFunctionOperatorFormattable
IQueryableConvertible

To register a custom function in your application, use the CriteriaOperator.RegisterCustomFunction method.

Files to look at:

DistinctCountFunction.cs (VB: DistinctCountFunction.vb)
Form1.cs (VB: Form1.vb)
Program.cs (VB: Program.vb)

How to provide the search functionality in PivotExcelFieldListControl (Customization Form)

$
0
0

For version 20.1+:

In the latest version (20.1) we added search functionality to the Customization Form. Please refer to the following What's new topic - What's New 20.1 PivotGrid. You can also find helpful information in this article - Field List Overview.

For older versions:

This example illustrates how to add a search box to the field list control.
Our PivotExcelFieldListControl uses the TreeViewFieldsPresenter component to show fields in a tree-like view. In this example, we create a TreeViewFieldsPresenter control descendant and implement the filtering functionality at its level.  The default TreeViewFieldsPresenter is replaced with our descendant via styles.

Important: The provided approach works when fields are grouped via User Folders. In OLAP mode, fields are grouped automatically. If fields are not grouped, PivotGrid uses another control (not TreeViewFieldsPresenter ) to manage hidden fields and custom style is not used.

Files to look at:

MainWindow.xaml (VB: MainWindow.xaml)
MainWindow.xaml.cs (VB: MainWindow.xaml.vb)
PivotFieldsChooser.xaml (VB: PivotFieldsChooser.xaml)
PivotFieldsChooser.xaml.cs (VB: PivotFieldsChooser.xaml.vb)
TreeViewFieldsPresenterEx.cs (VB: TreeViewFieldsPresenterEx.vb)
VisualHelper.cs (VB: VisualHelper.vb)

How to: Use Google, Facebook and Microsoft accounts in ASP.NET XAF applications (OAuth2 demo)

$
0
0

This example demonstrates the use of OAuth2 authentication in a web application. Users can sign in to the application via Google, Facebook or Microsoft authentication providers.


You can try this demo "as is" to overview its capabilities, and then try the demonstrated functionality in your own XAF applications according to the instructions below.

How to Run this Demo

Before running this demo, register developer accounts at the services you are going to use

https://console.developers.google.com/ (Make sure that 'Google+ API' is enabled. Read more here: Creating a Google app for OAuth 2 and connecting the app to the project)
https://developers.facebook.com/
https://portal.azure.com/
• Open the Web.config file and specify your own client IDs and client secrets for each provider.
[XML]
<appSettings><addkey="GoogleClientID"value="YourGoogleClientID"/><addkey="GoogleClientSecret"value="YourGoogleClientSecret"/><addkey="FacebookClientID"value="YourFacebookClientID"/><addkey="FacebookClientSecret"value="YourFacebookClientSecret"/><addkey="MicrosoftClientID"value="YourMicrosoftClientID"/><addkey="MicrosoftClientSecret"value="YourMicrosoftClientSecret"/>

You can remove keys corresponding to providers that you do not want to use.

Note that you may need to update nuget packages to work correctly.

Now you can run the application.

Overview of this Demo Capabilities

In the logon window, there are buttons for each provider specified in Web.config:


Standard XAF authentication with built-in username/password is also supported. When you log in via OAuth authentication, the email is used as a user name. By default, a user object is autocreated for each logon. You can disable autocreation, or specify the auto-assigned role for new users in the InitializeComponent method (see AuthenticationOwin.Web/WebApplication.cs(vb)):

C#

[C#]
OAuthProviderauthProvider=newOAuthProvider(typeof(OAuthUser),securityStrategyComplex1);authProvider.CreateUserAutomatically=true;

VB.NET

[VB.NET]
Dim authProvider AsNew OAuthProvider(GetType(OAuthUser), securityStrategyComplex1) authProvider.CreateUserAutomatically = True

When CreateUserAutomatically is false, the logon is allowed if a user with the email returned by the external service exists in the application database. To grant access to a user with a specific e-mail, use the built-in Admin account, create a user object and set the UserName to this e-mail.

If you set the EnableStandardAuthentication property to true for an auto-created user, this user will be able to login directly, with a user name and password. Note that the password is empty by default, so do not forget to specify it when enabling standard authentication.

Each user can have several associated email addresses. To add or remove email addresses, use the OAuth Authorization Emails list in the user's Detail View.

How to Implement the Demonstrated Functionality in your XAF Application

1. In your solution, open Package Manager Console.

1.1. Choose the YourSolutionName.Web project in the Default project combo box, and execute the following commands to add Owin packages:
Install-Package Microsoft.Owin -Version 4.1.0
Install-Package Microsoft.Owin.Cors -Version 4.1.0
Install-Package Microsoft.Owin.Security -Version 4.1.0
Install-Package Microsoft.Owin.Security.Cookies -Version 4.1.0
Install-Package Microsoft.Owin.Host.SystemWeb -Version 4.1.0
Install-Package Microsoft.Owin.Security.Google -Version 4.1.0
Install-Package Microsoft.Owin.Security.Facebook -Version 4.1.0
Install-Package Microsoft.Owin.Security.MicrosoftAccount -Version 4.1.0

1.2. Switch to the YourSolutionName.Module.Web project and install these two packages:
Install-Package Microsoft.AspNet.Cors -Version 5.2.7
Install-Package Microsoft.Owin -Version 4.1.0
Install-Package Microsoft.Owin.Host.SystemWeb -Version 4.1.0
Install-Package Microsoft.Owin.Security -Version 4.1.0

2. Open the YourSolutionName.Module.Web/Web.config file and specify your own client IDs and client secrets for each provider you are going to use. Refer to the AuthenticationOwin.Web\Web.config file in the demo solution to see the example. Then, set the authentication mode to "None" and comment or remove settings related to the default XAF authentication:
[XML]
<authenticationmode="None"/><!--<forms name="Login" loginUrl="Login.aspx" path="/" timeout="10" />--></authentication><!--<authorization> <deny users="?" /> <allow users="*" /> </authorization>-->
3. Copy the following files from the demo solution to the corresponding locations within your solution:
AuthenticationOwin.Module\IAuthenticationOAuthUser.cs(vb)
AuthenticationOwin.Module\BusinessObjects\OAuthUser.cs(vb)
AuthenticationOwin.Module.Web\Controllers\LogonAuthController.cs(vb)
AuthenticationOwin.Module.Web\Security\CustomSecurityStrategyComplex.cs(vb)
AuthenticationOwin.Module.Web\Images\Facebook.svg
AuthenticationOwin.Module.Web\Images\Google.svg
AuthenticationOwin.Module.Web\Images\Microsoft.png
AuthenticationOwin.Web\Startup.cs(vb)
AuthenticationOwin.Web\LogonTemplateContent1.ascx
AuthenticationOwin.Web\LogonTemplateContent1.ascx.cs(vb)
AuthenticationOwin.Web\LogonTemplateContent1.ascx.designer.cs(vb)
AuthenticationOwin.Web\Login.aspx
AuthenticationOwin.Web\Login.aspx.designer.cs
AuthenticationOwin.Web\Security\CustomAuthenticationStandardProvider.cs(vb)
AuthenticationOwin.Web\Security\OAuthProvider.cs(vb)

Include the copied files to your solution (Add|Existing Item... ). Update the namespace names in the copied code files to match namespaces you use in your solution. For image files, set the Build Action property to Embedded Resource.

4. Edit the YourSolutionName.Module.Web\WebModule.cs(vb) file. In the overridden Setup method, handle theXafApplication.CreateCustomLogonWindowControllers event and add the LogonAuthController to the e.Controllers collection passed to this event. Refer to the AuthenticationOwin.Module.Web\Module.cs(vb) file to see an example.

5. Edit the YourSolutionName.Web\WebApplication.cs(vb) code:

Register CustomSecurityStrategyComplex:

C#

[C#]
this.securityStrategyComplex1=newAuthenticationOwin.Module.Web.Security.CustomSecurityStrategyComplex();

VB.NET

[VB.NET]
Me.securityStrategyComplex1 = New AuthenticationOwin.Module.Web.Security.CustomSecurityStrategyComplex()

Use AuthenticationMixed instead of your authentication:

C#

[C#]
publicYourApplicationNameAspNetApplication(){InitializeComponent();//... AuthenticationMixedauthenticationMixed=newAuthenticationMixed();authenticationMixed.LogonParametersType=typeof(AuthenticationStandardLogonParameters);authenticationMixed.AuthenticationProviders.Add(typeof(CustomAuthenticationStandardProvider).Name,newCustomAuthenticationStandardProvider(typeof(OAuthUser)));OAuthProviderauthProvider=newOAuthProvider(typeof(OAuthUser),securityStrategyComplex1);authProvider.CreateUserAutomatically=true;authenticationMixed.AuthenticationProviders.Add(typeof(OAuthProvider).Name,authProvider);securityStrategyComplex1.Authentication=authenticationMixed;

VB.NET

[VB.NET]
PublicSubNew() InitializeComponent() '... Dim authenticationMixed AsNew AuthenticationMixed() authenticationMixed.LogonParametersType = GetType(AuthenticationStandardLogonParameters) authenticationMixed.AuthenticationProviders.Add(GetType(CustomAuthenticationStandardProvider).Name, New CustomAuthenticationStandardProvider(GetType(OAuthUser))) Dim authProvider AsNew OAuthProvider(GetType(OAuthUser), securityStrategyComplex1) authProvider.CreateUserAutomatically = True authenticationMixed.AuthenticationProviders.Add(GetType(OAuthProvider).Name, authProvider) securityStrategyComplex1.Authentication = authenticationMixed
6. Implement the IAuthenticationOAuthUser interface in your custom user class. You can see an example in the AuthenticationOwin.Module\BusinessObjects\OAuthUser.cs file. If you use the built-in user, you can use the OAuthUser class and set the SecurityStrategy.UserType property to OAuthUser in the Application Designer.

7. Change the code that creates your predefined users in YourSolutionName.Module\DatabaseUpdate\Updater.cs. Set EnableStandardAuthentication to true for users who can login with standard authentication (username and password). See the example in the AuthenticationOwin.Module\DatabaseUpdate\Updater.cs file.

8. Register the LogonTemplateContent1.ascx template in the Session_Start method in the YourSolutionName.Web\Global.asax.cs(vb) file:

C#

[C#]
WebApplication.Instance.Settings.LogonTemplateContentPath="LogonTemplateContent1.ascx";

VB.NET

[VB.NET]
WebApplication.Instance.Settings.LogonTemplateContentPath = "LogonTemplateContent1.ascx"
9. Copy the LoginWith* actions customizations and the AuthenticationStandardLogonParameters_DetailView layout settings from the AuthenticationOwin.Web\Model.xafml file to the same file in the YourSolutionName.Web project. If you have no model customizations in Model.xafml, you can just overwrite it with the file from demo. Ensure that the IsPostBackRequired property of each LoginWith* action is set to true.

10. Configure OAuth2 provider services according to their documentation.

This example shows how XAF can get a user's email from OAuth2 services and create (or authenticate) a user based on this data (the OAuthProvider.Authenticate method).

Note that a third-party API and settings of OAuth2 services (Google, Facebook, and Microsoft) that we use in this example often change and we cannot control this at the level of our components. While we try to keep this example up-to-date with these changes, it is always better to refer to the official OAuth2 provider documentation. Please leave comments or create merge requests to this example if you find any inconsistencies.

Known OAuth2 services specificities:

• Microsoft requires the '/signin-microsoft' string to the Redirect URI (validated on March 13th 2020);
chrome_2020-03-13_11-58-18w
• "The Microsoft.Owin.Security.MicrosoftAccount assembly supports authenticating to both: Microsoft user accounts and Azure AD (School/Orgnizational) user accounts. To successfully authenticate an Azure AD user account in this demo project, ensure that you configure the Azure AD registered application as 'multi-tenanted = yes'. (The manifest entry: "availableToOtherTenants": true)" - added by nrpieper:
• Google requires to enable the Google+ API.

Tip: You can refer to the OWIN OAuth 2.0 Authorization Server documentation to learn how to add more authentication providers.

For an example of integrating OAuth2 authentication in a WinForms XAF application, refer to the XAF - OAuth2 Authentication for WinForms ticket.

Files to look at:

LogonAuthController.cs (VB: LogonAuthController.vb)
CustomSecurityStrategyComplex.cs (VB: CustomSecurityStrategyComplex.vb)
OAuthUser.cs (VB: OAuthUser.vb)
IAuthenticationOAuthUser.cs (VB: IAuthenticationOAuthUser.vb)
CustomAuthenticationStandardProvider.cs (VB: CustomAuthenticationStandardProvider.vb)
OAuthProvider.cs (VB: OAuthProvider.vb)
Startup.cs (VB: Startup.vb)
WebApplication.cs (VB: WebApplication.vb)
See Also

Office.Cloud.Microsoft Module in eXpand Framework by Apostolis Bekiaris - authenticates against Azure Active Directory and contains API for querying the Microsoft Graph endpoints.

TreeList - How to display and edit file system with the client-side RemoteFileSystemProvider

How to use a custom Lookup Property Editor control for reference properties in WinForms

$
0
0

Clipboard-File-1.png

FEATURES

LookupPropertyEditorEx
This is a regular XAF PropertyEditor class that can be used for referenced properties instead of the standard LookupPropertyEditor in Windows Forms applications.
By default, this editor allows you to choose a value from the drop down list. It's possible to find the required record in the drop down list by typing text (auto-incremental search).
If you want to clear a value, use either the Control+Delete keystroke or click the minus (-) button.
If you want to add a new object, click the plus (+) button. It will show a modal DetailView allowing you to fill object properties and save it.

IMPORTANT NOTES 1. From this example, you need use only one assembly (the WinSolution from the example is just a demo application, and it has no relation to the solution): Editors.Win.dll
2. Since this is a regular XAF module, you should add this module to your application to be able to use its features. In case of standard modules, you add them from the Toolbox via the Application or Module designer. Since we deal with a custom module, you should add this into the Toolbox manually. Please refer to the How to: Add Items to the Toolbox article in MSDN, for more details.
3. Alternatively, you can take the source code and include it in your solution.
4. The LookupPropertyEditorEx is set as default for all lookup properties in the application.
5. If you want to change this, then invoke the Model Editor for the Windows Forms application project or module, and change the EditorType property of the DetailViewItems | PropertyEditors | LookupProperty node. Or, change the PropertyEditorType property for a class member, ListView column or DetailView item nodes individually.

See Also:
Implement Custom Property Editors
PropertyEditors.Lookup - How to provide alternative data representations for reference lookup properties (e.g., a simple drop-down box, a complex multi-column grid, or a tree view)

Blazor Data Grid - How to edit a row on a separate page

$
0
0

This example illustrates how to edit DataGrid's row on a separate page.

The main idea is to open a new page and send the key value of the currently edited row as a parameter.
For this, create your own command button using the column's DisplayTemplate.
The navigation can be implemented using the default tag as it's demonstrated with the "Edit" button.
Another approach is using the default NavigationManager object. It's demonstrated in the "Save" and "Cancel" buttons on the SeparateEditForm page.

Web Report Designer - How to open a report with an untyped DataSet as a data source

$
0
0

Untyped data sets cannot be serialized with an XML report layout.
The Web Report Designer works with XML report representation. If you bind a report to an untyped data set, create a custom DevExpress.XtraReports.Native.IDataSerializer and use data set XML-serialization methods to save and restore it.

In the IDataSerializer.Serialize method, serialize a DataSet to XML using the DataSet.WriteXml method.
In the IDataSerializer.Deserialize method, create a new DataSet instance and populate it from a correctly formatted XML stream by using the DataSet.ReadXml method.

See also:
How to serialize a report to XML with an untyped DataSet as a data source

Files to look at:

Default.aspx (VB: Default.aspx)
Default.aspx.cs (VB: Default.aspx.vb)
Global.asax (VB: Global.asax)
Global.asax.cs (VB: Global.asax.vb)
CustomUntypedDataSetSerializer.cs (VB: CustomUntypedDataSetSerializer.vb)
DataHelpers.cs (VB: DataHelpers.vb)
DataSourceInitializer.cs (VB: DataSourceInitializer.vb)

RichEdit for ASP.NET Core - How to integrate the control into a Blazor client application

$
0
0
Requirements • To use the RichEdit control in a Blazor application, you need to have a Universal, DXperience, or ASP.NET subscription.
• Versions of devexpress npm packages should be identical (their major and minor versions should be the same).

This example illustrates a possible way to integrate the client part of ASP.NET Core RichEdit into a Blazor client application using steps from the following help topic: Rich Text Editor > Get Started > Blazor WebAssembly Application.

Files to look at:

index.html
richedit-creator.js
RichEditController.cs
package.json

How to programmatically generate ObjectDataSource and bind object data source constructor parameters to report parameters

$
0
0

This example demonstrates how to programmatically generate an object data source with a parameterized constructorand map object data source parameters to report parameters.

Take note that the data source generation routine does not rely on a particular platform and is more like a 'core' functionality.

See also:
How to: Bind a Report to an Object Data Source
How to provide ASPxReportDesigner with the SqlDataSource, ObjectDataSource, EFDataSource and ExcelDataSource at runtime

Files to look at:

Default.aspx (VB: Default.aspx)
Default.aspx.cs (VB: Default.aspx.vb)

RibbonControl - How to provide CustomDraw capabilities for bar items

$
0
0
RibbonControl - How to provide CustomDraw capabilities for bar items

Starting with v15.1, we support the RibbonControl.CustomDrawItem event.

For earlier versions:

This example illustrates how to implement your own event at a RibbonControl level to allow you to draw a bar item link as required.

TreeView for Blazor - How to implement the Breadcrumbs control based on a selected node

$
0
0

This example uses the Bootstrap Breadcrumb component that is bound to DxTreeView via the SelectionChanged event handler. TreeView's selected node is changed when a Breadcrumb item is selected:

<a @onclick="@(() => SelectNode(currentNodeInfo.Text))" href="#">  
    @currentNodeInfo.Text  </a>  
...  
void SelectNode(string text) {  
    TreeView.SelectNode((n) => n.Text == text);  
}  

Files to look at:

Index.razor

How to Localize the Reporting Controls in a JavaScript Application with Knockout Bindings

$
0
0

This example includes the server-side (backend) application that is an ASP.NET MVC application created from the DevExpress Visual Studio template as described in the Report Designer's Server-Side Configuration (ASP.NET MVC) topic.

The client-side (front-end) application is created in JavaScript with npm as described in the Basic Report Designer Integration (with npm or Yarn Package Managers) document.

To run the example, perform the following steps:

1. Open the CS or VB solution in Visual Studio and rebuild to install the required NuGet packages.
2. Run the command prompt, navigate to the ClientSide folder and execute the command:
npm install
3. Open the Internet Information Services manages and add a website whose content's physical path is the ClientSide folder. Specify any free port, in this example it is 1020. Start the web site.
4. Run the Visual Studio project.
5. Open the URL localhost:1020 (port number may be different, as specified in step 3) in your browser.

Viewing all 7205 articles
Browse latest View live


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