How can I create an Expander with a ScrollViewer ?

This example shows how to create an Expander control that contains complex content such as an image and text. The example also encloses the content of the Expander in a ’ScrollViewer’ control. [XAML] <Expander Width=’200′ HorizontalContentAlignment=’Stretch’> <Expander.Header> <BulletDecorator> <BulletDecorator.Bullet> <Image Width=’10’ Source=’images\icon.jpg’/> </BulletDecorator.Bullet> <TextBlock Margin=’20,0,0,0′>My Expander</TextBlock> </BulletDecorator> </Expander.Header> <Expander.Content> <ScrollViewer Height=’50’> <TextBlock TextWrapping=’Wrap’> Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. </TextBlock> </ScrollViewer> </Expander.Content> </Expander>

How do I make the Context Menu to close after a set time interval?

To automatically close the context menu after a set time interval, you can use a Timer and send an Esc keystroke after the desired time interval as shown. [C#] private void timer1_Tick(object sender, System.EventArgs e) { SendKeys.Send(‘{ESC}’); timer1.Stop(); } private void contextMenu1_Popup(object sender, System.EventArgs e) { //set interval to 5 seconds timer1.Interval = 5000; timer1.Start(); }

How to determine which Panel in the Windows Forms StatusBar Control is Clicked ?

[C#] private void statusBar1_PanelClick(object sender, System.Windows.Forms.StatusBarPanelClickEventArgs e) { switch (statusBar1.Panels.IndexOf(e.StatusBarPanel)) { case 0 : MessageBox.Show(‘You have clicked Panel One.’); break; case 1 : MessageBox.Show(‘You have clicked Panel Two.’); break; } } //Place the following code in the form’s constructor to register the event handler. this.statusBar1.PanelClick += new System.Windows.Forms.StatusBarPanelClickEventHandler (this.statusBar1_PanelClick);

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 } }