|
Il presente articolo è stato tradotto manualmente. Passare il puntatore sulle frasi nell'articolo per visualizzare il testo originale.
|
Traduzione
Originale
|
How to: Create a ListView with Editable Cells
public class EditBox : Control { ... public static readonly DependencyProperty ValueProperty = DependencyProperty.Register( "Value", typeof(object), typeof(EditBox), new FrameworkPropertyMetadata(null)); ... public static DependencyProperty IsEditingProperty = DependencyProperty.Register( "IsEditing", typeof(bool), typeof(EditBox), new FrameworkPropertyMetadata(false)); ... }
<Style x:Key="{x:Type l:EditBox}" TargetType="{x:Type l:EditBox}" > <Setter Property="HorizontalAlignment" Value="Left" /> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type l:EditBox}"> <TextBlock x:Name="PART_TextBlockPart" Text="{Binding Path=Value,RelativeSource = {RelativeSource TemplatedParent}}"> </TextBlock> </ControlTemplate> </Setter.Value> </Setter> </Style>
internal sealed class EditBoxAdorner : Adorner { ... public EditBoxAdorner(UIElement adornedElement, UIElement adorningElement): base(adornedElement) { _textBox = adorningElement as TextBox; Debug.Assert(_textBox != null, "No TextBox!"); _visualChildren = new VisualCollection(this); BuildTextBox(); } ... }
public class EditBox : Control { ... protected override void OnMouseUp(MouseButtonEventArgs e) { base.OnMouseUp(e); if (e.ChangedButton == MouseButton.Right || e.ChangedButton == MouseButton.Middle) return; if (!IsEditing) { if (!e.Handled && (_canBeEdit || _isMouseWithinScope)) { IsEditing = true; } //If the first MouseUp event selects the parent ListViewItem, //then the second MouseUp event puts the EditBox in editing //mode if (IsParentSelected) _isMouseWithinScope = true; } } ... }
public class EditBox : Control { ... protected override void OnMouseEnter(MouseEventArgs e) { base.OnMouseEnter(e); if (!IsEditing && IsParentSelected) { _canBeEdit = true; } } ... protected override void OnMouseLeave(MouseEventArgs e) { base.OnMouseLeave(e); _isMouseWithinScope = false; _canBeEdit = false; } ... }
<GridViewColumn Header="ID" Width="50" > <GridViewColumn.CellTemplate> <DataTemplate> <l:EditBox Height="25" Value="{Binding Path=EmployeeNumber}" /> </DataTemplate> </GridViewColumn.CellTemplate> </GridViewColumn>