WPF中怎么才能实现combobox显示多行而不是单行,help!!!!!
wpf吧
全部回复
仅看楼主
level 8
圣诞节df 楼主
想了好几天了,不会啊,-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------谁来救救我-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
2015年05月16日 14点05分 1
level 8
圣诞节df 楼主
<Window x:Class="Binding.Window2"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window2" Height="300" Width="300">
<Window.Resources>
<DataTemplate x:Key="ST_TP">
<Border BorderBrush="Black" BorderThickness="1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<StackPanel Orientation="Horizontal">
<TextBlock Width="80" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Text="{Binding Id}"/>
<TextBlock Width="80" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Text="{Binding Name}"/>
<TextBlock Width="80" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Text="{Binding Grade}"/>
</StackPanel>
</Border>
</DataTemplate>
</Window.Resources>
<Grid>
<DataGrid AutoGenerateColumns="False" CanUserAddRows="True" Height="200" Name="dataGrid1" Width="280" HorizontalAlignment="Left">
<DataGrid.Columns>
<DataGridComboBoxColumn x:Name="h1" Header="Id" Width="100" ItemsSource="{Binding ListSource}">
<DataGridComboBoxColumn.EditingElementStyle>
<Style TargetType="ComboBox">
<Setter Property="ItemTemplate" Value="{StaticResource ResourceKey=ST_TP}"></Setter>
<Setter Property="ItemsSource" Value="{Binding ListSource}"></Setter>
</Style>
</DataGridComboBoxColumn.EditingElementStyle>
</DataGridComboBoxColumn>
<DataGridTextColumn Header="Name" Width="100" Binding="{Binding Name}"></DataGridTextColumn>
<DataGridTextColumn Header="Grade" Width="100" Binding="{Binding Grade}"></DataGridTextColumn>
</DataGrid.Columns>
</DataGrid>
</Grid>
</Window>
2015年05月21日 14点05分 4
level 8
圣诞节df 楼主
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
namespace Binding
{
/// <summary>
/// Window2.xaml 的交互逻辑
/// </summary>
public partial class Window2 : Window
{
public class ST
{
public int Id { get; set; }
public string Name { get; set; }
public string Grade { get; set; }
}
List<ST> ListSource = new List<ST>()
{
new ST(){ Id =101,Name="S1",Grade="G2"},
new ST(){ Id =102,Name="S2",Grade="G1"},
new ST(){ Id =103,Name="S3",Grade="G4"},
new ST(){ Id =104,Name="S4",Grade="G3"},
};
public Window2()
{
InitializeComponent();
List<ST> list = new List<ST>();
this.dataGrid1.ItemsSource = list;
this.h1.ItemsSource = ListSource;
}
}
}
2015年05月21日 14点05分 5
level 8
圣诞节df 楼主
如果我用DataTemplate感觉很难把选择的数据填入表格中
2015年05月21日 14点05分 6
level 8
圣诞节df 楼主
选择后第一列:填Id,第二列填:Name第三列填Grade
2015年05月21日 14点05分 7
level 8
圣诞节df 楼主
2015年05月21日 14点05分 8
1