2012-06-29 2 views
1

블렌드를 사용하여 스타일을 복사하고 필요한 대부분의 변경을 완료했지만 완전히 반올림을 제거하고이 공백을 제거하는 방법에 정말로 매달 렸습니다. arrouw가있는 버튼은 18이어야하며 전체 드롭 다운은 18이어야합니다. 이제 버튼이 가운데에 놓이지 않으면 서 패딩과 흰색 주위가 있습니다. 게다가,이 반올림? 나는 마침내가 바로이 시간을 가지고 ,내부의 패딩을 제거하고 둥근 모서리를 없애기위한 스타일 콤보 박스. 방법?

<Style x:Key="ComboBoxReadonlyToggleButton" 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 Height="18" 
          x:Name="Chrome" RoundCorners="False" 
          BorderBrush="{TemplateBinding BorderBrush}" 
          Background="{TemplateBinding Background}" 
          RenderMouseOver="{TemplateBinding IsMouseOver}" 
          RenderPressed="{TemplateBinding IsPressed}" SnapsToDevicePixels="true"> 
          <Border 
           BorderBrush="#a6a6a6" BorderThickness="1" 
           HorizontalAlignment="Right" Width="18" Height="18"> 
           <Border.Background>          
            <LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1"> 
             <GradientStop Color="#899ba5" /> 
             <GradientStop Color="#4f6473" Offset="1" /> 
            </LinearGradientBrush>          
           </Border.Background> 
           <Grid> 
            <Path x:Name="Arrow" Fill="#dcdcdc" HorizontalAlignment="Center" VerticalAlignment="Center"> 
             <Path.Data> 
              <Geometry>M 0 0 L 3.5 4 L 7 0 Z</Geometry> 
             </Path.Data> 
            </Path> 
           </Grid> 
          </Border>        
         </Microsoft_Windows_Themes:ButtonChrome> 
        </ControlTemplate> 
       </Setter.Value> 
      </Setter> 
     </Style>   
     <Style x:Key="ComboBoxStyle" TargetType="{x:Type ComboBox}"> 
      <Setter Property="Height" Value="18" /> 
      <Setter Property="Foreground" Value="#1a3e55"/> 
      <Setter Property="Background" Value="#f7f7f7"/> 
      <Setter Property="BorderBrush" Value="#a6a6a6"/> 
      <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto"/> 
      <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/> 

      <Setter Property="ScrollViewer.CanContentScroll" Value="true"/> 
      <Setter Property="ScrollViewer.PanningMode" Value="Both"/> 
      <Setter Property="Stylus.IsFlicksEnabled" Value="False"/> 
      <Setter Property="Template"> 
       <Setter.Value> 
        <ControlTemplate TargetType="{x:Type ComboBox}"> 
         <Grid x:Name="MainGrid" 
          SnapsToDevicePixels="true"> 
          <Grid.ColumnDefinitions> 
           <ColumnDefinition Width="*"/> 
           <ColumnDefinition MinWidth="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}" Width="0"/> 
          </Grid.ColumnDefinitions> 
          <Popup x:Name="PART_Popup" AllowsTransparency="true" Grid.ColumnSpan="2" IsOpen="{Binding IsDropDownOpen, RelativeSource={RelativeSource TemplatedParent}}" Margin="1" PopupAnimation="{DynamicResource {x:Static SystemParameters.ComboBoxPopupAnimationKey}}" Placement="Bottom"> 
           <Microsoft_Windows_Themes:SystemDropShadowChrome x:Name="Shdw" Color="Transparent" MaxHeight="{TemplateBinding MaxDropDownHeight}" MinWidth="{Binding ActualWidth, ElementName=MainGrid}"> 
            <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> 
          <ToggleButton 
           BorderBrush="{TemplateBinding BorderBrush}" 
           Background="{TemplateBinding Background}" 
           Grid.ColumnSpan="2" 
           IsChecked="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" 
           Style="{StaticResource ComboBoxReadonlyToggleButton}"/> 
          <ContentPresenter 
           ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}" 
           ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}" 
           Content="{TemplateBinding SelectionBoxItem}" 
           ContentStringFormat="{TemplateBinding SelectionBoxItemStringFormat}" 
           HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" 
           IsHitTestVisible="false" 
           Margin="{TemplateBinding Padding}" 
           SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" 
           VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/> 
         </Grid> 
        </ControlTemplate> 
       </Setter.Value> 
      </Setter>   
     </Style>  
+0

둥근 모서리 = - 적용 그 재산을 전반적인 통제로 덧 덧씌움은 잘 모르겠다. 패딩 = "0"속성을 추가하려고 했습니까? – Tom

+0

컨트롤에 RoundCorners 속성이 없습니다. – katit

+0

알았습니다. 이것은 정말로 재미있는 문제였습니다. 첫 번째 댓글과 답변을 드려 죄송합니다. 첫눈에 단순하게 표시되지만 상당히 복잡합니다. :) – Tom

답변

2

좋아요 :

enter image description here

내 스타일이다.

이 모든 것이 ButtonChrome 스타일 템플릿에 있습니다. 이 스타일을 바꾸는 방법에 대해이 대답 https://stackoverflow.com/a/4554309/1449777을 사용했습니다. 여기에 제공된 링크에서 클래스 파일을 다운로드하십시오. http://www.mediafire.com/?wnra4qj4qt07wn6

첫 번째 사항부터 먼저 둥근 모서리를 제거하십시오.

토글 버튼의 ​​스타일을 버튼 크롬 클래스의 로컬 사본으로 업데이트하고 RoundedCorners = "false"로 설정하십시오.

<local:MyButtonChrome RoundCorners="False" ... > 

둥근 모서리를 수정하려면 RoundedCorners = "false"를 올바르게 구현하도록 buttonchrome 클래스를 수정하십시오. 이제 처리 할 수 ​​있습니다

private void DrawInnerBorder(DrawingContext dc, ref Rect bounds) 
{ 
    if (DisableInnerBorder == false && ((base.IsEnabled || this.RoundCorners) && ((bounds.Width >= 4.0) && (bounds.Height >= 4.0)))) 
    { 
     Pen innerBorderPen = this.InnerBorderPen; 
     if (innerBorderPen != null) 
     { 
      if (this.RoundCorners) 
      { 
       dc.DrawRoundedRectangle(null, innerBorderPen, new Rect(bounds.Left + 1.5, bounds.Top + 1.5, bounds.Width - 3.0, bounds.Height - 3.0), 1.75, 1.75); 
      } 
      else 
      { 
       dc.DrawRoundedRectangle(null, innerBorderPen, new Rect(bounds.Left + 1.5, bounds.Top + 1.5, bounds.Width - 3.0, bounds.Height - 3.0), 0, 0); 
      } 
     } 
    } 
} 

:로 (라인 180)

if (this.RoundCorners) 
{ 
    Rect rectangle = new Rect(bounds.Left + 0.5, bounds.Top + 0.5, bounds.Width - 1.0, bounds.Height - 1.0); 
    if (base.IsEnabled && (pen != null)) 
    { 
     dc.DrawRoundedRectangle(null, pen, rectangle, 2.75, 2.75); 
    } 
    if (borderOverlayPen != null) 
    { 
     dc.DrawRoundedRectangle(null, borderOverlayPen, rectangle, 2.75, 2.75); 
    } 
} 
else 
{ 
    Rect rectangle = new Rect(bounds.Left + 0.5, bounds.Top + 0.5, bounds.Width - 1.0, bounds.Height - 1.0); 
    if (base.IsEnabled && (pen != null)) 
    { 
     dc.DrawRectangle(null, pen, rectangle); 
    } 
    if (borderOverlayPen != null) 
    { 
     dc.DrawRectangle(null, borderOverlayPen, rectangle); 
    } 
} 

그리고 나는 InnerBorder 기능을 변경하십시오 DrawBorder 기능, 나는 경계 (행 번호 128)에 그릴 논리를 변경 그 패딩.

이 중 하나를 찾아내는 데 시간이 걸렸지 만 ArrangeOverride 함수 (40 행)에서이 점을 발견했습니다. 다음 함수를 삭제하면 더 이상 게재 위치를 재정의하지 않습니다.

protected override Size ArrangeOverride(Size finalSize) 

결과 : 당신은 단지 버튼위한 설정하는 것이 거짓

그리고 그냥 실제로 일했다는 것을 증명하기 위해 ...

enter image description here

+0

와우! 고마워. 실제로 그 대답을 보았지만 나의 질문은 "왜 그렇게 힘들 수 있습니까?"였습니다. XAML에 대한 모든 내용은 내 스타일에서 내가 원하는 스타일링의 용이성에 관한 것입니다. 내가 원하는 것을 스타일링하기 위해 맞춤 크롬을 만드는 것은 조금 지나친 것 같습니다. Btw, CheckBox를 스타일링하려고 시도하고 정확히 같은 종류의 문제가 발생했습니다. – katit

+0

그래, 나는 그것이 과잉이라고 동의합니다. :)하지만 몇 가지 다른 방법을 시도한 후에, 나는 그것이 가능했는지를보고 싶었습니다. – Tom

관련 문제