當(dāng)Storyboard關(guān)閉窗口“This Visual is not connected to a PresentationSource”時(shí),我得到了這個(gè)錯(cuò)誤。我的場景包括兩個(gè)窗口和一個(gè) 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貢獻(xiàn)1943條經(jīng)驗(yàn) 獲得超7個(gè)贊
嘗試使用Dispatcher類在消息循環(huán)的下一次迭代中關(guān)閉窗口:
private void CloseLWindow_Completed(object sender, EventArgs e)
{
Dispatcher.BeginInvoke(new Action(() => Close()));
}
- 1 回答
- 0 關(guān)注
- 233 瀏覽
添加回答
舉報(bào)
0/150
提交
取消