首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 媒体动画 > CAD教程 >

silverlight中的datagrid如何内嵌combobox

2012-03-05 
silverlight中的datagrid怎么内嵌combobox?silverlight中的datagrid怎么内嵌combobox,网上看的代码有点复

silverlight中的datagrid怎么内嵌combobox?
silverlight中的datagrid怎么内嵌combobox,网上看的代码有点复杂,请给点精简的代码

[解决办法]

XML code
<data:DataGridTemplateColumn Header="进度" Width="50">    <data:DataGridTemplateColumn.CellTemplate>        <DataTemplate>            <ComboBox ItemsSource="{Binding something}"></ComboBox>        </DataTemplate>    </data:DataGridTemplateColumn.CellTemplate></data:DataGridTemplateColumn>
[解决办法]
XML code
<data:DataGrid x:Name="test"><data:DataGridTemplateColumn Header="进度" Width="50">    <data:DataGridTemplateColumn.CellTemplate>        <DataTemplate>            <ComboBox ItemsSource="{Binding something}"></ComboBox>        </DataTemplate>    </data:DataGridTemplateColumn.CellTemplate></data:DataGridTemplateColumn></data:DataGrid>
[解决办法]
XML code
<UserControl x:Class="SilverlightApplication1.MainPage"    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"    xmlns:src="clr-namespace:SilverlightApplication1"    mc:Ignorable="d"    d:DesignHeight="366" d:DesignWidth="617" xmlns:data="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data" xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls">    <UserControl.Resources>        <src:SexProvider x:Key="sexProvider"/>    </UserControl.Resources>    <Grid x:Name="LayoutRoot" Background="White">        <data:DataGrid AutoGenerateColumns="True" Name="dataGrid1" Margin="0,0,0,87" >            <data:DataGrid.Columns>                <data:DataGridTextColumn Header="ID" Binding="{Binding ID}"></data:DataGridTextColumn>                <data:DataGridTextColumn Header="姓名" Binding="{Binding Name}"></data:DataGridTextColumn>                                <data:DataGridTemplateColumn Header="生日">                    <data:DataGridTemplateColumn.CellTemplate>                        <DataTemplate>                            <TextBlock Text="{Binding Birthday}"></TextBlock>                        </DataTemplate>                    </data:DataGridTemplateColumn.CellTemplate>                    <data:DataGridTemplateColumn.CellEditingTemplate>                        <DataTemplate>                            <controls:DatePicker SelectedDate="{Binding Birthday,Mode=TwoWay}"/>                        </DataTemplate>                    </data:DataGridTemplateColumn.CellEditingTemplate>                </data:DataGridTemplateColumn>                <data:DataGridTemplateColumn Header="性别">                    <data:DataGridTemplateColumn.CellTemplate>                        <DataTemplate>                            <TextBlock Text="{Binding Sex}" />                        </DataTemplate>                    </data:DataGridTemplateColumn.CellTemplate>                    <data:DataGridTemplateColumn.CellEditingTemplate>                        <DataTemplate>                            <ComboBox SelectedItem="{Binding Sex, Mode=TwoWay}" ItemsSource="{Binding SexList,Source={StaticResource sexProvider}}">                                                          </ComboBox>                                                    </DataTemplate>                    </data:DataGridTemplateColumn.CellEditingTemplate>                </data:DataGridTemplateColumn>                <data:DataGridTemplateColumn Header="密码">                    <data:DataGridTemplateColumn.CellTemplate>                        <DataTemplate>                            <PasswordBox Password="{Binding Password}"  ></PasswordBox>                        </DataTemplate>                    </data:DataGridTemplateColumn.CellTemplate>                </data:DataGridTemplateColumn>            </data:DataGrid.Columns>        </data:DataGrid>        <Button Content="保存" Height="28" HorizontalAlignment="Left" Margin="136,307,0,0" Name="button1" VerticalAlignment="Top" Width="88" Click="button1_Click" />        <Button Content="删除" Height="28" HorizontalAlignment="Left" Margin="248,307,0,0" Name="button2" VerticalAlignment="Top" Width="88" Click="button2_Click" />        <Button Content="新增" Height="28" HorizontalAlignment="Left" Margin="21,307,0,0" Name="button3" VerticalAlignment="Top" Width="88" Click="button3_Click" />        <PasswordBox Height="23" HorizontalAlignment="Left" Margin="392,307,0,0" Name="passwordBox1" VerticalAlignment="Top" Width="120" Password="" DataContext="{Binding}" />    </Grid></UserControl> 


[解决办法]
注意以下四个代码 
xmlns:src="clr-namespace:SilverlightApplication1"

<UserControl.Resources>
<src:SexProvider x:Key="sexProvider"/>
</UserControl.Resources>

<ComboBox SelectedItem="{Binding Sex, Mode=TwoWay}" ItemsSource="{Binding SexList,Source={StaticResource sexProvider}}">
 
public class SexProvider
{
public List<string> SexList
{
get
{
return new List<string> { "男", "女"};
}
}
}

热点排行