2011-04-18 8 views
2

누구나 스타일/서식 파일을 기본 초기 상태로만 단추를 표시하는 방법에 대한 예제가 있는지 궁금합니다. 리본 모음의 DropDownButton 갤러리와 같습니다. 사용자가 버튼을 클릭하고 콤보 박스 항목을 나열 할 수 있기를 바랍니다. 선택을하면 텍스트 필드에 버튼 만 있기 때문에 선택한 항목을 텍스트 필드에 저장하지 않습니다. ContentPresenter에와 PART_EditableTextBox 의도적으로 주석 한 그들이 템플릿에서 이륙 할 수 있다는
참고 : 감사합니다 :)ComboBox ControlTemplate 드롭 다운 버튼

답변

4

는 여기에 몇 가지 예제 코드입니다.
또한 토글 버튼과 팝업의 모양을 사용자 정의 할 수 있습니다. Customizing the Appearance of an Existing Control by Creating a ControlTemplate

:

<Window x:Class="HiddenTextComboBox.Window1" 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     Title="Window1" Height="300" Width="300"> 
    <Window.Resources> 
     <ControlTemplate x:Key="HiddenTextComboBox" TargetType="{x:Type ComboBox}"> 
      <Grid> 
       <ToggleButton x:Name="DropDownToggle" 
        HorizontalAlignment="Stretch" VerticalAlignment="Stretch" 
        Margin="-1" HorizontalContentAlignment="Right" 
        IsChecked="{Binding Path=IsDropDownOpen,Mode=TwoWay, 
           RelativeSource={RelativeSource TemplatedParent}}"> 
        <Path x:Name="BtnArrow" Height="4" Width="8" 
        Stretch="Uniform" Margin="0,0,4,0" Fill="Black" 
        Data="F1 M 300,-190L 310,-190L 305,-183L 301,-190 Z " /> 
       </ToggleButton> 
       <!--<ContentPresenter x:Name="ContentPresenter" Margin="6,2,25,2" 
        Content="{TemplateBinding SelectionBoxItem}" 
        ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}" 
        ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}"> 
       </ContentPresenter> 
       <TextBox x:Name="PART_EditableTextBox" 
        Style="{x:Null}" 
        Focusable="False" 
        Background="{TemplateBinding Background}" 
        HorizontalAlignment="Left" 
        VerticalAlignment="Center" 
        Margin="3,3,23,3" 
        Visibility="Hidden" 
        IsReadOnly="{TemplateBinding IsReadOnly}"/>--> 
       <Popup x:Name="PART_Popup" 
        IsOpen="{TemplateBinding IsDropDownOpen}"> 
        <Border x:Name="PopupBorder" 
        HorizontalAlignment="Stretch" Height="Auto" 
        MinWidth="{TemplateBinding ActualWidth}" 
        MaxHeight="{TemplateBinding MaxDropDownHeight}" 
        BorderThickness="{TemplateBinding BorderThickness}" 
        BorderBrush="Black" Background="White" CornerRadius="3"> 
         <ScrollViewer x:Name="ScrollViewer" BorderThickness="0" Padding="1"> 
          <ItemsPresenter/> 
         </ScrollViewer> 
        </Border> 
       </Popup> 
      </Grid> 
     </ControlTemplate> 
    </Window.Resources> 
    <Grid> 
      <ComboBox Height="23" Width="23" Template="{StaticResource HiddenTextComboBox}"> 
       <ComboBoxItem>First</ComboBoxItem> 
       <ComboBoxItem>Second</ComboBoxItem> 
       <ComboBoxItem>Third</ComboBoxItem> 
      </ComboBox> 
    </Grid> 
</Window> 

코드에서 적응