Re: WPF Background issue
- From: Glenn <Glenn@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Thu, 28 Feb 2008 10:49:08 -0800
Here's some code to reproduce this problem:
Window1.xaml:
<Window x:Class="BackgroundIssue.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:test="clr-namespace:BackgroundIssue"
Title="Background Issue" Height="375" Width="464"
xmlns:my="clr-namespace:System;assembly=mscorlib">
<Grid>
<test:CustomViewer x:Name="customViewer1" HorizontalAlignment="Left"
Width="238" Background="Red" />
</Grid>
</Window>
CustomWindow.cs:
using System;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows;
namespace BackgroundIssue
{
public class CustomViewer : ScrollViewer
{
public CustomViewer()
{
this.VerticalScrollBarVisibility = ScrollBarVisibility.Hidden;
}
protected override void OnRender(System.Windows.Media.DrawingContext
drawingContext)
{
drawingContext.DrawRectangle(null, new Pen(new
SolidColorBrush(Colors.Navy), 10), new Rect(20, 20, 400, 300));
}
}
}
This will create a window with the control on half of it. A rectangle is
drawn larger than the control so you can see that the red background is
covering what is drawn in the OnRender method.
-Glenn
"Bob Powell [MVP]" wrote:
Post some code....
--
Bob Powell [MVP]
Visual C#, System.Drawing
Ramuseco Limited .NET consulting
http://www.ramuseco.com
Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm
Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm
All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
Glenn wrote:
Hi,
I've created a control that derives from ScrollViewer and override the
OnRender method to draw onto the control. However, if the Background
property is set, the background always draws on top of whatever I draw.
Even if I don't call base.OnRender the background is drawn, so I'm not sure
what is drawing the background or why it would be drawn after OnRender is
called. Does anyone have any ideas?
- Follow-Ups:
- Re: WPF Background issue
- From: Bob Powell [MVP]
- Re: WPF Background issue
- References:
- Re: WPF Background issue
- From: Bob Powell [MVP]
- Re: WPF Background issue
- Prev by Date: Re: WPF Background issue
- Next by Date: struggling to save tiff as png and keep file size down
- Previous by thread: Re: WPF Background issue
- Next by thread: Re: WPF Background issue
- Index(es):
Relevant Pages
|