How can I extend the style of a DocumentViewer ?

The following style uses the ‘BasedOn’ attribute to extend the default DocumentViewer style. [XAML] <Window x:Class='SDKSample.Window1' xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'> <Window.Resources> <Style x:Key='MyDVStyleExtend' BasedOn='{StaticResource {x:Type DocumentViewer}}' TargetType='{x:Type DocumentViewer}'> <Setter Property='Background'> <Setter.Value> <LinearGradientBrush StartPoint='0.5,0' EndPoint='0.5,1'> <GradientStop Offset='0.0' Color='#CC99CCFF' /> <GradientStop Offset='1.0' Color='White' /> </LinearGradientBrush> </Setter.Value> </Setter> </Style> </Window.Resources> <Grid> <DocumentViewer Style='{StaticResource MyDVStyleExtend}' Name='MyDocumentViewer'/> </Grid> </Window>

How can I enable a Context Menu on a disabled Control ?

This example uses the ContextMenuService.ShowOnDisabled property to show the context menu for a disabled button. [XAML] <Button Height='30' Content='Disabled Button' IsEnabled='False' ContextMenuService.ShowOnDisabled='True'> <Button.ContextMenu> <ContextMenu> <MenuItem Header='Item 1'/> <MenuItem Header='Item 2'/> <MenuItem Header='Item 3'/> </ContextMenu> </Button.ContextMenu> </Button>

How can I add a style to a TabItem that is used in the TabControl ?

Here is a custom style that changes the look and feel of the tabs (TabItems) in the corresponding window. [XAML] <Style TargetType='TabItem'> <Setter Property='BorderThickness' Value='3'/> <Setter Property='BorderBrush' Value='Red'/> <Setter Property='Background' Value='LightBlue'/> <Setter Property='VerticalContentAlignment' Value='Center'/> <Setter Property='HorizontalContentAlignment' Value='Center'/> <Setter Property='Template'> <Setter.Value> <ControlTemplate TargetType='{x:Type TabItem}'> <Border> <Grid> <Grid> <Border CornerRadius='3,3,0,0' Background='{TemplateBinding Background}' BorderBrush='{TemplateBinding BorderBrush}' BorderThickness='{TemplateBinding BorderThickness}'/> </Grid> <Border BorderThickness='{TemplateBinding BorderThickness}' Padding='{TemplateBinding Padding}'> <ContentPresenter ContentSource='Header' HorizontalAlignment='{TemplateBinding HorizontalContentAlignment}' VerticalAlignment='{TemplateBinding VerticalContentAlignment}'/> </Border> </Grid> </Border> </ControlTemplate> </Setter.Value> </Setter> </Style> This is how the tabs look with the above style applied on them:

How do I validate the current tab before selection changes to another tab on user click?

Unfortunately, WPF doesn’t provide a straight forward way of validating a tab page’s content before switching to a new tab, in the first version. One workaround is to listen to the TabItem’s PreviewLostKeyboardFocus event and mark it as Handled as shown below. [C#] public TabValidation() { InitializeComponent(); foreach (TabItem item in tabControl1.Items) { item.PreviewLostKeyboardFocus += new KeyboardFocusChangedEventHandler(item_PreviewLostKeyboardFocus); } } void item_PreviewLostKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e) { // sender is the TabItem. if (this.ValidateTab() == false) e.Handled = true; }