具有TreeView ContextMenu目标的Caliburn Micro不存在

时间:2013-11-25 08:33:02

标签: wpf telerik treeview contextmenu caliburn.micro

似乎(来自其他有类似问题的帖子)我试图将目标绑定到同一个可视树中不存在的元素。我在TreeView的第3级有一个ContextMenu,我试图设置一个动作来通过父元素的标签(TextBlock)在ViewModel上执行一个方法,但是无法使它工作。

XAML是:

<HierarchicalDataTemplate x:Key="FeatureTemplate">
    <Grid HorizontalAlignment="Stretch"> 
    <TextBlock Text="{Binding Name}" Tag="{Binding DataContext, RelativeSource={RelativeSource Self}}">
        <telerik:RadContextMenu.ContextMenu >
        <telerik:RadContextMenu cal:Action.TargetWithoutContext="{Binding Path=PlacementTarget.Tag, RelativeSource={RelativeSource Self}}"
         cal:Message.Attach="[Event Opened] = [Action ContextMenuOpened($source)]">               
        <telerik:RadMenuItem Header="Export" cal:Message.Attach="[Event Click]=[Action ContextMenuClick($source)]"/>
        </telerik:RadContextMenu>
        </telerik:RadContextMenu.ContextMenu>
    </TextBlock>
</Grid>
</HierarchicalDataTemplate>

<HierarchicalDataTemplate 
x:Key="FormTemplate" 
ItemTemplate="{StaticResource FeatureTemplate}" 
ItemsSource="{Binding List}">
<Grid>
    <Grid.ColumnDefinitions>
    <ColumnDefinition Width="Auto"/>
    <ColumnDefinition Width="*"/>
    </Grid.ColumnDefinitions>
    <Image Source="{Binding Image}" Width="32" Height="32" HorizontalAlignment="Right" Margin="0,3"/>
    <TextBlock Grid.Column="1" Text="{Binding Name}" VerticalAlignment="Center" Margin="5"/>
</Grid>
</HierarchicalDataTemplate>

<HierarchicalDataTemplate  
    x:Key="JobTemplate"  
ItemTemplate="{StaticResource FormTemplate}" 
ItemsSource="{Binding List}">
<TextBlock Text="{Binding Name}"/>
</HierarchicalDataTemplate>

<telerik:RadTreeView Name="TreeView1" 
 Grid.Row="2" 
 cal:Message.Attach="[Event SelectionChanged] = [Action SetSelectedItem($this.SelectedItem)]" 
 Background="White" 
 ItemsSource="{Binding AvailableData}" 
 ItemTemplate="{StaticResource JobTemplate}" 
 telerik:AnimationManager.IsAnimationEnabled="False" >
</telerik:RadTreeView>

ViewModel代码:     public void ContextMenuOpened(FrameworkElement source){}

我收到了找不到ContextMenuOpened目标的错误。 任何帮助或建议将不胜感激。

0 个答案:

没有答案