2009-09-16 4 views
1

XamlPadX를 사용하여 ComboBox의 defaultstyle을 복사하여 내 응용 프로그램 소스에 붙여 넣었습니다.스타일을 appingle 후 ComboBox를 열 수 없습니다.

이제는 더 이상 콤보 박스를 열 수 없습니다. 드롭 다운 버튼을 클릭해도 아무런 변화가 없습니다.

또 다른 문제는 나를 괴롭 히고 있습니다. 다음 줄에

"Value 'Control.Template' cannot be assigned to property 'Property'. 'IFrameworkInputElement' type does not have a matching DependencyObjectType.".

: 응용 프로그램의 컴파일 및 실행 입력해도, 디자이너는 나에게 오류 보여줍니다 때문에 디자이너가 나에게 컨트롤을 표시하지 않습니다이의

<ComboBox Name="modifier" SelectedIndex="0" Style="{DynamicResource MyComboStyle}"> 
     <ComboBoxItem>1</ComboBoxItem> 
     <ComboBoxItem>2</ComboBoxItem> 
     <ComboBoxItem>3</ComboBoxItem> 
</ComboBox> 

을하지만 나타난다 앱을 실행하면 올바르게 작동합니다.

하지만 자신의 컨트롤과 콤보를 선언 할 때 어떤 디자이너 오류가 없습니다 :

<ComboBox x:Class="ModifierControl" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"  
    Style="{DynamicResource MyComboStyle}" > 
</ComboBox> 

그런 다음 어떤 디자이너 오류가 표시되지 않습니다는.

답변

2

다음은 Blend에서 직접 선택한 ComboBox 용 템플릿입니다. 작동하는지 알려주세요.

<Window 
    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.Classic" 
    x:Class="MyComboBoxStyle.MainWindow" 
    x:Name="Window" 
    Title="MainWindow" 
    Width="640" Height="480"> 

    <Window.Resources> 
     <Style x:Key="MyComboBoxStyle" TargetType="{x:Type ComboBox}"> 
      <Setter Property="FocusVisualStyle"> 
       <Setter.Value> 
        <Style> 
         <Setter Property="Control.Template"> 
          <Setter.Value> 
           <ControlTemplate> 
            <Rectangle Stroke="Black" StrokeDashArray="1 2" StrokeThickness="1" Margin="4,4,21,4" SnapsToDevicePixels="True"/> 
           </ControlTemplate> 
          </Setter.Value> 
         </Setter> 
        </Style> 
       </Setter.Value> 
      </Setter> 
      <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.WindowTextBrushKey}}"/> 
      <Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.WindowBrushKey}}"/> 
      <Setter Property="Margin" Value="0"/> 
      <Setter Property="Padding" Value="2,1"/> 
      <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto"/> 
      <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/> 
      <Setter Property="ScrollViewer.CanContentScroll" Value="True"/> 
      <Setter Property="VerticalContentAlignment" Value="Center"/> 
      <Setter Property="Template"> 
       <Setter.Value> 
        <ControlTemplate TargetType="{x:Type ComboBox}"> 
         <Border SnapsToDevicePixels="True" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}"> 
          <Grid> 
           <Microsoft_Windows_Themes:ClassicBorderDecorator x:Name="Border" Background="{TemplateBinding Background}" BorderStyle="Sunken" BorderThickness="2"> 
            <Microsoft_Windows_Themes:ClassicBorderDecorator.BorderBrush> 
             <SolidColorBrush/> 
            </Microsoft_Windows_Themes:ClassicBorderDecorator.BorderBrush> 
            <Popup x:Name="PART_Popup" AllowsTransparency="True" IsOpen="{TemplateBinding IsDropDownOpen}" Placement="Bottom" PopupAnimation="{DynamicResource {x:Static SystemParameters.ComboBoxPopupAnimationKey}}" Focusable="False"> 
             <Microsoft_Windows_Themes:SystemDropShadowChrome x:Name="Shdw" MaxHeight="{TemplateBinding MaxDropDownHeight}" MinWidth="{Binding ActualWidth, ElementName=Border}" Color="Transparent"> 
              <Border x:Name="DropDownBorder" Background="{DynamicResource {x:Static SystemColors.WindowBrushKey}}" BorderBrush="{DynamicResource {x:Static SystemColors.WindowFrameBrushKey}}" BorderThickness="1"> 
               <ScrollViewer> 
                <ItemsPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" KeyboardNavigation.DirectionalNavigation="Contained"/> 
               </ScrollViewer> 
              </Border> 
             </Microsoft_Windows_Themes:SystemDropShadowChrome> 
            </Popup> 
           </Microsoft_Windows_Themes:ClassicBorderDecorator> 
           <DockPanel Margin="2"> 
            <FrameworkElement Width="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}" DockPanel.Dock="Right"/> 
            <Border x:Name="SelectedItemBorder" Margin="{TemplateBinding Padding}"> 
             <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="1" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" Content="{TemplateBinding SelectionBoxItem}" ContentStringFormat="{TemplateBinding SelectionBoxItemStringFormat}" ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}"/> 
            </Border> 
           </DockPanel> 
           <ToggleButton Margin="2" MinHeight="0" MinWidth="0" Width="Auto" Focusable="False" ClickMode="Press" IsChecked="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"> 
            <ToggleButton.Style> 
             <Style TargetType="{x:Type ToggleButton}"> 
              <Setter Property="MinWidth" Value="0"/> 
              <Setter Property="MinHeight" Value="0"/> 
              <Setter Property="Width" Value="NaN"/> 
              <Setter Property="Height" Value="NaN"/> 
              <Setter Property="Background" Value="Transparent"/> 
              <Setter Property="BorderBrush"> 
               <Setter.Value> 
                <SolidColorBrush/> 
               </Setter.Value> 
              </Setter> 
              <Setter Property="BorderThickness" Value="2"/> 
              <Setter Property="Template"> 
               <Setter.Value> 
                <ControlTemplate TargetType="{x:Type ToggleButton}"> 
                 <DockPanel SnapsToDevicePixels="True" Background="{TemplateBinding Background}" LastChildFill="False"> 
                  <Microsoft_Windows_Themes:ClassicBorderDecorator x:Name="Border" Width="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}" DockPanel.Dock="Right" Background="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" BorderBrush="{TemplateBinding BorderBrush}" BorderStyle="AltRaised" BorderThickness="{TemplateBinding BorderThickness}"> 
                   <Path Fill="{TemplateBinding Foreground}" HorizontalAlignment="Center" VerticalAlignment="Center" Data="M0,0L3.5,4 7,0z"/> 
                  </Microsoft_Windows_Themes:ClassicBorderDecorator> 
                 </DockPanel> 
                 <ControlTemplate.Triggers> 
                  <Trigger Property="IsChecked" Value="True"> 
                   <Setter Property="BorderStyle" TargetName="Border" Value="AltPressed"/> 
                  </Trigger> 
                 </ControlTemplate.Triggers> 
                </ControlTemplate> 
               </Setter.Value> 
              </Setter> 
              <Style.Triggers> 
               <Trigger Property="IsEnabled" Value="False"> 
                <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlDarkBrushKey}}"/> 
               </Trigger> 
              </Style.Triggers> 
             </Style> 
            </ToggleButton.Style> 
           </ToggleButton> 
          </Grid> 
         </Border> 
         <ControlTemplate.Triggers> 
          <MultiTrigger> 
           <MultiTrigger.Conditions> 
            <Condition Property="IsSelectionBoxHighlighted" Value="True"/> 
            <Condition Property="IsDropDownOpen" Value="False"/> 
           </MultiTrigger.Conditions> 
           <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.HighlightTextBrushKey}}"/> 
          </MultiTrigger> 
          <Trigger Property="IsSelectionBoxHighlighted" Value="True"> 
           <Setter Property="Background" TargetName="SelectedItemBorder" Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}"/> 
          </Trigger> 
          <Trigger Property="HasItems" Value="False"> 
           <Setter Property="MinHeight" TargetName="DropDownBorder" Value="95"/> 
          </Trigger> 
          <Trigger Property="IsEnabled" Value="False"> 
           <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/> 
           <Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"/> 
          </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> 
         </ControlTemplate.Triggers> 
        </ControlTemplate> 
       </Setter.Value> 
      </Setter> 
      <Style.Triggers> 
       <Trigger Property="IsEditable" Value="True"> 
        <Setter Property="IsTabStop" Value="False"/> 
        <Setter Property="Padding" Value="1"/> 
        <Setter Property="Template"> 
         <Setter.Value> 
          <ControlTemplate TargetType="{x:Type ComboBox}"> 
           <Border SnapsToDevicePixels="True" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}"> 
            <Grid> 
             <Microsoft_Windows_Themes:ClassicBorderDecorator x:Name="Border" Background="{TemplateBinding Background}" BorderStyle="Sunken" BorderThickness="2"> 
              <Microsoft_Windows_Themes:ClassicBorderDecorator.BorderBrush> 
               <SolidColorBrush/> 
              </Microsoft_Windows_Themes:ClassicBorderDecorator.BorderBrush> 
              <Popup x:Name="PART_Popup" AllowsTransparency="True" IsOpen="{TemplateBinding IsDropDownOpen}" Placement="Bottom" PopupAnimation="{DynamicResource {x:Static SystemParameters.ComboBoxPopupAnimationKey}}" Focusable="False"> 
               <Microsoft_Windows_Themes:SystemDropShadowChrome x:Name="Shdw" MaxHeight="{TemplateBinding MaxDropDownHeight}" MinWidth="{Binding ActualWidth, ElementName=Border}" Color="Transparent"> 
                <Border x:Name="DropDownBorder" Background="{DynamicResource {x:Static SystemColors.WindowBrushKey}}" BorderBrush="{DynamicResource {x:Static SystemColors.WindowFrameBrushKey}}" BorderThickness="1"> 
                 <ScrollViewer> 
                  <ItemsPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" KeyboardNavigation.DirectionalNavigation="Contained"/> 
                 </ScrollViewer> 
                </Border> 
               </Microsoft_Windows_Themes:SystemDropShadowChrome> 
              </Popup> 
             </Microsoft_Windows_Themes:ClassicBorderDecorator> 
             <ToggleButton Margin="2" MinHeight="0" MinWidth="0" Width="Auto" Focusable="False" ClickMode="Press" IsChecked="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"> 
              <ToggleButton.Style> 
               <Style TargetType="{x:Type ToggleButton}"> 
                <Setter Property="MinWidth" Value="0"/> 
                <Setter Property="MinHeight" Value="0"/> 
                <Setter Property="Width" Value="NaN"/> 
                <Setter Property="Height" Value="NaN"/> 
                <Setter Property="Background" Value="Transparent"/> 
                <Setter Property="BorderBrush"> 
                 <Setter.Value> 
                  <SolidColorBrush/> 
                 </Setter.Value> 
                </Setter> 
                <Setter Property="BorderThickness" Value="2"/> 
                <Setter Property="Template"> 
                 <Setter.Value> 
                  <ControlTemplate TargetType="{x:Type ToggleButton}"> 
                   <DockPanel SnapsToDevicePixels="True" Background="{TemplateBinding Background}" LastChildFill="False"> 
                    <Microsoft_Windows_Themes:ClassicBorderDecorator x:Name="Border" Width="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}" DockPanel.Dock="Right" Background="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" BorderBrush="{TemplateBinding BorderBrush}" BorderStyle="AltRaised" BorderThickness="{TemplateBinding BorderThickness}"> 
                     <Path Fill="{TemplateBinding Foreground}" HorizontalAlignment="Center" VerticalAlignment="Center" Data="M0,0L3.5,4 7,0z"/> 
                    </Microsoft_Windows_Themes:ClassicBorderDecorator> 
                   </DockPanel> 
                   <ControlTemplate.Triggers> 
                    <Trigger Property="IsChecked" Value="True"> 
                     <Setter Property="BorderStyle" TargetName="Border" Value="AltPressed"/> 
                    </Trigger> 
                   </ControlTemplate.Triggers> 
                  </ControlTemplate> 
                 </Setter.Value> 
                </Setter> 
                <Style.Triggers> 
                 <Trigger Property="IsEnabled" Value="False"> 
                  <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlDarkBrushKey}}"/> 
                 </Trigger> 
                </Style.Triggers> 
               </Style> 
              </ToggleButton.Style> 
             </ToggleButton> 
             <DockPanel Margin="2"> 
              <FrameworkElement Width="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}" DockPanel.Dock="Right"/> 
              <TextBox x:Name="PART_EditableTextBox" Margin="{TemplateBinding Padding}" HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}" IsReadOnly="{Binding IsReadOnly, RelativeSource={RelativeSource TemplatedParent}}"> 
               <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="Template"> 
                  <Setter.Value> 
                   <ControlTemplate TargetType="{x:Type TextBox}"> 
                    <ScrollViewer x:Name="PART_ContentHost" Background="Transparent" Focusable="False" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden"/> 
                   </ControlTemplate> 
                  </Setter.Value> 
                 </Setter> 
                </Style> 
               </TextBox.Style> 
              </TextBox> 
             </DockPanel> 
            </Grid> 
           </Border> 
           <ControlTemplate.Triggers> 
            <Trigger Property="HasItems" Value="False"> 
             <Setter Property="MinHeight" TargetName="DropDownBorder" Value="95"/> 
            </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="IsEnabled" Value="False"> 
             <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/> 
             <Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"/> 
            </Trigger> 
            <Trigger Property="IsGrouping" Value="True"> 
             <Setter Property="ScrollViewer.CanContentScroll" Value="False"/> 
            </Trigger> 
           </ControlTemplate.Triggers> 
          </ControlTemplate> 
         </Setter.Value> 
        </Setter> 
       </Trigger> 
      </Style.Triggers> 
     </Style> 
    </Window.Resources> 

    <Grid x:Name="LayoutRoot"> 
     <ComboBox HorizontalAlignment="Left" Margin="111,156,0,0" Style="{DynamicResource MyComboBoxStyle}" VerticalAlignment="Top" Width="197" Height="25"/> 
    </Grid> 
</Window> 
+0

고맙습니다. :) – codymanix

0

내 마음에 가장 먼저 오는 것은 StaticResource로 리소스에 액세스하기 위해 아래 언급 된 라인을 변경하는 것입니다. 컴파일러가 리소스를 찾지 못하면 컴파일 오류가 발생합니다. 또한 실제로 사용하는 행 앞에 자원을 정의해야합니다.

Style="{DynamicResource MyComboStyle}" 
+0

자원이 발견되었지만 경고가 표시되며 콤보를 열 수 없습니다. – codymanix

관련 문제