How do I bind a flat table/list containing self-referencing data to a TreeView to render it in a hierarchical view?
The following article illustrates how you can first shape a flat table or list into a hierarchical list and then bind the resultant hierachy to the tree: .NET – LINQ AsHierarchy() extension method
How do I listen to text changed events in a ComboBox in editable mode?
Unfortunately, the first version of WPF does not provide a TextChanged event for a ComboBox like the one available for a TextBox. So, a workaround like the following is required: [C#] public Window1() { InitializeComponent(); this.comboBox.Loaded += delegate { TextBox editTextBox = comboBox.Template.FindName('PART_EditableTextBox', comboBox) as TextBox; if (editTextBox != null) { editTextBox.TextChanged += delegate { MessageBox.Show(comboBox.Text); }; } }; }
How do I dynamically hide/unhide tabs in a TabControl?
You can dynamically remove and inseret TabPages into the TabControl.TabPages collection to hide and show tabs at runtime. TabPage tabPageSave = null; private void button1_Click(object sender, EventArgs e) { //hide a tab by removing it from the TabPages collection this.tabPageSave = tabControl1.SelectedTab; this.tabControl1.TabPages.Remove(this.tabPageSave); } private void button2_Click(object sender, EventArgs e) { //show a tab by adding it to the TabPages collection if (this.tabPageSave != null) { int loc = tabControl1.SelectedIndex; this.tabControl1.TabPages.Insert(loc, this.tabPageSave); } }
At the end of animation, how do I cause the value of a property to revert back to it’s original value?
By default, the value of the property on which the animation is applied is overwritten to the ’To’ value of the animation at the end of the animation. But, instead you can reset the property’s value to it’s original value by setting the ‘FillBehavior’ property of the animation to ‘Stop’ (by default it’s set to the HoldEnd enum).
How do I control a Storyboard animation once it starts?
In code behind: The following article from MSDN describes how to Pause, Resume, Stop, etc. on a running animation: http://msdn.microsoft.com/en-us/library/ms741997.aspx In XAML: The following example uses controllable storyboard actions to interactively control a storyboard. [XAML] <Page xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' WindowTitle='Controlling a Storyboard' > <StackPanel Margin='20' > <!-- This rectangle is animated. --> <Rectangle Name='myRectangle' Width='100' Height='20' Margin='12,0,0,5' Fill='#AA3333FF' HorizontalAlignment='Left' /> <!-- This StackPanel contains all the Buttons. --> <StackPanel Orientation='Horizontal' Margin='0,30,0,0'> <Button Name='BeginButton'>Begin</Button> <Button Name='PauseButton'>Pause</Button> <Button Name='ResumeButton'>Resume</Button> <Button Name='SeekButton'>Seek</Button> <Button Name='SkipToFillButton'>Skip To Fill</Button> <Button Name='SetSpeedRatioButton'>Triple Speed</Button> <Button Name='StopButton'>Stop</Button> <StackPanel.Triggers> <!-- Begin the Storyboard --> <EventTrigger RoutedEvent='Button.Click' SourceName='BeginButton'> <BeginStoryboard Name='MyBeginStoryboard'> <Storyboard > <DoubleAnimation Storyboard.TargetName='myRectangle' Storyboard.TargetProperty='Width' Duration='0:0:5' From='100' To='500' /> </Storyboard> </BeginStoryboard> </EventTrigger> <!-- Pause the Storyboard --> <EventTrigger RoutedEvent='Button.Click' SourceName='PauseButton'> <PauseStoryboard BeginStoryboardName='MyBeginStoryboard' /> </EventTrigger> <!-- Resume the Storyboard --> <EventTrigger RoutedEvent='Button.Click' SourceName='ResumeButton'> <ResumeStoryboard BeginStoryboardName='MyBeginStoryboard' /> </EventTrigger> <!-- Seek one second into the storyboard’s active period. --> <EventTrigger RoutedEvent='Button.Click' SourceName='SeekButton'> <SeekStoryboard BeginStoryboardName='MyBeginStoryboard' Offset='0:0:1' Origin='BeginTime' /> </EventTrigger> <!-- Skip to Fill --> <EventTrigger RoutedEvent='Button.Click' SourceName='SkipToFillButton'> <SkipStoryboardToFill BeginStoryboardName='MyBeginStoryboard' /> </EventTrigger> <!-- Stop the Storyboard --> <EventTrigger RoutedEvent='Button.Click' SourceName='StopButton'> <StopStoryboard BeginStoryboardName='MyBeginStoryboard' /> </EventTrigger> <!-- Triple the speed of the Storyboard --> <EventTrigger RoutedEvent='Button.Click' SourceName='SetSpeedRatioButton'> <SetStoryboardSpeedRatio SpeedRatio='3' BeginStoryboardName='MyBeginStoryboard' /> </EventTrigger> </StackPanel.Triggers> </StackPanel> </StackPanel> </Page>