.NET Framework Developer Center >
.NET Development Forums
>
Windows Presentation Foundation (WPF)
>
WPF ContentControl in InkCanvas
WPF ContentControl in InkCanvas
I want to adjust(Max/min) the player size at run time. Using Inkcanvas able to adjust the MediaElement but unable to adjust the ContentControl. Curently displaying the video through the ContentControl and unable to resize using the InkCanvas, video is playing but not able visible... can you please help.
Expected:
1. Need to adjust the size of Contentcontrol at runtime using InkCanvas or any.
suresh sm- Moved byRiquel_DongModeratorMonday, October 26, 2009 8:39 AMremove to right forum (From:Windows Communication Foundation)
- Edited bysuresh sm Friday, October 23, 2009 6:28 AM
- Edited bysuresh sm Friday, October 23, 2009 6:34 AM
Answers
- Hi Sursh,
A ContentControl has a limited default style. The default ControlTemplate of the ContentControl contains nothing but the ContentPresenter, i.e. nothing but the content contained in the ContentControl will rendered. So setting the Height or Width property on the ContentControl makes no difference from the view of visual.
The solution is to create a new ControlTemplate for the ContentControl to add an UIElement in the ControlTemplate, binding the Width and Height property of the UIElement to the Width and Height property of the ContentControl. The following is a sample:
<Style TargetType="{x:Type ContentControl}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ContentControl}">
<Grid>
<Border Width="{TemplateBinding Width}" Height="{TemplateBinding Width}" Background="{TemplateBinding Background}"/>
<ContentPresenter VerticalAlignment="Center" HorizontalAlignment="Center"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Put this XAML segment in the Resources section of the Window or application, so this style will be applied to all ContentControl in the Window or application.
Hope this helps.
Sincerely,
Linda Liu
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.- Marked As Answer byLinda LiuMSFT, ModeratorThursday, November 12, 2009 10:04 AM
All Replies
- Please move this thread to the WPF forum (http://social.msdn.microsoft.com/Forums/en-US/wpf/threads), as this is a Windows Presentation (not Communication) Foundation issue.
- Hi Sursh,
A ContentControl has a limited default style. The default ControlTemplate of the ContentControl contains nothing but the ContentPresenter, i.e. nothing but the content contained in the ContentControl will rendered. So setting the Height or Width property on the ContentControl makes no difference from the view of visual.
The solution is to create a new ControlTemplate for the ContentControl to add an UIElement in the ControlTemplate, binding the Width and Height property of the UIElement to the Width and Height property of the ContentControl. The following is a sample:
<Style TargetType="{x:Type ContentControl}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ContentControl}">
<Grid>
<Border Width="{TemplateBinding Width}" Height="{TemplateBinding Width}" Background="{TemplateBinding Background}"/>
<ContentPresenter VerticalAlignment="Center" HorizontalAlignment="Center"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Put this XAML segment in the Resources section of the Window or application, so this style will be applied to all ContentControl in the Window or application.
Hope this helps.
Sincerely,
Linda Liu
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.- Marked As Answer byLinda LiuMSFT, ModeratorThursday, November 12, 2009 10:04 AM


