2015-10-16 26 views
2

我建立了一個消息欄,帶有動畫文本, see the .gif from the animation。 就像你可以在前臺看到文字「蒼蠅」並隱藏佔位符。但我需要佔位符在前臺。Wpf文字選框後面的其他元素

我的第一個想法是動畫的區域從

doubleAnimation.To = tbInfo.ActualWidth *-1; 

改變

doubleAnimation.To = boLogo.ActualWidth; 

但結果看起來是這樣的:version with other animation area

如何在前臺設置佔位符,讓動畫「飛」的背後呢?


我的XAML碼

<Canvas x:Name="canMain" HorizontalAlignment="Stretch" VerticalAlignment="Center"> 
    <Border x:Name="boLogo" Height="40" Background="Gray" Canvas.Left="0" Canvas.Top="-20"> 
     <Button Content="Placeholder" Width="90" /> 
    </Border> 
    <TextBlock x:Name="tbInfo" Visibility="Hidden" FontSize="32" FontWeight="Bold" Padding="5" HorizontalAlignment="Stretch" VerticalAlignment="Center"></TextBlock> 
</Canvas> 

和代碼顯示窗口

public void ShowWindow(string str) 
{ 
    tbInfo.Text = str; 
    this.Height = 39; 
    this.Width = SystemParameters.WorkArea.Width; 
    this.Left = SystemParameters.PrimaryScreenWidth - this.Width; 
    this.Show(); 

    TextMarquee(20); 
} 

private void TextMarquee(int duration) 
{ 
    double height = canMain.ActualHeight - tbInfo.ActualHeight; 
    tbInfo.Margin = new Thickness(0, height/2, 0, 0); 
    DoubleAnimation doubleAnimation = new DoubleAnimation(); 
    doubleAnimation.From = canMain.ActualWidth; 
    doubleAnimation.To = tbInfo.ActualWidth * -1; 
    doubleAnimation.RepeatBehavior = RepeatBehavior.Forever; 
    doubleAnimation.Duration = new Duration(TimeSpan.FromSeconds(duration)); 
    tbInfo.BeginAnimation(Canvas.LeftProperty, doubleAnimation); 
    tbInfo.Visibility = Visibility.Visible; 
} 

回答

1

嘗試Grid.ZIndex:

<Grid x:Name="canMain" > 
    <Border x:Name="boLogo" Grid.ZIndex="2"> 
     <Button Content="Placeholder" /> 
    </Border> 
    <TextBlock x:Name="tbInfo" Grid.ZIndex="1"/> 
</Grid> 

是最可見的圖層ZIndex = "2"

+0

我嘗試它與周圍的網格,並與周圍的畫布。像[這裏](http://stackoverflow.com/a/5450993/4248617)。但它不會改變任何事情。 –

+0

您正在使用'doubleAnimation.To = tbInfo.ActualWidth * -1;'對嗎?你也可以嘗試改變元素的順序。首先是文本塊,然後是邊框。 – Jose

+0

是的,我願意。請參閱@ O.DO的答案,Panel.ZIndex是要走的路。 –

相關問題