当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>
1 回答
杨__羊羊
TA贡献1943条经验 获得超7个赞
尝试使用Dispatcher类在消息循环的下一次迭代中关闭窗口:
private void CloseLWindow_Completed(object sender, EventArgs e)
{
Dispatcher.BeginInvoke(new Action(() => Close()));
}
- 1 回答
- 0 关注
- 209 浏览
添加回答
举报
0/150
提交
取消