Wpf expander header template stretch




















To animate rotation of the arrow, we can use RenderTransform. RotateTransform to rotate the element over time. Since this is using RenderTransform , it will only affect how the element is drawn and not disturb the layout. To get the content to "stretch" out when expanded, we can use LayoutTransform. ScaleTransform and animate its ScaleY property. In this case, we use LayoutTransform instead of RenderTransform since we need the height layout of the control to change not just how the control is drawn rendered.

You can see the difference by replacing LayoutTransform with RenderTransform and experimenting with that. Animations are done through Triggers. In the code below, note the syntax for referencing the ScaleY property and declaring LayoutTransform under ContentPresenter :.

To get the content to "reveal" not sure what to call it is slightly more complicated than the above animations. Thus, a workaround was used instead below , and it is credited to Justin in this thread. In the initial collapsed state, Tag is set to 0 so that the ScrollViewer 's Height is set to 0. Below is the XAML for the "reveal" animation. Note the first line to declare the converter that was used. It must be in the same namespace as the code-behind. It simply multiplies all the values that was fed to it in MultiBinding.

Don't put too many controls inside the animated expanders. Learn more. WPF Expander. Header horizontal stretch Ask Question. Asked 6 years, 6 months ago. Active 2 years, 3 months ago.

Viewed 13k times. Stretching Content in an Expander Header — Bolu. Add a comment. Active Oldest Votes. Sinatr Sinatr This should be accepted answer, because this one does not suggest that you need to alter header template. I agree that this should be the accepted answer. But the binding should be defined on the Grid , not the TextBlock.

The alignment on the ContentPresenter is what helped me. Fixed that in my custom expander template et voila! Thanks Patrick. If you get a chance, please drop the XAML in a file and post a link to it. Curse of the angle brackets. Here it is again, assuming it treats HTML entities correctly:. Hey Patrick, thanks for the great idea!

After seeing your approach, I realized that it is easy to take it one more step and remove all the code. I think there is a problem with the XAML-only way. Try it with a button in the header and you will see that the right side of the button is cut off. That is because binding to the width of the control does not take into account the 25 pixels or so taken up by the toggle button in the header.

Yeah, that is true for a header which contains a Button. I was updating my sample, where the header content is just a simple TextBlock. In the case of using a Button, or any element with a border around it, I suppose you should use my original technique.

Since the indicator could be swapped out with a different element via templating, that approach is too brittle. If I remember correctly, the ToggleButton is in a Grid with two columns one for the ToggleButton, another for the header content. Actually, it is not hard-coded. It hard-codes a reasonable default 25 , but it also checks the parameter argument for an override.

This override could then be bound to the ActualWidth property of the relevant expansion control in the template. When the user click the button the expander opens completely…Any ideas???

For more information, see Create a template for a control. The Expander control does not have any named parts. The following table lists the visual states for the Expander control. The following example shows how to define a ControlTemplate for the Expander control.

For the complete sample, see Styling with ControlTemplates Sample. Skip to main content.



0コメント

  • 1000 / 1000