How do I dynamically hide and unhide tabs in a TabControl ?
The TabItems have a Visibility property which can be set to Collapsed (no space will be reserved for this tab) or Hidden (not rendered, but space will be reserved for this tab). [XAML] <TabControl x:Name=’tabControl1′> <TabItem Header=’Tab1′></TabItem> <TabItem Header=’Tab2′ Visibility=’Hidden’></TabItem> <TabItem Header=’Tab3′ Visibility=’Collapsed’></TabItem> <TabItem Header=’Tab4′></TabItem> </TabControl>
Can I delay the display of a ToolTip ?
You can set a ‘ToolTipService’ property that causes a brief delay before a ToolTip displays. You set the properties of the ‘ToolTipService’ class by attaching them directly to the element that exposes the tooltip. [XAML] <TextBox HorizontalAlignment=’Left’ ToolTipService.InitialShowDelay=’1500′ ToolTip=’Useful information goes here.’> ToolTip with delay </TextBox>
How do I embed a Button into a TextBox?
This is very easy to do in XAML, as follows: [XAML] <TextBlock x:Name=’myTextBlock’ Width=’100′ Height=’40’> <Button>Test</Button> </TextBlock> And you can do something similar in C# as follows: [C#] Button btn = new Button(); btn.Content = ‘Test’; this.myTextBlock.Inlines.Add(btn);
How do I customize the style of a tooltip that gets shown ONLY on the CheckBoxes in my Window?
Nest the tooltip’s style within the checkbox’s style as follows: <Window.Resources> <Style TargetType=’CheckBox’> <Style.Resources> <Style TargetType=’ToolTip’> <Setter Property=’Background’ Value=’Red’/> </Style> </Style.Resources> <Setter Property=’FontSize’ Value=’14’/> </Style> </Window.Resources> <Grid> <CheckBox ToolTip=’Sample ToolTip!’>Sample CheckBox</CheckBox> </Grid>
How do I bind my tree to a hierarchical list?
Let us say you have a hierarchical list like this: – Division1 | |— Department1 | |— Room1 | |— Room2 |— Department2 | |— Room3 | |— Room4 – Division2 (……) With corresponding types like this: [C#] public class Division { public string Name{…} public DepartmentsCollection Departments{…} } public class Department { public string Name{…} public RoomsCollection Rooms{…} } public class Room { public string Name{….} } You could then bind a collection of Divisions to a tree to achieve the above look and feel by defining a HierarchicalDataTemplate for Division and Department and a DataTemplate for Room types, as follows: [XAML] <HierarchicalDataTemplate DataType='{x:Type src:Division}’ ItemsSource='{Binding Path=Departments}’> <TextBlock Text='{Binding Path=Name}’/> </HierarchicalDataTemplate> <HierarchicalDataTemplate DataType='{x:Type src:Department}’ ItemsSource='{Binding Path=Rooms}’> <TextBlock Text='{Binding Path=Name}’/> </HierarchicalDataTemplate> <DataTemplate DataType='{x:Type src:Room}’> <TextBlock Text='{Binding Path=Name}’/> </DataTemplate> You can then bind the TreeView to a collection of Divisions. [XAML] <!–myDivisonsCollection could be an ObjectDataSource returning the list of Divisions collection –!> <TreeView ItemsSource='{Binding Source={StaticResource myDivisionsCollection}}’></TreeView>