2014-11-21 2 views
1

배경 이미지에 불투명도를 적용하고 싶지만 컨트롤 위에 "오버레이"를 지정하지 마십시오. 여기에 제 XAML 작동하지만, 현재 컨트롤 (콤보 박스 등)도 이미지와 함께 페이드 인 및 페이드 아웃됩니다. 컨트롤을 변경하지 않으려면 어떻게 변경합니까?그리드의 배경에 대해서는 이미지의 불투명도를 애니메이트하지만 그리드의 컨트롤에는 애니메이션을 적용하지 않는 방법은 무엇입니까?

<Window x:Class="george.MainWindow" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    Title="MainWindow" Height="350" Width="525" > 
<Grid> 
    <Grid.RowDefinitions> 
     <RowDefinition /> 
     <RowDefinition /> 
    </Grid.RowDefinitions> 
    <Border> 
     <Border.Style> 
      <Style TargetType="Border"> 
       <Setter Property="Background"> 
        <Setter.Value> 
         <ImageBrush ImageSource="/George_mcfly.jpg" /> 
        </Setter.Value> 
       </Setter> 
       <Setter Property="Opacity" Value="0.4" /> 
       <Style.Triggers> 
        <EventTrigger RoutedEvent="Border.MouseEnter"> 
         <BeginStoryboard> 
          <Storyboard> 
           <DoubleAnimation To="0.8" AutoReverse="True" RepeatBehavior="Forever" Storyboard.TargetProperty="Opacity"></DoubleAnimation> 
          </Storyboard> 
         </BeginStoryboard> 
        </EventTrigger> 
        <EventTrigger RoutedEvent="Border.MouseLeave"> 
         <BeginStoryboard> 
          <Storyboard> 
           <DoubleAnimation To="0.3" AutoReverse="True" RepeatBehavior="Forever" Storyboard.TargetProperty="Opacity"></DoubleAnimation> 
          </Storyboard> 
         </BeginStoryboard> 
        </EventTrigger> 

       </Style.Triggers> 
      </Style> 
     </Border.Style> 
     <Grid Grid.Row="0"> 
      <Grid.RowDefinitions> 
       <RowDefinition Height="Auto"/> 
       <RowDefinition Height="Auto"/> 
       <RowDefinition Height="Auto"/> 
       <RowDefinition Height="Auto"/> 
       <RowDefinition Height="Auto"/> 
       <RowDefinition Height="60"/> 
       <RowDefinition Height="60"/> 
       <RowDefinition Height="Auto"/> 
       <RowDefinition Height="Auto" /> 
      </Grid.RowDefinitions> 
      <Grid.ColumnDefinitions> 
       <ColumnDefinition /> 
       <ColumnDefinition /> 
      </Grid.ColumnDefinitions> 
      <Label Content="{Binding ApplicationName}" FontSize="18" Grid.ColumnSpan="2" /> 
      <Label Content="Version:" Grid.Row="1" FontWeight="Bold" FontSize="14"/> 
      <Label Content="{Binding Version}" FontSize="14" Foreground="Red" Grid.Row="1" Grid.Column="1"/> 

      <Label Content="Current Connection:" Grid.Row="2" FontWeight="Bold"/> 
      <Label Content="example" Grid.Row="2" Grid.Column="1"/> 

      <ComboBox Grid.Row="3"> 
       <ComboBoxItem Content="A" /> 
       <ComboBoxItem Content="B" /> 
      </ComboBox> 
      <Label Content="User Name: " Grid.Row="4" FontWeight="Bold"/> 
      <Label Content="sample text" Grid.Row="4" Grid.Column="1"/> 

      <Label Content="Active Directory Groups: " Grid.Row="5" FontWeight="Bold"/> 
      <ListBox Grid.Row="5" Grid.Column="1" Background="Transparent" BorderBrush="Transparent"> 
       <ListBoxItem Content="1" /> 
       <ListBoxItem Content="2" /> 
       <ListBoxItem Content="3" /> 
       <ListBoxItem Content="4" /> 
      </ListBox> 
     </Grid> 
    </Border> 
</Grid> 

답변

1

그냥 당신이 이미 그리드에 포함 된 이후 매우 간단하다 그 부모 - 자식 관계를 분리;

<Window x:Class="george.MainWindow" 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     Title="MainWindow" Height="350" Width="525" > 
    <Grid> 
     <Grid.RowDefinitions> 
      <RowDefinition /> 
      <RowDefinition /> 
     </Grid.RowDefinitions> 
     <Border> 
      <Border.Style> 
       <Style TargetType="Border"> 
        <Setter Property="Background"> 
         <Setter.Value> 
          <ImageBrush ImageSource="/George_mcfly.jpg" /> 
         </Setter.Value> 
        </Setter> 
        <Setter Property="Opacity" Value="0.4" /> 
        <Style.Triggers> 
         <EventTrigger RoutedEvent="Border.MouseEnter"> 
          <BeginStoryboard> 
           <Storyboard> 
            <DoubleAnimation To="0.8" AutoReverse="True" RepeatBehavior="Forever" Storyboard.TargetProperty="Opacity"></DoubleAnimation> 
           </Storyboard> 
          </BeginStoryboard> 
         </EventTrigger> 
         <EventTrigger RoutedEvent="Border.MouseLeave"> 
          <BeginStoryboard> 
           <Storyboard> 
            <DoubleAnimation To="0.3" AutoReverse="True" RepeatBehavior="Forever" Storyboard.TargetProperty="Opacity"></DoubleAnimation> 
           </Storyboard> 
          </BeginStoryboard> 
         </EventTrigger> 
        </Style.Triggers> 
       </Style> 
      </Border.Style> 
<!-- We end the Border so it's only behind the elements instead of acting as their parent --> 
      </Border> 
      <Grid Grid.Row="0"> 
       <Grid.RowDefinitions> 
        <RowDefinition Height="Auto"/> 
        <RowDefinition Height="Auto"/> 
        <RowDefinition Height="Auto"/> 
        <RowDefinition Height="Auto"/> 
        <RowDefinition Height="Auto"/> 
        <RowDefinition Height="60"/> 
        <RowDefinition Height="60"/> 
        <RowDefinition Height="Auto"/> 
        <RowDefinition Height="Auto" /> 
       </Grid.RowDefinitions> 
       <Grid.ColumnDefinitions> 
        <ColumnDefinition /> 
        <ColumnDefinition /> 
       </Grid.ColumnDefinitions> 
       <Label Content="{Binding ApplicationName}" FontSize="18" Grid.ColumnSpan="2" /> 
       <Label Content="Version:" Grid.Row="1" FontWeight="Bold" FontSize="14"/> 
       <Label Content="{Binding Version}" FontSize="14" Foreground="Red" Grid.Row="1" Grid.Column="1"/> 

       <Label Content="Current Connection:" Grid.Row="2" FontWeight="Bold"/> 
       <Label Content="example" Grid.Row="2" Grid.Column="1"/> 

       <ComboBox Grid.Row="3"> 
        <ComboBoxItem Content="A" /> 
        <ComboBoxItem Content="B" /> 
       </ComboBox> 
       <Label Content="User Name: " Grid.Row="4" FontWeight="Bold"/> 
       <Label Content="sample text" Grid.Row="4" Grid.Column="1"/> 

       <Label Content="Active Directory Groups: " Grid.Row="5" FontWeight="Bold"/> 
       <ListBox Grid.Row="5" Grid.Column="1" Background="Transparent" BorderBrush="Transparent"> 
        <ListBoxItem Content="1" /> 
        <ListBoxItem Content="2" /> 
        <ListBoxItem Content="3" /> 
        <ListBoxItem Content="4" /> 
       </ListBox> 
      </Grid> 

    </Grid> 

McFly는 오, +1, 마티와 의사는 어디 있습니까? :)

오, 그리고 또한 부모 격자에 해당 이벤트를 첨부하고 TargetName 또는 TargetObject으로 애니메이션의 경계 만 타겟팅하는 것이 좋습니다. 테두리 만하면됩니다.

+0

박사님은 2 버전 전 이었으므로 로렌이 현재 버전입니다. 마티 한테 아직 안 왔어. 나는 당신의 제안을 지금 고맙다고 생각합니다. –

+1

하하 그게 최고예요! Biff 또는 바늘을 기다릴 수 없습니다. lol –

+0

감사합니다. –

관련 문제