I have just received the link to join the Office 365 beta program… Sadly (again) I don’t have the time to test it properly today, but I will on Tuesday hopefully.
I’ll keep you posted.
A lot of licenses to assign, a lot of software to try…
Spells, invocations, alchemy and code... well just code actually.
I have just received the link to join the Office 365 beta program… Sadly (again) I don’t have the time to test it properly today, but I will on Tuesday hopefully.
I’ll keep you posted.
A lot of licenses to assign, a lot of software to try…
<Grid x:Name="LayoutRoot">
<Border VerticalAlignment="Top" BorderBrush="#FF929EB0" BorderThickness="1" CornerRadius="2" Background="#FFE9E9E9" Margin="5,2">
<Grid d:LayoutOverrides="Width">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" MinHeight="20"/>
<RowDefinition Height="Auto" MinHeight="5"/>
</Grid.RowDefinitions>
<TextBlock x:Name="Header" TextWrapping="Wrap" d:LayoutOverrides="Width" Foreground="#FF656565" Margin="15,2,0,0" VerticalAlignment="Top"/>
<StackPanel x:Name="ChildrenPanel" VerticalAlignment="Top" d:LayoutOverrides="Width" Margin="0,2,0,0" Grid.Row="1"/>
</Grid>
</Border>
</Grid>The trick is adding a TextBlock in the header of the "expander" and subscribe to the MouseLeftButtonUp event of the TextBlock to control the folding and unfolding. I have also added a Folded property so I can externally set up the status of the expander. public partial class Expander : UserControl
{
bool _Folded;
public bool Folded
{
get { return _Folded; }
set
{
_Folded = !value;
ExpanderSwitch();
}
}
List ChildrenList;
public Expander()
{
// Required to initialize variables
InitializeComponent();
ChildrenList = new List();
Header.MouseLeftButtonUp += new System.Windows.Input.MouseButtonEventHandler(UserActivity_MouseLeftButtonUp);
}
void UserActivity_MouseLeftButtonUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
ExpanderSwitch();
}
private void ExpanderSwitch()
{
if (Folded)
{
foreach (var child in ChildrenList)
ChildrenPanel.Children.Add(child);
}
else
{
if (ChildrenList.Count == 0)
foreach (var item in ChildrenPanel.Children)
ChildrenList.Add(item);
while (ChildrenPanel.Children.Count > 0)
ChildrenPanel.Children.RemoveAt(0);
}
_Folded = !_Folded;
}
} And to use it you just have to add the control:<Grid x:Name="LayoutRoot">
<this:Expander x:Name="UserNews" />
</Grid>In code behind you can do something like this: UserNews.Header.Text = GetHeader(News[0]);
foreach (FrameworkNews news in News)
UserNews.ChildrenPanel.Children.Add(new NewsDetail(news.Link, GetDetail(news), news.Where));
UserNews.Folded = true;If you have time you can add images and animations to the expander as well as a better "Folding Control"… Sadly I can't spend more time working on it, even though I'd love to :(
No comments:
Post a Comment