Reputation: 19122
.I am creating a user control that stacks three WPF month calendars (Master, Slave1, and Slave2) vertically. I want the second and third calendars to be hidden until the host window is large enough to show the entire month--no partial calendars. I have implemented the feature be trapping the SizeChanged event in an event handler in code-behind:
/// <summary>
/// Shows only complete calendars--partially visible calendars are hidden.
/// </summary>
private void OnSizeChanged(object sender, SizeChangedEventArgs e)
{
// Increasing window height
var newHeight = e.NewSize.Height;
if (newHeight > 500)
{
SlaveCalendar1.Visibility = Visibility.Visible;
SlaveCalendar2.Visibility = Visibility.Visible;
}
else if (newHeight > 332)
{
SlaveCalendar1.Visibility = Visibility.Visible;
SlaveCalendar2.Visibility = Visibility.Hidden;
}
else
{
SlaveCalendar1.Visibility = Visibility.Hidden;
SlaveCalendar2.Visibility = Visibility.Hidden;
}
}
It works fine, but I would rather implement the feature in XAML, and I am not sure how to do it. Any suggestions? I'm not looking for someone else to write this for me--just point me in the right direction. Thanks for your help.
Upvotes: 0
Views: 222
Reputation: 3916
You should be able to do this with xaml templates and triggers. Probably event triggers for the OnSizeChanged event. I believe
Here are some resources to get you pointed in the right direction.
http://msdn.microsoft.com/en-us/library/cc294856%28Expression.30%29.aspx http://www.wpfdude.com/articles/Triggers.aspx http://www.geektieguy.com/2008/01/05/wpf-controltemplate-trigger-tip/
Upvotes: 1
Reputation: 32629
One idea is to create a new panel type, derived from Panel
(or maybe StackPanel
) which is called for example IntegralClippingPanel
. In that panel's overrides of MeasureOverride
and ArrangeOverride
make sure to only display child elements if they fit in their entirety inside the available space.
Upvotes: 1