I have a ListBox of Dockpanels which display "FieldName:, [ _ ____] (user input textbox) ". After the user populates the field, I'm looking for a LINQ way to take the pairs and throw them into a KeyValuePair object.
<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);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.