2012-01-25 6 views
1

콤보 상자에서 상속하는 사용자 지정 WPF 컨트롤을 만들고 싶습니다. 지금까지는 프로젝트를 만들고 Control에서 ComboBox 로의 상속을 원하는대로 변경했습니다. Generic.xaml로 가서 시각적 업데이트를 시도하고 템플릿을 기본 콤보 상자의 복사본으로 변경했습니다. (Blend를 사용하여 템플릿 사본을 만들고 복사했습니다.) 이것은 충돌이 시작되는 곳입니다.WPF에서 사용자 지정 콤보 상자 만들기

지금은 오류가 발생했습니다. '제어'유형의 정적 멤버 'MaxDropDownHeightProperty'를 찾을 수 없습니다.

오류가있는 위치를 나타내는 그루브 선은 표시되지 않지만 그 위치는 어디인지 생각할 수 있습니다.

나는이 템플릿이 여전히 '컨트롤'유형의 템플릿이라고 생각하지만 ComboBox로 변경하는 방법을 알고 있다고 생각합니다.

감사합니다,

편집 : 나는 정확히 같은를 사용하기 위하여려고하는 경우 combox 상자의 템플릿을 복사하는 것은 정말 유용되지 않는다는 것을 충분히 알고 있지만, 사실은 내가 evenually을 변경하려는 것입니다 , 따라서 필요합니다.

다음은 General.xaml 및 내 코드 페이지입니다. 그것은 꽤 긴

SearchComboBox.vb입니다 :

Public Class SearchComboBox 
Inherits ComboBox 

Public Shared ReadOnly OriginalItemSourceProperty As DependencyProperty 

Private _OriginalItemSource As System.Collections.IEnumerable 

Shared Sub New() 
    'This OverrideMetadata call tells the system that this element wants to provide a style that is different than its base class. 
    'This style is defined in Themes\Generic.xaml 
    DefaultStyleKeyProperty.OverrideMetadata(GetType(SearchComboBox), New FrameworkPropertyMetadata(GetType(SearchComboBox))) 

    Dim md As New FrameworkPropertyMetadata() 
    SearchComboBox.OriginalItemSourceProperty = DependencyProperty.Register("OriginalSource", GetType(System.Collections.IEnumerable), GetType(SearchComboBox), md) 

End Sub 

Public Sub New() 

    MyBase.IsEditable = True 


End Sub 

Public Property OriginalSource As System.Collections.IEnumerable 
    Get 
     Return CType(GetValue(SearchComboBox.OriginalItemSourceProperty), System.Collections.IEnumerable) 
    End Get 
    Set(ByVal value As System.Collections.IEnumerable) 
     SetValue(SearchComboBox.OriginalItemSourceProperty, value) 
     MyBase.ItemsSource = value 
    End Set 
End Property 

End Class 

generic.xaml을 :

<ResourceDictionary 
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
xmlns:Microsoft_Windows_Themes="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero" 
xmlns:local="clr-namespace:SeachComboBox"> 

    <Style TargetType="{x:Type local:SearchComboBox}"> 
    <Setter Property="Template"> 
     <Setter.Value> 
      <ControlTemplate> 
       <Grid x:Name="Placement" SnapsToDevicePixels="True"> 
        <Grid.ColumnDefinitions> 
         <ColumnDefinition Width="*"/> 
         <ColumnDefinition Width="Auto"/> 
        </Grid.ColumnDefinitions> 
        <Popup x:Name="PART_Popup" AllowsTransparency="True" Grid.ColumnSpan="2" IsOpen="{Binding IsDropDownOpen, RelativeSource={RelativeSource TemplatedParent}}" PopupAnimation="{DynamicResource {x:Static SystemParameters.ComboBoxPopupAnimationKey}}" Placement="Bottom"> 
         <Microsoft_Windows_Themes:SystemDropShadowChrome x:Name="Shdw" Color="Transparent" MaxHeight="{TemplateBinding MaxDropDownHeight}" MinWidth="{Binding ActualWidth, ElementName=Placement}"> 
          <Border x:Name="DropDownBorder" BorderBrush="{DynamicResource {x:Static SystemColors.WindowFrameBrushKey}}" BorderThickness="1" Background="{DynamicResource {x:Static SystemColors.WindowBrushKey}}"> 
           <ScrollViewer x:Name="DropDownScrollViewer"> 
            <Grid RenderOptions.ClearTypeHint="Enabled"> 
             <Canvas HorizontalAlignment="Left" Height="0" VerticalAlignment="Top" Width="0"> 
              <Rectangle x:Name="OpaqueRect" Fill="{Binding Background, ElementName=DropDownBorder}" Height="{Binding ActualHeight, ElementName=DropDownBorder}" Width="{Binding ActualWidth, ElementName=DropDownBorder}"/> 
             </Canvas> 
             <ItemsPresenter x:Name="ItemsPresenter" KeyboardNavigation.DirectionalNavigation="Contained" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/> 
            </Grid> 
           </ScrollViewer> 
          </Border> 
         </Microsoft_Windows_Themes:SystemDropShadowChrome> 
        </Popup> 
        <Microsoft_Windows_Themes:ListBoxChrome x:Name="Border" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Grid.ColumnSpan="2" RenderMouseOver="{TemplateBinding IsMouseOver}" RenderFocused="{TemplateBinding IsKeyboardFocusWithin}"/> 
        <TextBox x:Name="PART_EditableTextBox" HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" IsReadOnly="{Binding IsReadOnly, RelativeSource={RelativeSource TemplatedParent}}" Margin="{TemplateBinding Padding}" VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"> 
         <TextBox.Style> 
          <Style TargetType="{x:Type TextBox}"> 
           <Setter Property="OverridesDefaultStyle" Value="True"/> 
           <Setter Property="AllowDrop" Value="True"/> 
           <Setter Property="MinWidth" Value="0"/> 
           <Setter Property="MinHeight" Value="0"/> 
           <Setter Property="FocusVisualStyle" Value="{x:Null}"/> 
           <Setter Property="ScrollViewer.PanningMode" Value="VerticalFirst"/> 
           <Setter Property="Stylus.IsFlicksEnabled" Value="False"/> 
           <Setter Property="Template"> 
            <Setter.Value> 
             <ControlTemplate TargetType="{x:Type TextBox}"> 
              <ScrollViewer x:Name="PART_ContentHost" Background="{TemplateBinding Background}" Focusable="False" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden"/> 
              <ControlTemplate.Triggers> 
               <Trigger Property="IsEnabled" Value="False"> 
                <Setter Property="FontWeight" Value="Bold"/> 
                <Setter Property="Background" Value="#FFEDDDDD"/> 
               </Trigger> 
              </ControlTemplate.Triggers> 
             </ControlTemplate> 
            </Setter.Value> 
           </Setter> 
          </Style> 
         </TextBox.Style> 
        </TextBox> 
        <ToggleButton Grid.Column="1" IsChecked="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"> 
         <ToggleButton.Style> 
          <Style TargetType="{x:Type ToggleButton}"> 
           <Setter Property="OverridesDefaultStyle" Value="True"/> 
           <Setter Property="IsTabStop" Value="False"/> 
           <Setter Property="Focusable" Value="False"/> 
           <Setter Property="ClickMode" Value="Press"/> 
           <Setter Property="Template"> 
            <Setter.Value> 
             <ControlTemplate TargetType="{x:Type ToggleButton}"> 
              <Microsoft_Windows_Themes:ButtonChrome x:Name="Chrome" BorderBrush="{TemplateBinding BorderBrush}" Background="{TemplateBinding Background}" RenderMouseOver="{TemplateBinding IsMouseOver}" RenderPressed="{TemplateBinding IsPressed}" RoundCorners="False" SnapsToDevicePixels="True" Width="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}"> 
               <Path x:Name="Arrow" Data="M0,0L3.5,4 7,0z" Fill="Black" HorizontalAlignment="Center" Margin="0,1,0,0" VerticalAlignment="Center"/> 
              </Microsoft_Windows_Themes:ButtonChrome> 
              <ControlTemplate.Triggers> 
               <Trigger Property="IsChecked" Value="True"> 
                <Setter Property="RenderPressed" TargetName="Chrome" Value="True"/> 
               </Trigger> 
               <Trigger Property="IsEnabled" Value="False"> 
                <Setter Property="Fill" TargetName="Arrow" Value="#FFEDDDDD"/> 
               </Trigger> 
              </ControlTemplate.Triggers> 
             </ControlTemplate> 
            </Setter.Value> 
           </Setter> 
          </Style> 
         </ToggleButton.Style> 
        </ToggleButton> 
       </Grid> 
       <ControlTemplate.Triggers> 
        <Trigger Property="IsKeyboardFocusWithin" Value="True"> 
         <Setter Property="Foreground" Value="Black"/> 
        </Trigger> 
        <Trigger Property="IsDropDownOpen" Value="True"> 
         <Setter Property="RenderFocused" TargetName="Border" Value="True"/> 
        </Trigger> 
        <Trigger Property="HasItems" Value="False"> 
         <Setter Property="Height" TargetName="DropDownBorder" Value="95"/> 
        </Trigger> 
        <Trigger Property="IsEnabled" Value="False"> 
         <Setter Property="FontWeight" Value="Bold"/> 
         <Setter Property="Background" Value="#FFEDDDDD"/> 
        </Trigger> 
        <Trigger Property="IsGrouping" Value="True"> 
         <Setter Property="ScrollViewer.CanContentScroll" Value="False"/> 
        </Trigger> 
        <Trigger Property="HasDropShadow" SourceName="PART_Popup" Value="True"> 
         <Setter Property="Margin" TargetName="Shdw" Value="0,0,5,5"/> 
         <Setter Property="Color" TargetName="Shdw" Value="#71000000"/> 
        </Trigger> 
        <Trigger Property="CanContentScroll" SourceName="DropDownScrollViewer" Value="False"> 
         <Setter Property="Canvas.Top" TargetName="OpaqueRect" Value="{Binding VerticalOffset, ElementName=DropDownScrollViewer}"/> 
         <Setter Property="Canvas.Left" TargetName="OpaqueRect" Value="{Binding HorizontalOffset, ElementName=DropDownScrollViewer}"/> 
        </Trigger> 
       </ControlTemplate.Triggers> 
      </ControlTemplate> 
     </Setter.Value> 
    </Setter> 
</Style> 
</ResourceDictionary> 

답변

1
<Style TargetType="{x:Type local:SearchComboBox}" BasedOn="{x:Type ComboBox}"> 
+0

나는, 나는 내 문제가 무엇인지 발견했다. 그것은 당신이 진술 한 것이 아니라 가까이에 있습니다. ControlTemplate 태그에 TargetType을 넣어야합니다. –

관련 문제