how to get input for transparent elements

Some elements in WPF are transparent by default (like Canvas) and for being transparent it doesn't get input events (mouse, keyboard). What is the correct way to get input events for these elements ? I know I can set a Background (event Brushes.Transparent) to workaround, but I don't want to change any default prorperty in the element if possible. I suppose I can subclass canvas and reimplement HitTestCore() but that is more work and I would like to do.

Thanks
Felipe

[490 byte] By [FelipeHeidrich] at [2007-12-27]
# 1

Would it be acceptable to style the Canvases so they all have transparent backgrounds?

<StackPanel
xmlns="
http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="
http://schemas.microsoft.com/winfx/2006/xaml">
<StackPanel.Resources>
<Style TargetType="{x:Type Canvas}">
<Setter Property="Canvas.Background" Value="Blue"/>
</Style>
</StackPanel.Resources>

<Canvas Width="100" Height="100"/>
<Canvas Width="300" Height="300"/>
</StackPanel>

AnthonyHodsdon-MSFT at 2007-9-4 > top of Msdn Tech,Visual Studio Orcas,Windows Presentation Foundation (WPF)...
# 2

Thanks Anthony,

I would prefer not to touch the default background for the uielement, different themes can define different colors for background and for me is important to keep the right one.

here is example: I have a TabControl, inside of it I have group. The background of the TabControl depends on the theme (it can be grandient, solid gray, whatever). If I don't touch the backgrond of the group, in the normal case it is transparent showing the background of the tabcontrol thru. If the user sets the background of all group to red it will still work (since I never set the background of it).

I guess I can set the background to Transparent if only background == null.

Felipe

FelipeHeidrich at 2007-9-4 > top of Msdn Tech,Visual Studio Orcas,Windows Presentation Foundation (WPF)...

Visual Studio Orcas

Site Classified