Le réseau pour les développeurs >
Forums - Accueil
>
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- DéplacéRiquel_DongModérateurlundi 26 octobre 2009 08:39remove to right forum (From:Windows Communication Foundation)
- Modifiésuresh sm vendredi 23 octobre 2009 06:28
- Modifiésuresh sm vendredi 23 octobre 2009 06:34
Réponses
- 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.- Marqué comme réponseLinda LiuMSFT, Modérateurjeudi 12 novembre 2009 10:04
Toutes les réponses
- 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.- Marqué comme réponseLinda LiuMSFT, Modérateurjeudi 12 novembre 2009 10:04

