我在另一个应用程序中使用了media元素来播放具有相同实现的视频,并且它按预期工作但每当我将控件放入我的Avalon dock数据模板时,我收到此错误消息“名称'VideoControl'不存在于VideoControl.Play()
上的当前上下文,即使在同一个应用程序中,我将控件置于Avalon停靠栏标签之外,按预期工作。
<DockPanel Name="df" Grid.Row="2" FlowDirection="LeftToRight" LastChildFill="True" SnapsToDevicePixels="True" WindowChrome.ResizeGripDirection="TopLeft">
<avalonDock:DockingManager x:Name="dockManager" AnchorablesSource="{Binding Tools}" DocumentsSource="{Binding Files}" ActiveContent="{Binding ActiveDocument, Mode=TwoWay, Converter={StaticResource ActiveDocumentConverter}}" DockPanel.Dock="Left" Grid.Row="2" BorderBrush="Black" BorderThickness="1">
<avalonDock:DockingManager.LayoutItemTemplateSelector>
<localController:PanesTemplateSelector>
<localController:PanesTemplateSelector.PreviewViewTemplate>
<DataTemplate>
<StackPanel>
<MediaElement Canvas.Left="20" Canvas.Top ="40" x:Name= "VideoControl" LoadedBehavior="Manual" UnloadedBehavior="Stop" ></MediaElement>
<Button Height="23" HorizontalAlignment="Left" Margin="15,0,0,13" Name="PlayButton" VerticalAlignment="Bottom" Width="75" Click="PlayClick">Play</Button>
<Button Height="23" HorizontalAlignment="Left" Margin="103,0,0,13" Name="PauseButton" VerticalAlignment="Bottom" Width="75" Click="PauseClick">Pause</Button>
<Button Height="23" Margin="191,0,186,13" Name="StopButton" VerticalAlignment="Bottom" Click="StopClick">Stop</Button>
</StackPanel>
</DataTemplate>
</localController:PanesTemplateSelector.PreviewViewTemplate>
</localController:PanesTemplateSelector>
</avalonDock:DockingManager.LayoutItemTemplateSelector>
</avalonDock:DockingManager>
</DockPanel>
C#Class:
public class PanesTemplateSelector : DataTemplateSelector
{
public DataTemplate PreviewViewTemplate
{
get;
set;
}
#endregion
#region Template Selection
public override System.Windows.DataTemplate SelectTemplate(object item, System.Windows.DependencyObject container)
{
//Creates a new collection of layout content
var itemAsLayoutContent = item as LayoutContent;
if (item is PreviewViewModel)
return PreviewViewTemplate;
//Returns selected template
return base.SelectTemplate(item, container);
}
#endregion
}
答案 0 :(得分:0)
这不是预期的行为吗?按名称访问datatemplate中的控件很棘手。使用
or
检索您的控件