How can I use the attached properties of Canvas to position child elements ?
This example shows how to use the attached properties of Canvas to position child elements. [XAML] <Page xmlns=’http://schemas.microsoft.com/winfx/2006/xaml/presentation’ WindowTitle=’Canvas Attached Properties Sample’> <Border HorizontalAlignment=’Left’ VerticalAlignment=’Top’ BorderBrush=’Black’ BorderThickness=’2′> <Canvas Background=’LightBlue’ Width=’400′ Height=’400′> <Button Canvas.Top=’50’>Canvas.Top=’50′</Button> <Button Canvas.Bottom=’50’>Canvas.Bottom=’50′</Button> <Button Canvas.Left=’50’>Canvas.Left=’50′</Button> <Button Canvas.Right=’50’>Canvas.Right=’50′</Button> </Canvas> </Border> </Page>
How do I make a Button to trigger a Click event at specific time intervals when the mouse is down like a ScrollBar button?
This can be done with the following piece of code. [C#] public class RepeatButton : Button { private Timer timer1; public int Interval { get { return Timer.Interval; } set { Timer.Interval = value; } } private Timer Timer { get { if ( timer1 == null ) { // create and setup the timer timer1 = new Timer(); timer1.Tick += new EventHandler( OnTimer ); timer1.Enabled = false; } return timer1; } } protected override void OnMouseDown( MouseEventArgs me ) { base.OnMouseDown( me ); Timer.Enabled = true; // turn on the timer } protected override void OnMouseUp( MouseEventArgs me ) { Timer.Enabled = false; // turn off the timer base.OnMouseUp( me ); } private void OnTimer( object sender, EventArgs e ) { OnClick( EventArgs.Empty ); // fire off a click on each timer tick } }
How can I use a BulletDecorator control that uses an image as the Bullet and a non-text element as the Child ?
The following example shows how to define a BulletDecorator control that uses an ’image’ as the Bullet and a ’non-text element’ as the Child. In this example, the Bullet object centers itself next to the non-text element. [XAML] <BulletDecorator Grid.Row=’3′ Grid.Column=’0′ Margin=’0,5,0,0′> <BulletDecorator.Bullet> <Image Source=’images\apple.jpg’/> </BulletDecorator.Bullet> <Ellipse Height=’75’ Width=’50’ Fill=’Purple’ HorizontalAlignment=’Left’ ></Ellipse> </BulletDecorator>
Can I host WPF objects in WIN32 application ?
Yes. VisualObjects of WPF application can be hosted in WIN32 application using the “HwndSource” class. The HwndSource class wraps the objects in the WPF application and allow them to be incorporated in the WIN32 application as a child window.
How HitTest methods in VisualTreeHelper is useful ?
HitTest methods are used to determine whether a point or geometry value is within the content of a rendered object like a control or graphic element. Using the ’HitTest’ methods you can determine whether the mouse was clicked within a control and also by overriding the implementation, custom actions can be performed.