深入探索Silverlight中的样式、行为与触发器
1. 动作类代码及容器查找方法
在处理媒体播放时,我们需要找到合适的布局容器来添加媒体元素。以下是相关代码:
media.MediaFailed += delegate
{
container.Children.Remove(media);
};
// Add the MediaElement and begin playback.
media.AutoPlay = true;
container.Children.Add(media);
为了找到合适的容器,我们可以使用 FindContainer() 方法,该方法使用 VisualTreeHelper 从当前元素开始向上遍历元素层次结构:
private Panel FindContainer()
{
FrameworkElement element = this.AssociatedObject;
// Search for some sort of panel where the MediaElement can be inserted.
while (element != null)
{
if (element is Panel) return (Panel)element;
element = VisualTreeHel
超级会员免费看
订阅专栏 解锁全文


被折叠的 条评论
为什么被折叠?



