I created a simple ListBoxItemStyle that contains a TextBox with its Visibility set to Collapsed and a trigger based on the ListBoxItem Tag property being set to True which sets the TextBox Visibility to Visible. Then in the Click event for the button I set its Tag value to True. But when I click the button and set the Tag Value to True nothing happens. If I change the Trigger to be IsSelected instead of Tag the edit works each time I click on an item in the Listbox. But I want to only have the edit active if I click the Button.
I don't know what I am doing wrong?
<Style x:Key="ListBoxItemStyle1" TargetType="{x:Type ListBoxItem}"><Setter Property="Background" Value="Transparent"/><Setter Property="HorizontalContentAlignment" Value="{Binding HorizontalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/><Setter Property="VerticalContentAlignment" Value="{Binding VerticalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/><Setter Property="Padding" Value="2,0,0,0"/><Setter Property="Template"><Setter.Value><ControlTemplate TargetType="{x:Type ListBoxItem}"><Grid><Border x:Name="Bd" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Padding="{TemplateBinding Padding}" SnapsToDevicePixels="true"><ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/></Border><TextBox x:Name="EditableText" LostFocus="RenameLostFocus" Visibility="Collapsed"/></Grid><ControlTemplate.Triggers><Trigger Property="IsSelected" Value="true"><Setter Property="Background" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}"/><Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.HighlightTextBrushKey}}"/></Trigger><MultiTrigger><MultiTrigger.Conditions><Condition Property="IsSelected" Value="true"/><Condition Property="Selector.IsSelectionActive" Value="false"/></MultiTrigger.Conditions><Setter Property="Background" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"/><Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/></MultiTrigger><Trigger Property="IsEnabled" Value="false"><Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/></Trigger><Trigger Property="Tag" Value="true"><Setter TargetName="EditableText" Property="Visibility" Value="Visible" /><Setter TargetName="EditableText" Property="Text" Value="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Content}"/></Trigger></ControlTemplate.Triggers></ControlTemplate></Setter.Value></Setter></Style>
I then bind the Tag property of the ListBoxItem to the Button Tag Property
<ListBox ItemsSource="{StaticResource MyFiles}" ItemContainerStyle="{DynamicResource ListBoxItemStyle1}"><ListBox.Resources><Style TargetType="{x:Type ListBoxItem}"><Setter Property="Tag" Value="{Binding Path=Tag,ElementName=bt_RENAME}"/></Style></ListBox.Resources></ListBox>
<Button x:Name="bt_RENAME" Content="RENAME" Click="bt_Rename" />
Private Sub bt_Rename(sender as Object, e as RoutedEventArgs)sender.Tag = True End Sub
Jeff Davis