【发布时间】:2018-08-04 20:49:28
【问题描述】:
请看下面的代码。我试图在同一个datagrid 中显示两个不同的列表。在我的FormulaUploadViewModel 中,我有两个不同的列表需要在datagrid 中实现。 datagrid 中的DataGridTextColumn 将从SelectedData 列表中获取值,comboBox 将从PersonList 中获取值。我设置了DataContext="{DynamicResource FormulaUploadViewModel}。谢谢。
<UserControl x:Class="SSM.Formulas.FormulaUploadView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:SSM.Formulas"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
mc:Ignorable="d"
MinWidth="800"
d:DataContext="{DynamicResource FormulaUploadViewModel}">
<TextBox Margin="10" Grid.Row="2" Grid.Column="0" Text="{Binding PersonId, Delay=500, UpdateSourceTrigger=PropertyChanged}" MaxLength="4">
<DataGrid x:Name="selectGrid" Grid.Row="0" Grid.RowSpan="2" Grid.Column="1" ItemsSource="{Binding SelectedData}"
AutoGenerateColumns="false" CanUserAddRows="False" IsReadOnly="True" MinHeight="700">
<DataGrid.Columns>
<DataGridTextColumn Header="Flow Value" Binding="{Binding point}" />
<DataGridTextColumn Header="Dev-Code" Binding="{Binding code}" />
<DataGridTemplateColumn Header="Solvent">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<ComboBox ItemsSource="{Binding PersonList}" DisplayMemberPath="PersonCode" SelectedItemBinding="{Binding PersonCode, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
</Grid>
public class FormulaUploadViewModel : INotifyPropertyChanged
{
public FormulaUploadViewModel()
{
SelectedData = new List<Data>();
PersonList = new List<PersonList>();
PersonId=100;
}
public long PersonId { get; set; }
}
【问题讨论】:
-
另外,我正在尝试从 SelectedData 显示组合的选定项,从 PersonList 显示 itemsource。
-
请清楚说明您的代码似乎有什么问题!你没有得到你所期望的?
标签: c# wpf data-binding wpf-controls wpfdatagrid