积极答复者
Visual 未连接到 PresentationSource

问题
答案
-
你好,
>>Visual 未连接到 PresentationSource
在WPF中,一个视图Visual元素需要 PresentationSource去呈现,这个问题可能的情形是这个Visual还没有完全呈现出来,导致你做的操作抛出异常
>>窗口中有一个 Tabcontral ,从一个tabItem 点击到另一个tabItem 时,在当前的tabItem要获取某个控件的属性值
因为你没有提供代码,在我的示例中,对一个TabControl添加 SelectionChanged事件处理,在其中调用Control.PointToScreen()方法,会出现你提到的错误。
为了解决这个问题,我们可以对TabItem 添加 GotFocus事件处理:
<TabControl> <TabItem Header="Tab1"> <Image Name="image1" Source="Build.png" /> </TabItem> <TabItem Header="Tab2" GotFocus="TabItem_GotFocus"> <Image Name="image2" Source="Folder.png" /> </TabItem> </TabControl>
private void TabItem_GotFocus(object sender, RoutedEventArgs e) { Point screenTopLeft = image2.PointToScreen(new Point(0, 0)); }
可以看到能正常得到你要的结果:
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.- 已建议为答案 Leo (Apple) YangModerator 2014年9月27日 8:39
- 已标记为答案 Franklin ChenMicrosoft employee, Moderator 2014年10月2日 9:43
全部回复
-
你好,
>>Visual 未连接到 PresentationSource
在WPF中,一个视图Visual元素需要 PresentationSource去呈现,这个问题可能的情形是这个Visual还没有完全呈现出来,导致你做的操作抛出异常
>>窗口中有一个 Tabcontral ,从一个tabItem 点击到另一个tabItem 时,在当前的tabItem要获取某个控件的属性值
因为你没有提供代码,在我的示例中,对一个TabControl添加 SelectionChanged事件处理,在其中调用Control.PointToScreen()方法,会出现你提到的错误。
为了解决这个问题,我们可以对TabItem 添加 GotFocus事件处理:
<TabControl> <TabItem Header="Tab1"> <Image Name="image1" Source="Build.png" /> </TabItem> <TabItem Header="Tab2" GotFocus="TabItem_GotFocus"> <Image Name="image2" Source="Folder.png" /> </TabItem> </TabControl>
private void TabItem_GotFocus(object sender, RoutedEventArgs e) { Point screenTopLeft = image2.PointToScreen(new Point(0, 0)); }
可以看到能正常得到你要的结果:
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.- 已建议为答案 Leo (Apple) YangModerator 2014年9月27日 8:39
- 已标记为答案 Franklin ChenMicrosoft employee, Moderator 2014年10月2日 9:43
-
谢谢,我试了一下,确实如是这样,非常感谢!
您好,
如果我的回复解决了您的问题,请标记下答案,谢谢:)
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.