How can I create a GroupBox that has a title and a visible border that encloses it’s content ?
This can be created with the following piece of code. [XAML] <GroupBox Width=’300′ Height=’410′> <GroupBox.Header> <Label>Employee Data</Label> </GroupBox.Header> <StackPanel> <TabControl Name=’myTabControl’ TabStripPlacement=’Top’ Margin=’0, 0, 0, 10′ Height=’350′ > <TabItem Name=’PersonalInfo’> <TabItem.Header>_Personal Info</TabItem.Header> <StackPanel> <TextBlock>Employee</TextBlock> <TextBlock>Select your name</TextBlock> <ListBox Name=’empName’ SelectionChanged=’updateSummary’> <ListBoxItem IsSelected=’true’>Esther</ListBoxItem> <ListBoxItem>George</ListBoxItem> <ListBoxItem>Alan</ListBoxItem> <ListBoxItem>Eric</ListBoxItem> </ListBox> </StackPanel> </TabItem> <TabItem> <TabItem.Header>_Job Info</TabItem.Header> <StackPanel> <TextBlock>Select a job</TextBlock> <ListBox Name =’job’ SelectionChanged=’updateSummary’> <ListBoxItem IsSelected=’true’>Programmer</ListBoxItem> <ListBoxItem>Tester</ListBoxItem> <ListBoxItem>Writer</ListBoxItem> <ListBoxItem>Manager</ListBoxItem> </ListBox> </StackPanel> </TabItem> <TabItem Name=’Skill’> <TabItem.Header>_Skill</TabItem.Header> <StackPanel> <TextBlock> Select your strongest skill </TextBlock> <ListBox Name=’skills’ SelectionChanged=’updateSummary’> <ListBoxItem IsSelected=’true’>C#</ListBoxItem> <ListBoxItem>Visual Basic</ListBoxItem> <ListBoxItem>.NET</ListBoxItem> <ListBoxItem>JScript</ListBoxItem> </ListBox> </StackPanel> </TabItem> <TabItem Name=’Summary’ > <TabItem.Header>Su_mmary</TabItem.Header> <StackPanel> <TextBlock Name=’emp’/> <TextBlock Name=’ejob’/> <TextBlock Name=’eskill’/> </StackPanel> </TabItem> </TabControl> <Button Content=’Show Summary’ Click=’goToSummaryTab’/> </StackPanel> </GroupBox>
How to load an XPS document into the DocumentViewer?
XPS documents can be easily loaded into the documentviewer. Here’s the code snippet. [XAML] <DocumentViewer Name=’documentViewer’ /> [C#] XpsDocument xpsDocument = new XpsDocument(‘sample.xps’, FileAccess.Read); documentViewer.Document = xpsDocument;
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);