2010-02-22 3 views
2

Wpf 드롭 섀도우가 사라집니다. 재현하는 방법은 다음과 같습니다.WPF DropShadow가 사라짐

xaml 패드에 다음을 입력하십시오. 당신은 테두리와 텍스트를 볼 수

<Page.Resources> 
    <DropShadowEffect x:Key="shadow" 
     Opacity="1" 
     ShadowDepth="1" 
     Color="Blue" 
     BlurRadius="30"/> 
</Page.Resources> 
<Grid> 
    <Button HorizontalAlignment="Left" VerticalAlignment="Top" Margin="0,0,0,0"> 
     <Button.Style> 
      <Style TargetType="{x:Type Button}"> 
       <Setter Property="Template"> 
        <Setter.Value> 
         <ControlTemplate TargetType="{x:Type Button}"> 
          <Border x:Name="Bd" 
            BorderBrush="Black" BorderThickness="1" 
            Background="Yellow" 
            CornerRadius="8" 
            Effect="{StaticResource shadow}"> 
           <TextBlock Text="Hello out there" HorizontalAlignment="Center" VerticalAlignment="Center" /> 
          </Border> 
         </ControlTemplate> 
        </Setter.Value> 
       </Setter> 
      </Style> 
     </Button.Style> 
    </Button> 
</Grid> 

가 풍부하고, 국경 주변의 그림자. 당신이 국경을 볼 수 있도록

이제 여백 = "0,0,0,0" 에 여백 = "0,300,0,0" 및 크기 당신의 XAML 패드 창을 변경합니다. 내 컴퓨터에서 그림자가 사라졌습니다.

누구든이 사람이이 명 령을 보냅니 까? 도와주세요.

답변

2

나는 당신에게 좋은 설명이 있었으면 좋겠지 만, XAML에 이상한 것들이있어서 놀았고 당신을위한 해결책이 있다고 생각합니다.

  1. 그리드를 사용하는 경우 특정 수의 행과 열을 배치해야 할 가능성이 큽니다. 당신은 그것들을 지정해야합니다. 그러나 이것은 문제에 영향을주지 않습니다.
  2. 마찬가지로 요소에 대한 행 및 열을 지정해야합니다. 결국이 정보를 XAML에 저장해야하기 때문입니다. IMO로 시작하는 것이 좋은 습관입니다.
  3. 내가 설명 할 수없는 문제는 HorizontalAlignment와 VerticalAlignment를 함께 사용하는 것입니다. Grid에 Button을 배치하면 Button이 전체 공간을 차지할 것으로 예상되지만 그렇지 않습니다. 내가 알아낼 수있는 한이 작업을 할 수있는 유일한 방법은 높이너비을 지정하는 것입니다. 이렇게하면 효과가 작동합니다. 원본 XML의 임계 값은 총 Y 마진 239입니다. 예를 들어, 0,239,0,0을 사용하면 실패합니다. 0,139,0,100을 사용하면 합계가 239이기 때문에 실패합니다. 이상한 것. 영업 이익은 버튼의 콘텐츠를 동적으로 변경할 수 있기 때문에 버튼의 크기를 지정하지 않는

    <Page.Resources> 
        <DropShadowEffect x:Key="shadow" 
         Opacity="1" 
         ShadowDepth="2" 
         Color="Blue" 
         BlurRadius="30"/> 
    </Page.Resources> 
    <Grid Width="Auto" Height="Auto"> 
        <Grid.RowDefinitions> 
        <RowDefinition></RowDefinition> 
        </Grid.RowDefinitions> 
        <Grid.ColumnDefinitions> 
        <ColumnDefinition></ColumnDefinition> 
        </Grid.ColumnDefinitions> 
        <Button Width="90" Height="30" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="0,300,0,0" Grid.Row="0" Grid.Column="0"> 
         <Button.Style> 
          <Style TargetType="{x:Type Button}"> 
           <Setter Property="Template"> 
            <Setter.Value> 
             <ControlTemplate TargetType="{x:Type Button}"> 
              <Border x:Name="Bd" 
                BorderBrush="Black" BorderThickness="1" 
                Background="Yellow" 
                CornerRadius="8" 
                Effect="{StaticResource shadow}"> 
               <TextBlock Text="Hello out there" HorizontalAlignment="Center" VerticalAlignment="Center" /> 
              </Border> 
             </ControlTemplate> 
            </Setter.Value> 
           </Setter> 
          </Style> 
         </Button.Style> 
        </Button> 
    

    편집 :

여기에 작동하는 내 XAML입니다. MinHeight를 18과 같이 설정하면 (대부분의 콘텐츠에 대해 합리적이라고 생각합니다) 드롭 섀도우 효과가 다시 작동합니다.

<Border x:Name="Bd" BorderBrush="Black" BorderThickness="1" Background="Yellow" CornerRadius="8" Effect="{StaticResource shadow}" MinHeight="18"> 
    <StackPanel Orientation="Vertical"> 
    <TextBlock>hi</TextBlock> 
    <TextBlock>there</TextBlock> 
    </StackPanel> 
</Border> 
+0

그래, 이건 이상한 것입니다. Canvas를 Grid로 흉내 내기 때문에 행/열을 지정하지 않습니다. 당신의 말이 맞습니다 : 버튼 크기를 "고정"설정하지만 버튼 크기를 내용에 자동 크기로 지정하기 때문에 단추 크기를 명시 적으로 설정할 수 없습니다. 감사. –

+0

좋아, 나는 조금 더 가지고 놀 것이다. 왜 그리드로 캔버스를 흉내 내고 있습니까? 너는 찰칵 소리를 내고자하는거야? – Dave

+0

나는 가변 내용을 위해 일할 수있는 또 다른 해결책을 가지고있다. Border의 MinHeight를 18과 같이 합리적인 값으로 설정하십시오. StackPanel 내부의 여러 TextBlock에 대해 작업하고 있습니다. – Dave