2011-08-08 67 views
1

ビジュアルスタジオデザイナでカスタムWPFコントロールが表示されない(適切なスタイルが見つからないような)非常に奇妙な問題が発生していますが、スタイルが正しく表示されますStyleプロパティのPropertyグリッドの下にKey:Defaultが表示され、コンテンツとテキストを適切に設定してコントロールのスタイルが正しく表示されます。VS2010のデザイナでカスタムWPFコントロールが表示されない

私の質問はかなり明白ですが、私のコントロールがプロパティグリッドのスタイルを見つけることができれば、それはなぜデザイナーに正しく表示されませんか?

私のスタイルはThemes/Generic.xamlファイルで宣言されており、私のコントロールの静的コンストラクタにはDefaultStyleKeyProperty.OverrideMetadata(typeof(DragDockPanel), new FrameworkPropertyMetadata(typeof(DragDockPanel)));が呼び出されています。しかし、私はOnApplyTemplate()のオーバーライドされた機能がまったく呼び出されていないことに気付きました。ここで

がGeneric.xamlに位置私のスタイルです:

<Style TargetType="local:DragDockPanel"> 
     <Setter Property="Background" 
       Value="#ff000000" /> 
     <Setter Property="BorderBrush" 
       Value="#ff333333" /> 
     <Setter Property="BorderThickness" 
       Value="1" /> 
     <Setter Property="Template"> 
      <Setter.Value> 
       <ControlTemplate TargetType="local:DragDockPanel"> 
        <Grid> 
         <local:OuterGlowBorder OuterGlowOpacity="0.4" 
               OuterGlowSize="15" 
               CornerRadius="3,3,3,3" 
               Background="{TemplateBinding Background}" 
               BorderBrush="{TemplateBinding BorderBrush}" 
               BorderThickness="{TemplateBinding BorderThickness}"> 
          <local:InnerGlowBorder InnerGlowOpacity="1" 
                CornerRadius="3,3,3,3" 
                InnerGlowColor="#11ffffff" 
                InnerGlowSize="15,15,0,0" 
                Margin="0" 
                Padding="2" 
                ClipContent="True" 
                Background="Transparent" 
                BorderThickness="0"> 
           <Grid> 
            <Grid.RowDefinitions> 
             <RowDefinition Height="Auto" /> 
             <RowDefinition Height="*" /> 
            </Grid.RowDefinitions> 

            <ContentPresenter Grid.Row="1" 
                 Content="{TemplateBinding Content}" 
                 ContentTemplate="{TemplateBinding ContentTemplate}" /> 


            <Border Background="#7f000000" 
              Margin="-2" 
              Padding="3"> 
             <Grid> 
              <Border x:Name="GripBarElement" 
                CornerRadius="3,3,0,0" 
                Background="#00ffffff" 
                VerticalAlignment="Top" 
                MinHeight="30" 
                Cursor="Hand" 
                Margin="0,0,32,0" 
                IsHitTestVisible="{TemplateBinding DraggingEnabled}"> 
               <Grid> 
                <Rectangle Opacity="0.5"> 
                 <Rectangle.Fill> 
                  <LinearGradientBrush EndPoint="6.58300018310547,6.08300018310547" 
                       StartPoint="2.31500005722046,1.81500005722046" 
                       SpreadMethod="Repeat" 
                       MappingMode="Absolute"> 
                   <GradientStop Color="#FFAFAFAF" 
                       Offset="0" /> 
                   <GradientStop Color="#00FFFFFF" 
                       Offset="1" /> 
                   <GradientStop Color="#00FFFFFF" 
                       Offset="0.339" /> 
                  </LinearGradientBrush> 
                 </Rectangle.Fill> 
                </Rectangle> 
                <ContentPresenter Content="{TemplateBinding Header}" 
                     ContentTemplate="{TemplateBinding HeaderTemplate}" /> 

               </Grid> 
              </Border> 

              <ToggleButton x:Name="MaximizeToggleButton" 
                  VerticalAlignment="Top" 
                  HorizontalAlignment="Right" 
                  IsChecked="{Binding RelativeSource={RelativeSource TemplatedParent}, Mode=TwoWay, Path=IsMaximized}" 
                  Margin="0,5,5,0" 
                  Width="20" 
                  Height="20" 
                  Cursor="Hand"> 
               <ToggleButton.Template> 
                <ControlTemplate TargetType="ToggleButton"> 
                 <Border Background="#7F000000" 
                   CornerRadius="2,2,2,2"> 
                  <VisualStateManager.VisualStateGroups> 
                   <VisualStateGroup x:Name="FocusStates"> 
                    <VisualState x:Name="Focused" /> 
                    <VisualState x:Name="Unfocused" /> 
                   </VisualStateGroup> 
                   <VisualStateGroup x:Name="CommonStates"> 
                    <VisualState x:Name="Disabled" /> 
                    <VisualState x:Name="Normal" /> 
                    <VisualState x:Name="MouseOver"> 
                     <Storyboard> 
                      <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" 
                              Storyboard.TargetName="rectangle" 
                              Storyboard.TargetProperty="(UIElement.Opacity)"> 
                       <SplineDoubleKeyFrame KeyTime="00:00:00" 
                             Value="0.6" /> 
                       <SplineDoubleKeyFrame KeyTime="00:00:00.2000000" 
                             Value="0.3" /> 
                      </DoubleAnimationUsingKeyFrames> 
                     </Storyboard> 
                    </VisualState> 
                    <VisualState x:Name="Pressed"> 
                     <Storyboard> 
                      <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" 
                              Duration="00:00:00.0010000" 
                              Storyboard.TargetName="rectangle" 
                              Storyboard.TargetProperty="(UIElement.Opacity)"> 
                       <SplineDoubleKeyFrame KeyTime="00:00:00" 
                             Value="0.15" /> 
                      </DoubleAnimationUsingKeyFrames> 
                     </Storyboard> 
                    </VisualState> 
                   </VisualStateGroup> 
                   <VisualStateGroup x:Name="CheckStates"> 
                    <VisualState x:Name="Checked"> 
                     <Storyboard> 
                      <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" 
                              Duration="00:00:00.0010000" 
                              Storyboard.TargetName="checkedArrow" 
                              Storyboard.TargetProperty="(UIElement.Opacity)"> 
                       <SplineDoubleKeyFrame KeyTime="00:00:00" 
                             Value="1" /> 
                      </DoubleAnimationUsingKeyFrames> 
                      <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" 
                              Duration="00:00:00.0010000" 
                              Storyboard.TargetName="uncheckedArrow" 
                              Storyboard.TargetProperty="(UIElement.Opacity)"> 
                       <SplineDoubleKeyFrame KeyTime="00:00:00" 
                             Value="0" /> 
                      </DoubleAnimationUsingKeyFrames> 
                     </Storyboard> 
                    </VisualState> 
                    <VisualState x:Name="Unchecked"> 
                     <Storyboard /> 
                    </VisualState> 
                    <VisualState x:Name="Indeterminate" /> 
                   </VisualStateGroup> 
                  </VisualStateManager.VisualStateGroups> 
                  <Grid Height="Auto" 
                    Width="Auto"> 
                   <Border Margin="0,0,0,0" 
                     BorderBrush="#FFFFFFFF" 
                     BorderThickness="1,1,1,1" 
                     CornerRadius="1,1,1,1" 
                     Width="16" 
                     Height="16"> 
                    <Grid> 
                     <Path HorizontalAlignment="Right" 
                       Margin="0,1.24500000476837,1.70700001716614,5.375" 
                       x:Name="uncheckedArrow" 
                       VerticalAlignment="Stretch" 
                       Width="6.752" 
                       Stretch="Fill" 
                       Stroke="#FFFFFFFF" 
                       Data="M0.5,1.005 L6.2509999,1.005 M6.25,6.8800006 L6.25,0.5 M6.2520003,1.0880001 L0.50000024,6.8800001" /> 
                     <Path HorizontalAlignment="Stretch" 
                       Margin="1.45899999141693,5.74200010299683,5.78900003433228,0.878000020980835" 
                       x:Name="checkedArrow" 
                       VerticalAlignment="Stretch" 
                       Stretch="Fill" 
                       Stroke="#FFFFFFFF" 
                       Data="M0.5,1.005 L6.2509999,1.005 M6.25,6.8800006 L6.25,0.5 M6.2520003,1.0880001 L0.50000024,6.8800001" 
                       Opacity="0" 
                       RenderTransformOrigin="0.5,0.5"> 
                      <Path.RenderTransform> 
                       <TransformGroup> 
                        <ScaleTransform /> 
                        <SkewTransform /> 
                        <RotateTransform Angle="180" /> 
                        <TranslateTransform /> 
                       </TransformGroup> 
                      </Path.RenderTransform> 
                     </Path> 
                    </Grid> 
                   </Border> 
                   <Rectangle Fill="#FFFFFFFF" 
                      RadiusX="2" 
                      RadiusY="2" 
                      Margin="1,1,1,1" 
                      Opacity="0" 
                      x:Name="rectangle" /> 
                  </Grid> 
                 </Border> 
                </ControlTemplate> 
               </ToggleButton.Template> 
              </ToggleButton> 
             </Grid> 
            </Border> 



           </Grid> 
          </local:InnerGlowBorder> 
         </local:OuterGlowBorder> 

        </Grid> 
       </ControlTemplate> 
      </Setter.Value> 
     </Setter> 
     <Setter Property="HeaderTemplate"> 
      <Setter.Value> 
       <DataTemplate> 
        <local:DropShadowTextBlock Text="{Binding}" 
               FontFamily="Verdana" 
               FontSize="14" 
               VerticalAlignment="Center" 
               Margin="5" 
               DropShadowDistance="3" 
               DropShadowAngle="45" 
               Foreground="#ffffffff" /> 
       </DataTemplate> 
      </Setter.Value> 
     </Setter> 
    </Style> 

このコントロールは、他のカスタムを使用して、すべてのGeneric.xamlで宣言され、そのDefaultStyleKeyPropertyセットを持っているだけでなく制御します。あなたが私ができるこれらのカスタムコントロールのスタイルを投稿するようにしたい場合は、私はできるだけ早く私はそれらを残している。ここで

は私がコントロールを呼んでいる方法は次のとおりです。

<bl:DragDockPanelHost x:Name="dragDockPanelTest" 
            HorizontalAlignment="Stretch" 
            VerticalAlignment="Stretch" 
            Visibility="Visible" 
            Margin="0,0,0,0"> 
       <bl:DragDockPanel Name="Test1" 
            Header="TEST" 
            Content="WHERE AM I?" 
            HorizontalAlignment="Stretch" 
            VerticalAlignment="Stretch" 
            Visibility="Visible"> 
       </bl:DragDockPanel> 
      </bl:DragDockPanelHost> 

任意の助けをいただければ幸いです、私は、この時点でのアイデアから完全です。ありがとう!

編集:

はここに助けるかもしれないいくつかの詳細情報です。 DragDropPanelHostのスタイルをGeneric.xamlに追加しました。これは、キャンバスの背景色を変更するだけです。ただし、デザイナーのDragDropPanelHost(再コンパイル後など)では背景色が変更されません。

ここスタイルです:

<Style TargetType="local:DragDockPanelHost"> 
    <Setter Property="ItemsPanel"> 
     <Setter.Value> 
      <ItemsPanelTemplate> 
       <Canvas Background="BLUE"> 
       </Canvas> 
      </ItemsPanelTemplate> 
     </Setter.Value> 
    </Setter> 
</Style> 

何かは非常にここで台無しにされているようだ...スタイルがまったくロードされていないいくつかの理由で...ブライアン・Lagunas経由することで解決

答えて

0

質問MSDN:。

http://social.msdn.microsoft.com/Forums/pl-PL/wpf/thread/8e45f931-c6e3-4a70-91e5-39ef5c2a0b41?prof=required

は、「私はあなたがあなたのDragDockPanelHostのテンプレートを定義していなかった問題をすぐに見examplため、このにそれを変更します。 E:

<Style TargetType="local:DragDockPanelHost"> 
    <Setter Property="ItemsPanel"> 
     <Setter.Value> 
     <ItemsPanelTemplate> 
      <Canvas Background="AliceBlue"/> 
     </ItemsPanelTemplate> 
     </Setter.Value> 
    </Setter> 
    <Setter Property="Template"> 
     <Setter.Value> 
     <ControlTemplate TargetType="local:DragDockPanelHost"> 
      <ItemsPresenter /> 
     </ControlTemplate>   
     </Setter.Value> 
    </Setter> 
    </Style> 

関連する問題