Note that there are some explanatory texts on larger screens.

plurals
  1. POWPF Canvas not rendering programmatically added children on XP
    primarykey
    data
    text
    <p>I have developed a WPF application in .NET 4.0 that makes use of several Canvas UI elements. Everything works fine on my development machine that runs Windows 8.</p> <p>I ran into problem when I tested that app in a virtual machine running Windows XP. Canvas renders elements added in XAML, but fails to render elements created in code.</p> <p>Program was tested on Windows 8, Windows 7(VM) and Windows XP SP3(VM). Everything works fine except for the rendering of elements created in codebehind under XP. I have tested and elements are created, and properly added as children.</p> <p>I have tried with manually setting Z index, calling UpdateLayout and InvalidateVisual, but to no avail.</p> <p>Thanks for any help in advance.</p> <p>UPDATE: XAML</p> <pre><code>&lt;Canvas Name="frontPresenter" Background="White" Grid.Column="1" Grid.Row="1"/&gt; &lt;Canvas Name="frontPlaceholderPresenter" Grid.Column="1" Grid.Row="1" Width="{Binding ActualWidth, ElementName=frontPresenter}" Height="{Binding ActualHeight, ElementName=frontPresenter}"/&gt; </code></pre> <p>C#</p> <pre><code>foreach (Models.BadgePosition position in currentItem.BadgesLayouts[layoutItem].BadgesPositions) { double size = currentItem.FrontImage.Width * (position.Badge.BadgeImage == LanguageAssets.Controls.BadgePlaceholder ? 0.1d : 0.15d) * scale; Image img = new Image { Source = position.Badge.BadgeImage, Width = size, Height = size }; img.DataContext = position; Canvas.SetTop(img, currentItem.FrontImage.Height * position.Y * scale); Canvas.SetLeft(img, currentItem.FrontImage.Width * position.X * scale); if (canvas == frontPresenter) { if (position.Badge.BadgeImage == LanguageAssets.Controls.BadgePlaceholder) frontPlaceholderPresenter.Children.Add(img); else canvas.Children.Add(img); } else canvas.Children.Add(img); </code></pre> <p>In essence, I want to print the final canvas, but not the placeholders. That is why I create placeholder images on the canvas in front and replace the images with the image user chooses on the same place but on the canvas meant for printing. This code does the job on Windows 8 and Windows 7 but bugs out on XP.</p> <p>Note: Similar code</p> <pre><code>Canvas canvas = new Canvas(); canvas.Children.Add(img); new Window { Content = canvas }.Show(); </code></pre> <p>will draw as expected on Windows 8 and 7, but will not render <code>img</code> object on XP.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload