Datagrid和组合框 - MVVM和C# [英] Datagrid and combobox - MVVM and C#
问题描述
您好,我正在用c#研究mvvm模式。我有一个问题!
我有一个带有ItemSource(类Order)和SelectedItem(SelectedOrder)的数据网格。
使用select i填充a使用数据网格中的信息形式,但是对于某些值,我需要使用组合框提出一些选择。
组合框的选择不在选定项目中。
如何我可以显示所选数据的详细信息,并让用户可以从价值清单中选择(OPEN,CLOSE,...)。
提前谢谢
我尝试过:
Hello, i'm studying the mvvm pattern with c#. I've a problem!
I have a datagrid with an ItemSource (class "Order") and a SelectedItem ("SelectedOrder").
With a select i fill a form with the information conteined in the datagrid, but for some values i need to proposing some choice with combobox.
The choices of the combobox are not in the selecteditem.
How can I display the detail of my selected article of data and give the possibility to the user to choice from a list of value (OPEN, CLOSE, ...).
Thanks in advance
What I have tried:
This is the view
<pre>
<Grid DataContext="{Binding SelectedOrder}">
...
<Label Content="Customer:" FontSize="12" x:Name="lblState" VerticalAlignment="Top" Grid.Row="2" Grid.Column="2"/>
<ComboBox x:Name="cmbState" FontSize="12" FontWeight="Normal" IsEditable="True" Grid.Row="2" Grid.Column="3" Text="{Binding state,Mode=TwoWay}">
...
</Grid>
<DataGrid ItemsSource="{Binding Order, IsAsync=True}" SelectedItem="{Binding SelectedOrder, Mode=TwoWay}" Grid.Row="3" AutoGenerateColumns="false" CanUserAddRows="False" CanUserSortColumns="True" CanUserResizeRows="False" IsReadOnly="True" SelectionMode="Single" SelectionUnit="FullRow">
<DataGrid.Columns>
<DataGridTextColumn Header="Number" Binding="{Binding numOrder}" Width="1*" />
这是班级订单
This is the class Order
public class Order
{
public int id { get; set; }
public string numOrder { get; set; }
public string title { get; set; }
public string state { get; set; }
public string dateCreation { get; set; }
public string note { get; set; }
}
推荐答案
我做了一个快速的Google搜索: wpf datagrid组合框列绑定mvvm - Google搜索 [ ^ ]
第一个结果是适合您的答案:绑定WPF DataGridComboBoxColumn MVVM - Stack Overflow [ ^ ]
iI did a quick Google Search: wpf datagrid combobox column binding mvvm - Google Search[^]
The first result is a working answer for you: Binding a WPF DataGridComboBoxColumn with MVVM - Stack Overflow[^]
这篇关于Datagrid和组合框 - MVVM和C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!