2014-05-08 70 views
0

我正在寻找链接ListBox中的选定项目上的笔记列与文本框。这个想法是当用户点击列表视图中的某个项目时,他们可以更改关于该项目的注释。稍后,我可以在保存时使用针对此项目保存的注释。笔记标题是隐藏的。WPF链接列表查看与文本框选定的项目

正如您在下面的图片中看到的,我已经选择了列表中的项目,并且所有选定的值都通过了文本框。

  1. 我只希望AttachmentNotes才能通过
  2. 我希望能够改变这些笔记,然后将更新所选项目的结合。

enter image description here

下面是我的WPF代码:

   <ListView x:Name="LstAttachments" HorizontalAlignment="Left" Height="137" Margin="10,83,0,0" VerticalAlignment="Top" Width="641"> 
        <ListView.View> 
         <GridView> 
          <GridViewColumn Header="Attachment Name" Width="400" DisplayMemberBinding="{Binding AttachmentName}"/> 
          <GridViewColumn Header="" Width="0" DisplayMemberBinding="{Binding AttachmentPath}"/> 
          <GridViewColumn Header="Attachment Type" Width="237" DisplayMemberBinding="{Binding AttachmentType}"/> 
          <GridViewColumn Header="Notes" Width="0" DisplayMemberBinding="{Binding AttachmentNotes}"/> 
         </GridView> 
        </ListView.View> 
       </ListView> 
       <TextBox x:Name="TxtAttachmentNotes" Text="{Binding SelectedValue, ElementName=LstAttachments}" HorizontalAlignment="Left" Height="133" Margin="10,235,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="641" SpellCheck.IsEnabled="True" MaxLength="25000"/> 

项目添加到ListView像这样:

//Display the File Name and Type in the ListBox 
LstAttachments.Items.Add(new { AttachmentName = RibbonTest.attfilename, AttachmentPath = RibbonTest.attfilename, AttachmentType = RibbonTest.attfiletype, AttachmentNotes = "Test Notes Blah Blah" }); 

所有帮助深表感谢。 :)

谢谢

+1

正如你在我试图用绑定文本框ListView控件选择的值的示例代码中看到并带回所有的值。我知道我可以将它设置为TwoWay来保存信息。不过,我只想能够编辑AttachmentNotes值 – LiveKarma

回答

0

您需要更新您的数据源,甚至适当。所以也许改变文本框中的文本?例如关于texchange更新附件提示

+0

我已经考虑过这一点,但我不使用数据源。列表视图中的每个项目都是使用变量单独添加的。我已经添加了一个如何将数据添加到我的问题底部的ListView的示例。 – LiveKarma

+0

这听起来像你没有帮助自己。如果您不存储信息,您希望如何更新信息的来源? – Coops

1

我可能误解了你的问题,但似乎解决方案非常简单。您曾说过,您使用SelectedValueGridView中获取适当的选定项目,但您只想使用该项目中的一个属性。当然,你可以通过使用它的名字像这样引用您所需的属性:

<TextBox x:Name="TxtAttachmentNotes" Text="{Binding SelectedValue.AttachmentNotes, 
    ElementName=LstAttachments}" HorizontalAlignment="Left" Height="133" 
    Margin="10,235,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="641" 
    SpellCheck.IsEnabled="True" MaxLength="25000"/> 
+0

这正是我想要做的:)但是,这不会带回任何数据,我不认为你可以用Binding这样做。 – LiveKarma

+0

*我不认为你可以用Binding这样做*你当然可以,虽然我不知道为什么结果是空的...尝试使用'ListView.SelectedItem'属性而不是' SelectedValue'属性,因为它真的与'SelectedValuePath'属性结合使用。 – Sheridan

相关问题