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>
<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"
<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>
</StackPanel>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
<
ComboBox x:Name
=
"
ComboNewsSortName
"
Style
=
"
{StaticResource ComboBoxStyle1}
"
ItemsSource
=
"
{Binding}
"
DisplayMemberPath
=
"
NewsSortName
"
SelectedValuePath
=
"
NewsSortID
"
>
</ ComboBox >
</ 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
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); // 赋值
int inewsSortID = Convert.ToInt32(newsInfoRow[ " NewsSortIDParamerter " ]);
ComboNewsSortName.SelectedValue = inewsSortID; // 取值
NewsDomain newsInfo = new NewsDomain();
newsInfo.NewsSortID = Convert.ToInt32(ComboNewsSortName.SelectedValue); // 赋值
#endregion