0

我使用 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();
    }

或者有人知道如何滑动我的子窗口?

4

1 回答 1

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>
于 2012-07-17T00:43:46.453 回答