【问题标题】:Template is not loading模板未加载
【发布时间】:2012-12-21 17:05:59
【问题描述】:

我有一个 WPF 模板,但在启动应用程序时它没有显示。 WPF 中没有错误,任何地方都没有。只是没有使用模板。如何找出问题所在?

<ResourceDictionary.MergedDictionaries>
    <ResourceDictionary Source="MoveThumb.xaml"/>
    <ResourceDictionary Source="ResizeDecorator.xaml"/>
    <ResourceDictionary Source="RotateDecorator.xaml"/>
</ResourceDictionary.MergedDictionaries>

<!-- ContentControl style to move, resize and rotate items -->
<Style x:Key="DesignerItemStyle" TargetType="ContentControl">
    <Setter Property="MinHeight" Value="50"/>
    <Setter Property="MinWidth" Value="50"/>
    <Setter Property="RenderTransformOrigin" Value="0.5,0.5"/>
    <Setter Property="SnapsToDevicePixels" Value="true"/>
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="ContentControl">
                <Grid DataContext="{Binding RelativeSource={RelativeSource TemplatedParent}}">
                    <Control Name="RotateDecorator"
                 Template="{StaticResource RotateDecoratorTemplate}"
                 Visibility="Collapsed"/>
                    <s:MoveThumb Template="{StaticResource MoveThumbTemplate}"
                     Cursor="SizeAll"/>
                    <Control x:Name="ResizeDecorator"
                 Template="{StaticResource ResizeDecoratorTemplate}"
                 Visibility="Collapsed"/>
                    <ContentPresenter Content="{TemplateBinding ContentControl.Content}"/>
                </Grid>
                <ControlTemplate.Triggers>
                    <Trigger Property="Selector.IsSelected" Value="True">
                        <Setter TargetName="ResizeDecorator" Property="Visibility" Value="Visible"/>
                        <Setter TargetName="RotateDecorator" Property="Visibility" Value="Visible"/>
                    </Trigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

<!-- RotateDecorator Template -->
<ControlTemplate x:Key="RotateDecoratorTemplate" TargetType="Control">
    <Grid>
        <my:RotateThumb Margin="-18,-18,0,0" VerticalAlignment="Top" HorizontalAlignment="Left"/>
        <my:RotateThumb Margin="0,-18,-18,0" VerticalAlignment="Top" HorizontalAlignment="Right">
            <my:RotateThumb.RenderTransform>
                <RotateTransform Angle="90" />
            </my:RotateThumb.RenderTransform>
        </my:RotateThumb>
        <my:RotateThumb Margin="0,0,-18,-18" VerticalAlignment="Bottom" HorizontalAlignment="Right">
            <my:RotateThumb.RenderTransform>
                <RotateTransform Angle="180" />
            </my:RotateThumb.RenderTransform>
        </my:RotateThumb>
        <my:RotateThumb Margin="-18,0,0,-18" VerticalAlignment="Bottom" HorizontalAlignment="Left">
            <my:RotateThumb.RenderTransform>
                <RotateTransform Angle="270" />
            </my:RotateThumb.RenderTransform>
        </my:RotateThumb>
    </Grid>
</ControlTemplate>

【问题讨论】:

  • 问题是“如何”修复模板问题。在上面的示例中,是的 DesignerItemStyle 没有加载。

标签: wpf xaml templates styles


【解决方案1】:

尝试重新排序字典和模板,看看它是否有效,

这都是关于 ORDER 的,因为有时即使您没有针对相同的 UIElement,最后一个字典总是覆盖他以前的字典(模板)!

【讨论】:

  • 如果在将所有 XAML 内容合并到一个字典文件时找到了解决方案。问题似乎是加载模板和样式的顺序。首先需要加载模板和样式之后。也许你想更新你的答案。感谢您的帮助。
猜你喜欢
  • 2015-11-11
  • 1970-01-01
  • 1970-01-01
  • 2022-12-19
  • 2018-05-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-18
相关资源
最近更新 更多