0

Can I set up a trigger that have something like this?

<Style x:Key="ContextMenuSelector" TargetType="{x:Type TreeView}">
    <Style.Triggers>
        <Trigger Property="SelectedItem.Tag" Value="MyTag">
            <Setter Property="ContextMenu" Value="{StaticResource MyTagContextMenu}"><!-- change context menu depending on selected item --></Setter>
        </Trigger>
        <!-- Other triggers depending on the value of the SelectedItem's Tag -->
    </Style.Triggers>
</Style>

I want to be able to change the ContextMenu of the treeview depending on the Tag of the selected item. However the above code doesn't compile because it seems that nested property like Property="SelectedItem.Tag" is not allowed. Any idea?

1
  • check with <Trigger Property="SelectedItem.Tag.ToString()" Value="MyTag"
    – hridya pv
    Nov 21, 2012 at 4:12

1 Answer 1

0

SelectedItem is of type object http://msdn.microsoft.com/en-us/library/system.windows.controls.primitives.selector.selecteditem.aspx but tag is a property on type FrameworkElement. To specify the SelectedItem type try using Property="(FrameworkElement.SelectedItem).Tag"

http://msdn.microsoft.com/en-us/library/ms742451.aspx see section on type-qualified

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.