执行故事板以关闭在 showdialog 中打开的窗口时出错

当Storyboard关闭窗口“This Visual is not connected to a PresentationSource”时,我得到了这个错误。


我的场景包括两个窗口和一个 UserControl


这是window1的xaml代码:


<Window x:Name="LWindow" x:Class="WpfAppXtesting.WindowTest1"

    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"

    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"

    xmlns:local="clr-namespace:WpfAppXtesting"

    mc:Ignorable="d"

    WindowStyle="None"

    Title="WindowTest1" Height="160" Width="435">

<Window.Resources>

    <ResourceDictionary>

        <ResourceDictionary.MergedDictionaries>

        </ResourceDictionary.MergedDictionaries>


        <!-- Storyboard -->

        <Storyboard x:Key="OpenLWindow">

            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Width)" Storyboard.TargetName="LWindow">

                <EasingDoubleKeyFrame KeyTime="0" Value="0"/>

                <EasingDoubleKeyFrame KeyTime="0:0:0.5" Value="434.4"/>

            </DoubleAnimationUsingKeyFrames>

            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Height)" Storyboard.TargetName="LWindow">

                <EasingDoubleKeyFrame KeyTime="0" Value="37"/>

                <EasingDoubleKeyFrame KeyTime="0:0:0.5" Value="37"/>

                <EasingDoubleKeyFrame KeyTime="0:0:1" Value="159.8"/>

            </DoubleAnimationUsingKeyFrames>

        </Storyboard>

    


猛跑小猪
浏览 210回答 1
1回答

杨__羊羊

尝试使用Dispatcher类在消息循环的下一次迭代中关闭窗口:private void CloseLWindow_Completed(object sender, EventArgs e){&nbsp; &nbsp; Dispatcher.BeginInvoke(new Action(() => Close()));}
打开App,查看更多内容
随时随地看视频慕课网APP