Back to Devexpress

AsyncDownloadPolicy.FailedEventArgs.Content Property

corelibraries-devexpress-dot-data-dot-asyncdownloadpolicy-dot-failedeventargs.md

latest2.9 KB
Original Source

AsyncDownloadPolicy.FailedEventArgs.Content Property

Gets or sets the content in place of an external resource that fails to load.

Namespace : DevExpress.Data

Assembly : DevExpress.Data.v25.2.dll

NuGet Package : DevExpress.Data

Declaration

csharp
public Stream Content { get; set; }
vb
Public Property Content As Stream

Property Value

TypeDescription
Stream

The stream with the content.

|

Remarks

Read the following topic for additional information: Suppress Control Requests to Download Data from External URLs.

Example

The following example handles the Failed event to display a placeholder image in a WinForms PictureEdit if an external image fails to load:

csharp
public Form1() {
    InitializeComponent();
    DevExpress.Data.AsyncDownloadPolicy.Failed += AsyncDownloadPolicy_Failed;
}

void AsyncDownloadPolicy_Failed(object sender, DevExpress.Data.AsyncDownloadPolicy.FailedEventArgs e) {
    if (e.ValueType.Name == "ImageOrSvgImageResult") {
        MemoryStream stream = new MemoryStream();
        /* A placeholder image is obtained from the DevExpress SvgImageCollection.
         * The placeholder image was added to the SvgImageCollection at design time.
         */
        var errorImage = svgImageCollection1[0];
        errorImage.Save(stream);
        e.Content = stream;
    }
}

async void btnLoadImage_Click(object sender, EventArgs e) {
    await pictureEdit1.LoadAsync("EXTERNAL_IMAGE_URL");
}
vb
Public Sub New()
    InitializeComponent()
    DevExpress.Data.AsyncDownloadPolicy.Failed += AsyncDownloadPolicy_Failed
End Sub

Private Sub AsyncDownloadPolicy_Failed(ByVal sender As Object, ByVal e As DevExpress.Data.AsyncDownloadPolicy.FailedEventArgs)
    If e.ValueType.Name = "ImageOrSvgImageResult" Then
        Dim stream As New MemoryStream()
        Dim errorImage = svgImageCollection1(0)
        errorImage.Save(stream)
        e.Content = stream
    End If
End Sub

Async Sub btnLoadImage_Click(ByVal sender As Object, ByVal e As EventArgs)
    Await pictureEdit1.LoadAsync("EXTERNAL_IMAGE_URL")
End Sub

See Also

AsyncDownloadPolicy.FailedEventArgs Class

AsyncDownloadPolicy.FailedEventArgs Members

DevExpress.Data Namespace