I can't get any online solution for this specific issue. Please suggest any solution to generate xps of the Textblock with shadow effect
I am creating XPS file.I have created a canvas from CreateCanvas method in which i have a textBlock to which i am setting the dropshadow effect and alignment properties of the textblock .If I change the default alignment i.e Top-left of the textBlock and applying dropShadow Effect to the textBlock then it is not displayed properly in the XPS file. When i look into the visual tree it properly displays the alignment of the textBlock but when it is written by XpsDocument.Write it can't produce the same result. If i remove the dropshadow effect property then xps created properly display textBlock alignment.
Further I have looked into the source code of XPS (by changing its extenstion from xps to zip) what i have found XPS writer is converting the text element into an Image and displaying it.In case of Top-Left Alignment and ReSizeToFit the Image resource is created absoultely fine (In Resources Folder a png is gets created).However in case of the center alignment (or any other alignment position different from Top-Left) the blank Image has been created.
using (var doc =newXpsDocument(fileName,FileAccess.Write)){var writer =XpsDocument.CreateXpsDocumentWriter(doc);var canvas =CreateCanvas();// Issue is here when writing the visual writer.Write(canvas); doc.Close();}privatestaticCanvasCreateCanvas(){var canvas =newCanvas();TextBlock mainText =newTextBlock(); mainText.Text="Sample Simple Text";var dpshadow =newDropShadowEffect(); dpshadow.Color=(Color)ColorConverter.ConvertFromString("Red"); dpshadow.Opacity=Convert.ToDouble(propertybag.ShadowOpacity); dpshadow.ShadowDepth=Convert.ToDouble(propertybag.ShadowDepth); dpshadow.Direction=Convert.ToDouble(propertybag.ShadowDirection); dpshadow.BlurRadius=Convert.ToDouble(propertybag.ShadowBlurRadius); dpshadow.RenderingBias=RenderingBias.Performance; mainText.Effect= dpshadow; mainText.TextAlignment=Base.Align.GetTextAlignment(propertybag.Align); mainText.HorizontalAlignment=(propertybag.Align!=Base.Align.None)?Base.Align.GetHorizontalAlignment(propertybag.Align):HorizontalAlignment.Left; mainText.VerticalAlignment=(propertybag.VAlign!=Base.VAlign.None)?Base.VAlign.GetVerticalAlignment(propertybag.VAlign):VerticalAlignment.Top; canvas.Children.Add(mainText);return canvas;}