这是我在这里的第一次干预 . 我很抱歉我的英语很差,我希望我能说清楚 .

我正在制作一个自定义控件 . (我是wpf的初学者)他的目标取决于属性“类型控制” . 它可以是显示数据的简单文本块(并根据级别属性更改背景颜色),它可以是字幕文本或可以是图片 . 此处的目标是进行动态控制 . 我解释了这一点,但我真正的麻烦是他的选择部分 .

这是我的XAML代码:

<ControlTemplate TargetType="{x:Type local:ControlPerso}">
                <Border Background="{TemplateBinding Background}"
                        BorderBrush="{TemplateBinding BorderBrush}"
                        BorderThickness="{TemplateBinding BorderThickness}" x:Name="PART_BORDER" VerticalAlignment="Stretch" CornerRadius="10" Height="Auto">

                    <Viewbox Margin="2" StretchDirection="DownOnly" x:Name="PART_VB" Stretch="Fill">
                        <Grid x:Name="PART_GRID"  ShowGridLines="false" VerticalAlignment="Center" Height="Auto"  >
                            <Grid.RowDefinitions>
                                <RowDefinition x:Name="PART_ROWLABEL"></RowDefinition>
                                <RowDefinition x:Name="PART_ROWSCROLL"></RowDefinition>
                                <RowDefinition x:Name="PART_ROWIMAGE"></RowDefinition>
                            </Grid.RowDefinitions>


                            <Grid Grid.Row="0" x:Name="RowLabel" VerticalAlignment="Center">
                                <TextBlock  x:Name="PART_LABEL" Text="{Binding MyText, RelativeSource='{RelativeSource Mode=TemplatedParent}', UpdateSourceTrigger=PropertyChanged}" Background="Transparent"
                           FontFamily="Verdana" FontSize="{Binding FontSize, RelativeSource='{RelativeSource Mode=TemplatedParent}'}"  FontWeight="ExtraBold" HorizontalAlignment="Center">
                                    <TextBlock.BitmapEffect>
                                        <DropShadowBitmapEffect Color="Black" Direction="320" ShadowDepth="2" Opacity=".9" Softness="0.3" />
                                    </TextBlock.BitmapEffect>
                                </TextBlock>
                            </Grid>

                            <Grid Grid.Row="1"  x:Name="RowScroll" VerticalAlignment="Center">

                                <Canvas x:Name="PART_ContentControl" ClipToBounds="True" 
                                    HorizontalAlignment="Stretch" 
                                    VerticalAlignment="Stretch" 
                                    Height="{Binding ActualHeight, RelativeSource={RelativeSource Mode=TemplatedParent}}"
                                    Width="{Binding ActualWidth, RelativeSource={RelativeSource Mode=TemplatedParent}}" >

                                    <Canvas.Triggers>
                                        <EventTrigger RoutedEvent="Canvas.Loaded">
                                            <BeginStoryboard>
                                                <Storyboard x:Name="ContentTickerStoryboard" Storyboard.TargetProperty="(Canvas.Left)">
                                                    <DoubleAnimation Storyboard.TargetName="PART_Content" RepeatBehavior="Forever" />
                                                </Storyboard>
                                            </BeginStoryboard>
                                        </EventTrigger>
                                    </Canvas.Triggers>

                                    <ContentPresenter x:Name="PART_Content"                                                       
                                                  HorizontalAlignment="{TemplateBinding ContentControl.HorizontalAlignment}" 
                                                  VerticalAlignment="{TemplateBinding ContentControl.VerticalAlignment}"
                                                  Content="{Binding MyText, RelativeSource={RelativeSource Mode=TemplatedParent}, UpdateSourceTrigger=PropertyChanged}"
                                                  ContentTemplate="{TemplateBinding ContentControl.ContentTemplate}" TextBlock.FontSize="{Binding FontSize, RelativeSource='{RelativeSource Mode=TemplatedParent}'}">
                                        <ContentPresenter.BitmapEffect>
                                            <DropShadowBitmapEffect Color="Black" Direction="320" ShadowDepth="2" Opacity=".9" Softness="0.3" />
                                        </ContentPresenter.BitmapEffect>
                                    </ContentPresenter>
                                </Canvas>


                            </Grid>

                            <Grid Grid.Row="2" x:Name="RowImg"  ShowGridLines="False" VerticalAlignment="Center" Height="Auto">
                                <Image Source="C:\Users\Zebody\Pictures\thk.jpg"/>
                            </Grid>
                        </Grid>
                    </Viewbox>


                </Border>
            </ControlTemplate>

我的麻烦:Viewbox适用于网格行的图片和网格的行“标签”(完全调整字体大小) . 但它不适用于rowscroll(选框部分) . 字体永远不会调整大小 . 看来这是因为画布 . 如果我删除高度和宽度,调整大小工作,但画布不填充我的自定义控件 .

我要做什么:画布填充我的所有自定义控件,并可以在我调整自定义控件(在主窗口中)时调整字体大小 .

任何人都可以帮我怎么办?

先谢谢你,再次为我糟糕的英语道歉