2011-08-08 3 views
1

Visual Studio 디자이너에서 사용자 지정 WPF 컨트롤을 볼 수없는 매우 이상한 문제가 발생합니다 (적절한 스타일을 찾을 수없는 것처럼)하지만 스타일이 올바르게 표시됩니다. 스타일 속성 아래의 속성 표 아래에 키 : 기본값이 표시되고 내용 및 텍스트가 올바르게 설정된 상태로 내 컨트롤의 그림이 올바르게 표시됩니다.디자이너에서 사용자 지정 WPF 컨트롤 VS2010을 볼 수 없습니다.

제 질문은 꽤 분명하지만 내 컨트롤이 속성 표에서 스타일을 찾을 수 있다면 디자이너에서 제대로 표시되지 않는 이유는 무엇입니까?

내 스타일이 Themes/Generic.xaml 파일에 선언되어 있고 DefaultStyleKeyProperty.OverrideMetadata(typeof(DragDockPanel), new FrameworkPropertyMetadata(typeof(DragDockPanel)));을 내 컨트롤의 정적 생성자에 호출하려고합니다. 그러나, 나는 OnApplyTemplate()의 무시 된 함수가 전혀 호출되지 않는다는 것을 알아 차렸다.

<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 설정되어 있습니다 :

여기 generic.xaml을에있는 내 스타일이다. 내가 할 수있는 이러한 사용자 지정 컨트롤에 대한 스타일을 게시하고 싶지만 간결하게하기 위해 나는 그들을 버렸습니다. 여기

내가 컨트롤을 호출하는거야 방법은 다음과 같습니다

어떤 도움을 크게 감상 할 수
<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> 

뭔가 매우 여기 엉망 보이는 스타일이 전혀로드되지 않는 몇 가지 이유 ...

답변

0

질문을 통해 브라이언 Lagunas 해결을 위해 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> 

"

관련 문제