开发者

WPF ListView that supports inline edit?

Is there a open source WPF control that looks lik开发者_开发问答e ListView and supports inline edit? More specifically, a cell in the ListView should be editable when you double click on it, and the edit result should be automatically saved unless you hit ESC afterwards.


I don't know of any WPF controls that do what you are looking for, but that is not indication that they don't exist. If you checkout the WPF Toolkit on Codeplex, you may find something and there are a lot of OSS projects for WPF controls on Codeplex in addition to the toolkit.

You can create one very easily taking advantage of the WPF content control model. Here is an example of a ListBox with a set of controls used to represent the objects bound to the list.

<ListBox x:Name="sampleListBox" 
         Width="500">
    <ListBox.ItemTemplate>
        <DataTemplate>
            <Grid>
                <GridRowDefinitions>
                   <RowDefinition Height="25"/>
                   <RowDefinition Height="25"/> 
                </GridRowDefinitions>
                <TextBox Grid.Row="0" Source="{Binding EditableProperty1}}"/>
                <TextBox Grid.Row="1" Source="{Binding EditableProperty2}"/>
            </Grid>
        </DataTemplate>
    </ListBox.ItemTemplate>
</ListBox>

You can control the editability of the controls with Styles so that when the ListBox item is selected, the internal controls are editable but otherwise, they are not. I don't have access to my work laptop atm so I can't provide a style example but there are a lot of materials on the web that can help you. And if you have Expression Blend 4, it has a lot of functionality that can really help you when you are styling your own controls.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜