Search This Blog

Tuesday, March 29, 2016

How to change the default error icons for failed validation rules

I've just updated the corresponding Support Center ticket and want to share one more advanced example on using the built-in ImageLoader API with you. Before reading further, please learn more on this helper class from its docs or from my previous post on the same subject: 




In the latest XAF v15.2+, there is a universal and platform-agnostic way to replace the default validation images globally in the application by handling the static DevExpress.ExpressApp.Utils > ImageLoader >CustomGetImageInfo  event. Consider the following example code that can be added in YourSolutionName.Module/Module.cs file:


[C#]Open in popup window
using DevExpress.ExpressApp.Utils; namespace MainDemo.Module { public sealed partial class MainDemoModule : ModuleBase { private const string STR_CustomErrorImageName = "BO_Skull"; public MainDemoModule() { InitializeComponent(); /* Dennis: The images corresponding to validation errors may have the followng names by default: "Error" or "State_Validation_Invalid" + size suffix "Warning" or "State_Validation_Warning" + size suffix "Information" or "State_Validation_Information" + size suffix */ ImageLoader.CustomGetImageInfo += (s, e) => { bool isLargeImage = e.ImageName.EndsWith("_32x32") || e.ImageName.EndsWith("_48x48"); if(e.ImageName.Contains("State_Validation_Invalid") || e.ImageName == "Error") { e.Handled = true; e.ImageInfo = isLargeImage ? ImageLoader.Instance.GetLargeImageInfo(STR_CustomErrorImageName) : ImageLoader.Instance.GetImageInfo(STR_CustomErrorImageName); } }; }
This simple code will work in both ASP.NET and WinForms apps.

Even thought there is a built-in image used in the example, you can usually replace it with any other image. Refer to the event's documentation for a more complex use-case scenario where the image is obtained from the database.

2 comments:

  1. Hi Dennis:
    I'm trying to get informed about Devexpress XPO/EF and XAF. I notice that on the official Devexpress blogs XPO is rarely mentioned. I enjoy your posts, but wonder why they aren't a part of the official blog? Does this indicate that XPO is not a primary product for Devexpress?

    ReplyDelete
    Replies
    1. >>I enjoy your posts, but wonder why they aren't a part of the official blog?<<
      Thanks for your feedback! I started my personal blog for *more frequent* and informal posting of any news related to our frameworks, while our official team blog is typically used for larger announcements like What's New in the next major release or other things like that. Taking into account that this blog is re-translated into our developers groups in social networks and is referenced from the Support Center and https://www.devexpress.com/Products/NET/Application_Framework/xaf-community.xml, we also do not have any problems with reaching a large part of the XAF community.
      Finally, it is important to remember that there are other DevExpress users who are not using XAF and they may be not very happy seeing only XAF news in their blogs feed at https://community.devexpress.com/blogs/ (just imagine what this page would look like with my current posting rate).

      So, this blog does not indicate anything related to XAF or XPO. As for the latter, we are quite proud of XPO and all that it offers. We support it and certainly want to improve it. So if there are suggestions/issues you have, please let us know via the Support Center (https://www.devexpress.com/Support/Center/Question/Create).

      Delete