滑动儿童窗口不在wpf中工作

时间:2012-07-17 00:14:22

标签: c# wpf animation

我使用translatetransform来滑动我的子窗口,但我认为我的xaml代码有问题。窗口不是在滑动,而是在窗口内滑动(或网格)。

这是我的儿童窗口XAML:

<Window x:Class="SAMPLE.ChildWindow"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  WindowStartupLocation="CenterOwner"
  x:Name="HomeWindows"
  Title="HomeWindow" Height="348" Width="440" Loaded="HomeWindows_Loaded">
  <Window.RenderTransform>
    <TranslateTransform />
  </Window.RenderTransform>
  <Window.Resources>
    <Storyboard x:Key="SlaydAndFeyd" >
        <DoubleAnimation Storyboard.TargetName="HomeWindows"  Storyboard.TargetProperty="(Window.RenderTransform).(TranslateTransform.X)" From="50" To="0" Duration="0:0:0.4" />
    </Storyboard>
  </Window.Resources>

然后为我的功能,调用故事板:

    public void SlaydAndFeyds()
    {
        (FindResource("SlaydAndFeyd") as Storyboard).Begin(this);
    }

现在在主窗口代码中:

namespace SAMPLE
{
  public partial class MainWindow : Window
  {

    public MainWindow()
    {
        InitializeComponent();
    }

    private ChildWindow NewChildWindow = new ChildWindow();

    private void btnShowChild_Click(object sender, RoutedEventArgs e)
    {
        NewHomeWindow.Owner = this;
        NewHomeWindow.Show();
    }

    private void btnSlideChild_Click(object sender, RoutedEventArgs e)
    {
       NewHomeWindow.SlaydAndFeyds();
    }

或者任何人都知道如何滑动我的儿童窗口?

1 个答案:

答案 0 :(得分:1)

该示例中的RenderTransform将影响窗口的内容,而不影响窗口本身。

要移动窗口,请使用EventTrigger调整Left / Top属性。我猜你想要在4秒内左右滑动50像素左右,调整数字以适应:

<Window.Triggers> 
    <EventTrigger RoutedEvent="Window.Loaded"> 
        <BeginStoryboard> 
            <Storyboard> 
                <DoubleAnimation BeginTime="00:00:00"    
                                Storyboard.TargetName="HomeWindows"    
                                Storyboard.TargetProperty="(Window.Left)"    
                                By="-12"    
                                Duration="0:0:4" /> 
            </Storyboard> 
        </BeginStoryboard> 
    </EventTrigger> 
</Window.Triggers>