All docs
V20.2
20.2
20.1
19.2
19.1
The page you are viewing does not exist in version 19.1. This link will take you to the root page.
18.2
The page you are viewing does not exist in version 18.2. This link will take you to the root page.
18.1
The page you are viewing does not exist in version 18.1. This link will take you to the root page.
17.2
The page you are viewing does not exist in version 17.2. This link will take you to the root page.

Badge.ContentFormatProvider Property

Gets or sets the format provider to format the BadgeControl's content. This is a dependency property.

Namespace: DevExpress.Xpf.Core

Assembly: DevExpress.Xpf.Core.v20.2.dll

Declaration

public IFormatProvider ContentFormatProvider { get; set; }
Public Property ContentFormatProvider As IFormatProvider

Property Value

Type Description
IFormatProvider

An object of a class that implements a IFormatProvider. IFormatProvider provides a mechanism for retrieving an object to control the Badge's content formatting.

Remarks

The following code sample specifies the Badge.ContentStringFormat and uses the ContentFormatProvider property to specify the Badge's content format:

WPF Badges - ContentStringFormat Property

<dx:SimpleButton
   HorizontalAlignment="Center"
   VerticalAlignment="Center"
   Glyph="{dx:SvgImageSource Uri=Glyph_Message.svg}">
   <dx:Badges.Badge>
       <dx:Badge Content="150" BadgeKind="Error"
                 ContentStringFormat="{}{0:length2}"
                 ContentFormatProvider="{local:BadgeFormatProvider}"/>
   </dx:Badges.Badge>
</dx:SimpleButton>
public class BadgeFormatProvider : MarkupExtension, IFormatProvider, ICustomFormatter {
   static readonly Regex formatExpression = new Regex(@"length(\d+)", RegexOptions.Compiled);

   public object GetFormat(Type formatType) { return this; }
   public override object ProvideValue(IServiceProvider serviceProvider) { return this; }
   public string Format(string format, object arg, IFormatProvider formatProvider) {
       if(arg==null)
           return String.Empty;

       var match = formatExpression.Match(format);
       if(!match.Success)
           return String.Format(CultureInfo.CurrentCulture, format ?? "{0}", arg);

       var length = int.Parse(match.Groups[1].Value);
       var inputString = Convert.ToString(arg);
       if (inputString.Length <= length)
           return inputString;

       if (decimal.TryParse(inputString, out _))
           return (Math.Pow(10, length) - 1) + "+";

       return inputString.Substring(0, length) + "...";
   }
}
See Also