0
我的XAML代碼是如何在Silverlight中使用C#在DataTemplate中的值中獲取ComboBox的選定值?
<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;
不工作..