[英]DataTemplate to Linq
I have a ListBox of Dockpanels which display "FieldName:, [ _ ____] (user input textbox) ". 我有一个Dockpanels的列表框,其中显示“ FieldName:,[ _ ____] (用户输入文本框) ”。 After the user populates the field, I'm looking for a LINQ way to take the pairs and throw them into a KeyValuePair object.
用户填充字段后,我正在寻找一种LINQ方式来将对放入并将其放入KeyValuePair对象。
<DataTemplate x:Key="ExtraLoginInfoTemplate">
<DockPanel>
<TextBlock Name="CodeID" Text="{Binding Path=ID,Converter={BLL:CodeMarkupExtension}}" />
<TextBox Name="Input"/>
</DockPanel>
</DataTemplate>
<ListBox Name="extraLoginInfoListBox" ItemsSource="{Binding}" ItemTemplate="{StaticResource ExtraLoginInfoTemplate}"/>
//codebehind
extraLoginInfoListBox.DataContext = cvList; //list of codevalue objects
private void submitButton_click(object sender, RoutedEventArgs e)
{
KeyValuePair<string,string> myInputs = /* ? some linq query to get the data from extraLoginInfoListBox */
}
You need a property to be bound with your Input textbox to store whatever value was entered by user: 您需要一个属性与“ 输入”文本框绑定,以存储用户输入的任何值:
<TextBox Name="Input" Text="{Binding Path=IDValue, Mode=TwoWay}" />
And then, you can use following code: 然后,您可以使用以下代码:
var keyValuePairs = cvList.ToDictionary((obj) => obj.ID, (obj) => obj.IDValue);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.