我使用WPF(C#).
I use WPF (C #).
我希望用户能够编辑列"说明»":
I want the user to be able to edit the column «Description»:
<ListView> <ListView.View> <GridView> <GridViewColumn Header="Name" DisplayMemberBinding="{Binding Path=Name}"></GridViewColumn> <GridViewColumn Header="Number" DisplayMemberBinding="{Binding Path=Number}"></GridViewColumn> <GridViewColumn Header="Description" > <GridViewColumn.CellTemplate> <DataTemplate> <TextBlock Text="{Binding Path=Description}" TextWrapping="Wrap" Margin="0"></TextBlock> </DataTemplate> </GridViewColumn.CellTemplate> </GridViewColumn> </GridView> </ListView.View> </ListView>请告诉我,如何使列说明"可编辑?
为此目的,最好使用另一个控件?什么?
May be better to use another control for this purpose? What?
推荐答案为GridViewColumn.CellTemplate创建一个名为EditBox的自定义控件.
Create a customized control called EditBox for GridViewColumn.CellTemplate.
在正常模式下,TextBlock用于显示内容. 在编辑模式下,将弹出一个文本框进行编辑.
In Normal mode, a TextBlock is used to display content; In Editing mode, a TextBox will pop up for editing.
从Control继承的类
Class inhertied from Control
在ListView中编辑
public class EditBox : Control { static EditBox() { public static readonly DependencyProperty ValueProperty = DependencyProperty.Register( "Value", typeof(object), typeof(EditBox), new FrameworkPropertyMetadata()); }为IsEditing添加依赖项属性.
Add a dependency Property for IsEditing.
public static DependencyProperty IsEditingProperty = DependencyProperty.Register( "IsEditing", typeof(bool), typeof(EditBox), new FrameworkPropertyMetadata(false) );自定义EditBox的样式:
Style for the Custom EditBox:
<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>在您的Xaml中,您可以放置EditBox:
In your Xaml, you can place the EditBox:
<GridViewColumn Header="Description" > <GridViewColumn.CellTemplate> <DataTemplate> <i:EditBox> </DataTemplate> </GridViewColumn.CellTemplate> </GridViewColumn>更多推荐
如何使列在ListView中可编辑?
发布评论