2012-12-21 123 views
0

我有一個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> 

+0

問題是「如何」修復模板問題。在上面的示例中,yes'DesignerItemStyle'沒有加載。 – Nasenbaer

回答

1

嘗試重新排序dictioneries &模板,看看它的工作原理,

其全部關於,因爲最後的字典總是覆蓋他的以前的字典(模板)有時即使你不針對相同的UIElement!

+1

如果在將所有XAML內容合併到一個單獨的Dictionary文件中時找到解決方案。問題似乎是加載模板和樣式的順序。首先需要加載模板並在樣式之後。也許你想更新你的答案。謝謝你的幫助。 – Nasenbaer

+0

不錯的觀察,我會更新我的答案 – S3ddi9