如果使用C#在DataTemplate中获取值,如何在Silverlight中获取ComboBox的选定值?

时间:2015-02-07 10:13:01

标签: c# silverlight

  

我的XAML代码是

<ComboBox  x:Name="ComboBoxTemplateCategory" Grid.Column="3" Grid.Row="2" SelectedValuePath="Text"  ItemsSource="{Binding}" >
                <ComboBox.ItemTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal">
                            <TextBlock Margin="5,0,0,0" Text="{Binding Path=TemplateName}" Width="100"/>
                        </StackPanel>
                </DataTemplate>
                </ComboBox.ItemTemplate>
            </ComboBox>

  

C#代码

string mySelectedValue = ((TextBlock)((ComboBoxItem)
ComboBoxTemplateCategory.SelectedItem).Content).Text;

不工作..

1 个答案:

答案 0 :(得分:0)

string SelectedValue =((BulkEmailNew.BulkEmailService.TemplateCategory)(ComboBoxTemplateCategory.SelectedItem))。TemplateName;