C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
Note: I modified the "Header" attribute of the Expander element. The Expander here shows a description when it is clicked.
IsExpanded: I modified the IsExpanded attribute to be false. This means when the program is started, the description is not visible.
TextBlock: On the TextBlock, I modified the "Text" property and the "Margin" property—these are not important.
Example markup: XAML
<Window x:Class="WpfApplication17.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Expander Header="Description"
HorizontalAlignment="Left"
Margin="10,10,0,0"
VerticalAlignment="Top"
IsExpanded="False"
Height="299"
Width="497">
<TextBlock TextWrapping="Wrap"
Text="This is some text content."
Margin="5"/>
</Expander>
</Grid>
</Window>
Here: In the screenshot, I used an ExpandDirection of Right. The TextBlock appears to the right after the arrow is clicked.
Then: We assign the Window Title to the value of the Header attribute on the Expander element.
Collapsed: In this event handler, we set the Window Title to "Collapsed." I never said this program was useful.
Example markup 2: XAML
<Expander Header="Description"
HorizontalAlignment="Left"
Margin="10,10,0,0"
VerticalAlignment="Top"
IsExpanded="False"
ExpandDirection="Right"
Expanded="Expander_Expanded"
Collapsed="Expander_Collapsed"
Height="299"
Width="497">
Example code 2: C#
using System.Windows;
using System.Windows.Controls;
namespace WpfApplication17
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void Expander_Expanded(object sender, RoutedEventArgs e)
{
// ... Set Window Title to Expander Header value.
var expander = sender as Expander;
this.Title = expander.Header.ToString();
}
private void Expander_Collapsed(object sender, RoutedEventArgs e)
{
// ... Change Window Title.
this.Title = "Collapsed";
}
}
}