ContentControl 及其子项 - 大小相同?

发布于 2024-11-04 01:49:08 字数 3589 浏览 0 评论 0原文

我想这是一个非常简单(读作:非常简单)的问题,但我已经花了相当长的时间来弄清楚。

我有一个类PresentationItem,它派生自ContentControl。我正在使用Expression Blend,这会导致PresentationItem 的高度和宽度出现问题。

当我插入PresentationItem时,它会自动调整太满的网格(800x600)。然后,当我插入例如文本块时,文本块的大小会变小。我认为这是正常且预期的行为。

我想要的是演示项目和内容子项(例如,文本块)具有相同的大小。当我有好几个这样的尺寸时,使用两种不同的尺寸是很烦人的。因此,要么应拉伸演示文稿项内的内容,要么应调整演示文稿项的大小以适合其子项。

(此外,不能选择使用 ContentControl 以外的其他内容)。

现在我有以下风格:

 <Style TargetType="local:JSLDPresentationItem">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="local:JSLDPresentationItem">
                <Border Background="{TemplateBinding Background}"
                        BorderBrush="{TemplateBinding BorderBrush}"
                        BorderThickness="{TemplateBinding BorderThickness}">
                    <VisualStateManager.VisualStateGroups>
                        <VisualStateGroup x:Name="PresentationStates">
                            <VisualStateGroup.Transitions>
                                <VisualTransition GeneratedDuration="0:0:0.3"/>
                            </VisualStateGroup.Transitions>
                            <VisualState x:Name="FocusedPresenting">
                                <Storyboard>
                                    <DoubleAnimation  Duration="0" To="1.2" Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.ScaleX)" Storyboard.TargetName="LocalLayoutPanel" />
                                    <DoubleAnimation Duration="0" To="1.2" Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.ScaleY)" Storyboard.TargetName="LocalLayoutPanel" />
                                </Storyboard>
                            </VisualState>
                            <VisualState x:Name="AfterPresenting">
                                <Storyboard>
                                    <DoubleAnimation Duration="0" To="0" Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="LocalLayoutPanel" />
                                </Storyboard>
                            </VisualState>
                            <VisualState x:Name="BeforePresenting">
                                <Storyboard>
                                    <DoubleAnimation Duration="0" To="0" Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="LocalLayoutPanel" />
                                </Storyboard>
                            </VisualState>
                            <VisualState x:Name="UnfocusedPresenting"/>
                        </VisualStateGroup>
                    </VisualStateManager.VisualStateGroups>

                    <Grid x:Name="LocalLayoutPanel" Margin="0,0,0,0" VerticalAlignment="Top"   >

                        <Grid.RenderTransform>
                            <CompositeTransform/>
                        </Grid.RenderTransform>
                        <ContentPresenter x:Name="contentPresenter" ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" />
                    </Grid>
                </Border>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

要改变什么以及在哪里?我猜这是一些“*”或“auto”在正确的位置!

I guess this is a quite simple (read: very simple) question, but I have been using quite some time to figure it out.

I have a class, PresentationItem, which is derived from ContentControl. I am working in Expression Blend, which gives a problem with the height and width of the PresentationItem.

When I insert a PresentationItem, it automatically sizes too full grid (800x600). Then, when I insert for instance a textblock, the textblock sizes to something small. I think this is the normal and expected behaviour.

What I want, is the presentationitem and Content child (for instance, a textblock) has the same size. It is annoying to work with 2 different sizes when I have several of these. So either the content inside the presentationitem should be stretched, or the presentationitem should resize to fit its children.

(Also, using something else than a ContentControl is not an option).

Right now I have the following style:

 <Style TargetType="local:JSLDPresentationItem">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="local:JSLDPresentationItem">
                <Border Background="{TemplateBinding Background}"
                        BorderBrush="{TemplateBinding BorderBrush}"
                        BorderThickness="{TemplateBinding BorderThickness}">
                    <VisualStateManager.VisualStateGroups>
                        <VisualStateGroup x:Name="PresentationStates">
                            <VisualStateGroup.Transitions>
                                <VisualTransition GeneratedDuration="0:0:0.3"/>
                            </VisualStateGroup.Transitions>
                            <VisualState x:Name="FocusedPresenting">
                                <Storyboard>
                                    <DoubleAnimation  Duration="0" To="1.2" Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.ScaleX)" Storyboard.TargetName="LocalLayoutPanel" />
                                    <DoubleAnimation Duration="0" To="1.2" Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.ScaleY)" Storyboard.TargetName="LocalLayoutPanel" />
                                </Storyboard>
                            </VisualState>
                            <VisualState x:Name="AfterPresenting">
                                <Storyboard>
                                    <DoubleAnimation Duration="0" To="0" Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="LocalLayoutPanel" />
                                </Storyboard>
                            </VisualState>
                            <VisualState x:Name="BeforePresenting">
                                <Storyboard>
                                    <DoubleAnimation Duration="0" To="0" Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="LocalLayoutPanel" />
                                </Storyboard>
                            </VisualState>
                            <VisualState x:Name="UnfocusedPresenting"/>
                        </VisualStateGroup>
                    </VisualStateManager.VisualStateGroups>

                    <Grid x:Name="LocalLayoutPanel" Margin="0,0,0,0" VerticalAlignment="Top"   >

                        <Grid.RenderTransform>
                            <CompositeTransform/>
                        </Grid.RenderTransform>
                        <ContentPresenter x:Name="contentPresenter" ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" />
                    </Grid>
                </Border>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

What to change and where? I guess it is some "*" or "auto" at the right place!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

风吹雪碎 2024-11-11 01:49:08

尝试将派生控件的 Horizo​​ntalContentAlignment 和 VerticalContentAlignment 设置为 Stretch。

Try setting the HorizontalContentAlignment and VerticalContentAlignment of your derived control to Stretch.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文