可编辑WPF的ListView [英] Editable WPF ListView
问题描述
我想作一个的ListView
编辑时,在一个项目的用户双击。我认识到,有许多样品在那里在网络上,但是,这些都是根据 IsSelected
属性,而不是在处理双击事件。
I'd like to make a ListView
editable when the user double clicks on an item. I realize that there are many samples out there on the web, however, these are all based on the IsSelected
property, and not on handling the double-click event.
任何意见或指针?
更新:的
所以另外一个问题,我已经是,我怎么能问题得到了控制数据模板中的的ListViewItem
?当我迷路是我需要去的控制,并启用或禁用控制的基础上,项目是否被编辑或不是问题的关键。
UPDATE:
So one other problem that I have is, how can I get to the controls in the data template for the ListViewitem
in question? Where I'm getting lost is the point where I need to get to the controls, and either enable or disable the control, based on whether the item is being edited or not.
目前,在的ListView
数据模板看起来是这样的:
Currently, the ListView
data template looks like this:
<DataTemplate>
<Grid>
<TextBlock Width="180" Text="{Binding Path=Description}"
Style="{StaticResource GridBlockStyle}" />
<TextBox Width="180" Text="{Binding Path=Description}"
Style="{StaticResource GridEditStyle}" />
</Grid>
</DataTemplate>
的样式被引用的是这样的:
The styles being referenced look like this:
<Window.Resources>
<Style TargetType="{x:Type TextBlock}" x:Key="GridBlockStyle">
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="Visibility" Value="{Binding Path=IsSelected,
RelativeSource={RelativeSource FindAncestor,
AncestorType={x:Type ListViewItem}},
Converter={StaticResource boolToVis},
ConverterParameter=False}" />
</Style>
<Style TargetType="{x:Type FrameworkElement}" x:Key="GridEditStyle">
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="Visibility" Value="{Binding Path=IsSelected,
RelativeSource={RelativeSource FindAncestor,
AncestorType={x:Type ListViewItem}},
Converter={StaticResource boolToVis},
ConverterParameter=True}" />
</Style>
</Window.Resources>
在 BoolToVisibilityConverter
是转换为的ListViewItem $的
IsSelected
属性C $ C>,然后确定一个ListViewItem的能见度
。
The BoolToVisibilityConverter
is the converter for the IsSelected
property of the ListViewItem
, which then determines the Visibility
of the ListViewItem.
你可以从目前的XAML标记看,编辑控件将激活(可见)在项目选择,而不是项目双击。
As you can see from the current XAML markup, the edit controls will activate (become visible) on item selection, not item double-click.
更新2:的 所有的建议至今让我只能解决一半的方式。有没有人有如何访问我需要显示/隐藏实际控制可行的解决方案?我将标志着这个答案的解决方案!
UPDATE 2: All the suggestions so far bring me to only half the way of the solution. Does anyone have a workable solution for how to access the actual controls that I need to make visible/invisible? I will mark that answer as the solution!
推荐答案
如果你在一个MVVM模式,你可能想看看AttachedProperties和行为,而不是事件处理程序,以避免在code写作code后面。
If you are in a MVVM pattern you may want to look at AttachedProperties and behaviors rather than event handlers to avoid writing code in your code behind.
HTTP://www.$c$cproject.com/KB/ WPF / AttachedBehaviors.aspx
的http://blog.fossmo.net/post/How-to-create-an-attached-property-in-WPF-using-a-ComboBox.aspx
http://msdn.microsoft.com/en-us/library/ ms749011.aspx
这篇关于可编辑WPF的ListView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!