What is the best way to implement Rename functionality from a context menu in WPF?, What I want is functionality like Windows Explorer where you right click on an item, get a context menu, and if you select rename, the text becomes editable.

So far I've tried the following, but I think there must be a better way. Pretty much any aspect of this solution can be changed :)

```
<ListBox Grid.Row="0" MinWidth="200" MinHeight="75" ItemsSource="{Binding Path=DataSetsVM.DataSets, Source={StaticResource vmLocator}}" x:Name="dataSets">
<ListBox.ItemTemplate>
    <DataTemplate>
        <StackPanel x:Name="nameRoot">
            <TextBlock x:Name="nameBlock" Text="{Binding Path=Name}" HorizontalAlignment="Stretch" MinWidth="200" Tag="{Binding DataContext, ElementName=dataSets}">
            <TextBlock.ContextMenu> 
                <ContextMenu >
                    <ContextMenu.Resources>
                        <Style TargetType="Image">
                            <Setter Property="Height" Value="24"/>
                            <Setter Property="Width" Value="24"/>
                        </Style>
                    </ContextMenu.Resources>
                    <MenuItem Header="Rename" x:Name="RenameDatasetContext"
                              Command="{Binding PlacementTarget.Tag.CoreCommands.RenameDatasetCommand, RelativeSource={RelativeSource AncestorType=ContextMenu}}"
                              CommandParameter="{Binding PlacementTarget.DataContext, 
                              RelativeSource={RelativeSource FindAncestor, 
                              AncestorType={x:Type ContextMenu}}}">
                        <MenuItem.Icon>
                            <Image Source="{StaticResource RenameLargeIcon}"/>
                        </MenuItem.Icon>
                    </MenuItem>
                </ContextMenu>
            </TextBlock.ContextMenu>
            </TextBlock>
            <TextBox x:Name="nameBox"  Text="{Binding Path=Name}" HorizontalAlignment="Stretch" MinWidth="200" Visibility="Collapsed" />
        </StackPanel>
        <DataTemplate.Triggers>                                            
            <DataTrigger Binding="{Binding Path=IsEditable}" Value="True">
                <Setter TargetName="nameBlock" Property="Visibility" Value="Collapsed"/>
                <Setter TargetName="nameBox" Property="Visibility" Value="Visible"/>
            </DataTrigger>
        </DataTemplate.Triggers>
    </DataTemplate>
</ListBox.ItemTemplate> 
</ListBox>

```

The setter for Name does this:

```
set
{
    if (IsEditable)
    {
        IsEditable = false;   
        if (_name == value)
        {
            RaisePropertyChanged(NamePropertyName);
            return;
        }
        // Do some back end stuff
        if (back end stuff worked)
        {
            var oldValue = _name;
            _name = value;
            RaisePropertyChanged(NamePropertyName);
        }
        else
        {
            // Do something about the error in the back end
        }
    }   
}

```

All the command does is set IsEditable to true.

This works unless you don't actually change the name, at which point there's nothing that sets IsEditable back as the setter for Name never gets called, so you can wind up with a bunch of items in Rename mode.

Can I set a property on a VM through a trigger, or is there a better way to do this?