ComboBox控件数据绑定

ComboBox控件Silverlight3里和Silverlight4里的属性是不一样的,在Silverlight4里使用。

<UserControl xmlns:aui="clr-namespace:CRM.Class"
xmlns:my="clr-namespace:CRM.UserControls" > //添加用户控件的引用 和RowIndexConverter类的引用
    <UserControl.Resources>
        <aui:RowIndexConverter x:Key="RowIndex"></aui:RowIndexConverter>
    </UserControl.Resources>
<Grid x:Name="LayoutRoot" Background="#FFE8E8E8">
<ComboBox x:Name="combCardType"  Grid.Row="0" Grid.Column="1">
       <ComboBox.ItemTemplate>
            <DataTemplate>
                <StackPanel x:Name="myStackPanel" Orientation="Horizontal"  >
                     <TextBlock Name="lblCardTypeName" VerticalAlignment="Center" HorizontalAlignment="Center"
                                Text="{Binding Converter={StaticResource RowIndex}, ConverterParameter=CT_Name}" />
                     <TextBlock Name="lblCardTypeID" VerticalAlignment="Center" HorizontalAlignment="Center" 
                                Text="{Binding Converter={StaticResource RowIndex}, ConverterParameter=CT_ID}" />
                 </StackPanel>
             </DataTemplate>
        </ComboBox.ItemTemplate>
 </ComboBox>
< ComboBox x:Name = " ComboNewsSortName "  Style = " {StaticResource ComboBoxStyle1} "  ItemsSource = " {Binding} "  DisplayMemberPath = " NewsSortName "  SelectedValuePath = " NewsSortID " >
</ ComboBox >
</Grid>
</UserControl>

Cs

private ObservableCollection<Row> rowResult;
  #region 选出所有卡类型
        void CwIntegralCard_SelectCardTypeCompleted(object sender, SelectCardTypeCompletedEventArgs e)
        {
            combCardType.ItemsSource = null;
            rowResult = new ObservableCollection<Row>();
            Row LogRow = new Row();
            foreach (CardTypeDomain v in e.Result)
            {
                LogRow["CT_Name"] = v.CTName;
                LogRow["CT_ID"] = v.CTID;
                rowResult.Add(LogRow);
            }
            combCardType.ItemsSource = rowResult;            
        }
  #endregion

  #region 选出所有新闻类型
ComboNewsSortName.DataContext  =  e.Result;    // 数据源绑定
int  inewsSortID  =  Convert.ToInt32(newsInfoRow[ " NewsSortIDParamerter " ]);
ComboNewsSortName.SelectedValue 
=  inewsSortID;  // 取值
NewsDomain newsInfo 
=   new  NewsDomain();
newsInfo.NewsSortID 
= Convert.ToInt32(ComboNewsSortName.SelectedValue);  // 赋值
  #endregion
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值