WPF中怎么才能实现combobox显示多行而不是单行,help!!!!!
wpf吧
全部回复
仅看楼主
level 8
圣诞节df 楼主
想了好几天了,不会啊,-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------谁来救救我-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
2015年05月16日 14点05分 1
level 5
下拉框不是用来单选的么?多行就没意义了吧?!
2015年05月17日 00点05分 2
打错了,是多列,不是多行
2015年05月17日 00点05分
@圣诞节df 试试用DataContext
2015年05月17日 00点05分
回复异性恋恐惧症:哦哦,能不能说详细点,我在群上也问过有人说用combobox里面套DataGrid
2015年05月17日 00点05分
回复
ʥ����df
:说错了, 不是DataContext, 应该是DataTemplate. 下面给个相关例子给你, 不过是ListBox的.
2015年05月17日 02点05分
level 5
下面是我以前写的一个界面, 里面就有应用到DataTemplate.
关于DataTemplate, 你可以百度一下.
除了DataTemplate, 你还可以用ControlTemplate, 不过DataTemplate更轻量.
<UserControl x:Class="PB.View.MainView"
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"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300" >
<UserControl.Resources>
<DataTemplate x:Key="listItemTemplate" DataType="ListBoxItem">
<Border BorderBrush="Blue" BorderThickness="1" CornerRadius="3">
<StackPanel HorizontalAlignment="Stretch">
<StackPanel.ToolTip>
<StackPanel Background="#FFADD14D">
<TextBlock Text="描述:"/>
<TextBlock Text="{Binding Path=Remarks}"/>
</StackPanel>
</StackPanel.ToolTip>
<StackPanel Orientation="Horizontal">
<TextBlock Text="用户名:" Margin="5"/>
<TextBlock Text="{Binding Path=UserName}" Margin="5"/>
</StackPanel>
<StackPanel Orientation="Horizontal">
<TextBlock Text="密码:" Margin="5"/>
<TextBlock Text="{Binding Path=Password}" Margin="5"/>
</StackPanel>
</StackPanel>
</Border>
</DataTemplate>
</UserControl.Resources>
<DockPanel>
<ListBox Name="ListInformation" MaxHeight="500" MinHeight="50"
ItemTemplate="{StaticResource listItemTemplate}">
</ListBox>
</DockPanel>
</UserControl>
    在棒子的游戏里追求平衡的人都是脑子有病...~
2015年05月17日 02点05分 3
好的,那我下午看看,三Q啦[笑眼]
2015年05月17日 03点05分
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