的我有以下XAML一個TreeView
:獲取位置選擇樹型視圖
<TreeView ItemsSource="{Binding Folders, UpdateSourceTrigger=PropertyChanged}" x:Name="tree">
<TreeView.InputBindings>
<KeyBinding Key="Delete"
Command="{Binding DataContext.DeleteFolderCommand, RelativeSource={RelativeSource FindAncestor, AncestorType=UserControl}}"
CommandParameter="{Binding ElementName=tree, Path=SelectedItem}"/>
<KeyBinding Key="F2"
Command="{Binding DataContext.RenameFolderCommand, RelativeSource={RelativeSource FindAncestor, AncestorType=UserControl}}"
CommandParameter="{Binding ElementName=tree, Path=SelectedItem}"/>
</TreeView.InputBindings>
<TreeView.ItemTemplate>
<HierarchicalDataTemplate ItemsSource="{Binding Folders, UpdateSourceTrigger=PropertyChanged}">
<Grid>
<Label Content="{Binding Name}">
<Label.ContextMenu>
<ContextMenu>
<MenuItem Header="Rename"
Command="{Binding DataContext.RenameFolderCommand, RelativeSource={RelativeSource FindAncestor, AncestorType=UserControl}}"
CommandParameter="{Binding ElementName=tree, Path=SelectedItem}"/>
<MenuItem Header="Delete"
Command="{Binding DataContext.DeleteFolderCommand, RelativeSource={RelativeSource FindAncestor, AncestorType=UserControl}}"
CommandParameter="{Binding ElementName=tree, Path=SelectedItem}"/>
</ContextMenu>
</Label.ContextMenu>
<Label.InputBindings>
<MouseBinding MouseAction="LeftDoubleClick"
Command="{Binding DataContext.SelectFolderCommand, RelativeSource={RelativeSource FindAncestor, AncestorType=UserControl}}"
CommandParameter="{Binding ElementName=tree, Path=SelectedItem}" />
</Label.InputBindings>
</Label>
</Grid>
</HierarchicalDataTemplate>
</TreeView.ItemTemplate>
</TreeView>
在上重命名一個點擊(或按下F2)上TreeViewItem
我想用一個TextBox
更換標籤。
這樣做的最好方法是什麼?
我已經試圖獲得TreeView
的SelectedItem的Position
或Bounds
,但這是Folder的一個實例,所以我無法在那裏獲取信息。
你可以使用'Control'並在'Style'中設置'Template'。在樣式中,您可以使用具有適合條件的內容的「ControlTemplate」。 HTH – XAMlMAX 2014-09-26 14:11:52