我在传递多个组合框值时遇到问题。例如,我有4个combox,只要我选择第一个,其他3个应该有相应的值。但现在什么都没有,请指教。我附加了xamlcode和c#代码。感谢
<navigation:Page x:Class="Survey.Views.Survey"
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"
mc:Ignorable="d"
xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"
d:DesignWidth="800" d:DesignHeight="513"
Title="Survey Page" xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk">
<Grid x:Name="LayoutRoot" Height="508" Width="800">
<ScrollViewer HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Auto">
<Image x:Name="Logo" Source="/Survey;component/Images/TES2Banner_test.png" Margin="0,0,0,380" Stretch="Fill"></Image>
</ScrollViewer>
<TextBlock Height="23" HorizontalAlignment="Left" Margin="44,145,0,0" Name="textBlock1" Text="Course" VerticalAlignment="Top" />
<TextBlock Height="23" HorizontalAlignment="Left" Margin="44,187,0,0" Name="textBlock2" Text="Location" VerticalAlignment="Top" />
<TextBlock Height="23" HorizontalAlignment="Left" Margin="44,229,0,0" Name="textBlock3" Text="Facilitator1" VerticalAlignment="Top" />
<TextBlock Height="23" HorizontalAlignment="Left" Margin="44,271,0,0" Name="textBlock4" Text="Facilitator2" VerticalAlignment="Top" />
<ComboBox Height="23" HorizontalAlignment="Left" Margin="221,141,0,0" Name="cmbxCourse" SelectionChanged="cmbxCourse_SelectionChanged_1" VerticalAlignment="Top" Width="422" />
<ComboBox Height="23" HorizontalAlignment="Left" Margin="221,183,0,0" Name="cmbxLocation" VerticalAlignment="Top" Width="422" />
<ComboBox Height="23" HorizontalAlignment="Left" Margin="221,229,0,0" Name="cmbxFacilitator1" VerticalAlignment="Top" Width="422" />
<ComboBox Height="23" HorizontalAlignment="Left" Margin="221,271,0,0" Name="cmbxFacilitator2" VerticalAlignment="Top" Width="422" />
<TextBlock Height="51" HorizontalAlignment="Left" Margin="12,345,0,0" Name="textBlock5" Text="Did not meet the expectation" VerticalAlignment="Top" TextWrapping="Wrap" Width="67" />
<RadioButton Content="RadioButton" Height="16" HorizontalAlignment="Left" Margin="101,356,0,0" Name="radioButton1" VerticalAlignment="Top" />
<RadioButton Content="RadioButton" Height="16" HorizontalAlignment="Right" Margin="0,356,491,0" Name="radioButton2" VerticalAlignment="Top" />
<RadioButton Content="RadioButton" Height="16" HorizontalAlignment="Right" Margin="0,355,369,0" Name="radioButton3" VerticalAlignment="Top" />
<RadioButton Content="RadioButton" Height="16" HorizontalAlignment="Left" Margin="468,355,0,0" Name="radioButton4" VerticalAlignment="Top" />
<TextBlock Height="40" HorizontalAlignment="Left" Margin="710,345,0,0" Name="textBlock6" Text="Exceeds expectation" VerticalAlignment="Top" TextWrapping="Wrap" Width="66" />
<TextBlock Height="20" HorizontalAlignment="Left" Margin="12,319,0,0" Name="textBlock7" Text="1. How did he prepare and manage the learning enviroment" VerticalAlignment="Top" Width="357" />
<TextBlock Height="21" HorizontalAlignment="Left" Margin="12,402,0,0" Name="textBlock8" Text="2. How did he prepare and manage the learning enviroment" VerticalAlignment="Top" Width="335" />
<TextBlock Height="54" HorizontalAlignment="Left" Margin="12,429,0,0" Name="textBlock9" Text="Did not meet the expectation" VerticalAlignment="Top" TextWrapping="Wrap" Width="67" />
<RadioButton Content="RadioButton" Height="16" HorizontalAlignment="Left" Margin="101,440,0,0" Name="radioButton5" VerticalAlignment="Top" />
<RadioButton Content="RadioButton" Height="16" HorizontalAlignment="Left" Margin="221,440,0,0" Name="radioButton6" VerticalAlignment="Top" />
<RadioButton Content="RadioButton" Height="16" HorizontalAlignment="Left" Margin="343,440,0,0" Name="radioButton7" VerticalAlignment="Top" />
<RadioButton Content="RadioButton" Height="16" HorizontalAlignment="Left" Margin="468,440,0,0" Name="radioButton8" VerticalAlignment="Top" />
<RadioButton Content="RadioButton" Height="17" HorizontalAlignment="Left" Margin="588,355,0,0" Name="radioButton9" VerticalAlignment="Top" Width="97" />
<RadioButton Content="RadioButton" Height="16" HorizontalAlignment="Left" Margin="588,440,0,0" Name="radioButton10" VerticalAlignment="Top" />
<TextBlock Height="34" HorizontalAlignment="Right" Margin="0,429,24,0" Name="textBlock10" Text="Exceeds expectation" VerticalAlignment="Top" TextWrapping="Wrap" Width="66" />
</Grid>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Navigation;
命名空间Survey.Views { 公共部门班调查:Page { 公共调查() { 的InitializeComponent(); this.Loaded + = new RoutedEventHandler(Survey_Loaded); }
void Survey_Loaded(object sender, RoutedEventArgs e)
{
List<Course> list = new List<Course>
{
new Course{ CourseName = "3G Traning" ,Locations = GetLocation(),Facilitator1 = GetFacilitator1(),Facilitator2 = GetFacilitator2()},
// new Course{ CourseName = "4G Traning", Location =new List<Location>(),Facilitator1 =new List<Facilitator1>(),Facilitator2 = new List<Facilitator2>()},
//new Course{ CourseName = "ASP.Net Traning", Location = new List<Location>(),Facilitator1 = new List<Facilitator1>(),Facilitator2 = new List<Facilitator2>()},
};
cmbxCourse.ItemsSource = list;
cmbxCourse.DisplayMemberPath = "CourseName";
}
private List<Location> GetLocation()
{
List<Location> list = new List<Location>
{
new Location{ Name = "HQ" },
new Location{ Name = "NE" },
new Location{ Name = "MW" },
new Location{ Name = "SO" },
new Location{Name = "WE" }
};
return list;
}
private List<Facilitator1> GetFacilitator1()
{
List<Facilitator1> list = new List<Facilitator1>
{
new Facilitator1{Name = "Jay Makowski"},
new Facilitator1{Name = "Kemmico Jones"},
new Facilitator1{Name = "Luann Fennick"},
new Facilitator1{Name = "Paul Conklin"},
new Facilitator1{Name = "Henry Farmer"},
};
return list;
}
private List<Facilitator2> GetFacilitator2()
{
List<Facilitator2> list = new List<Facilitator2>
{
new Facilitator2{Name = "Sarah Sidewell"},
new Facilitator2{Name = "Denice Bello"},
new Facilitator2{Name = "Carla Warner"},
new Facilitator2{Name = "Sarah Edmond"},
new Facilitator2{Name = "Eric Green"},
};
return list;
}
private void CmbxCourse_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
var cmbx = sender as ComboBox;
var selectedItem = cmbx.SelectedItem as Course;
cmbxLocation.ItemsSource = selectedItem.Locations;
cmbxLocation.DisplayMemberPath = "Name";
cmbxFacilitator1.ItemsSource = selectedItem.Facilitator1;
cmbxFacilitator1.DisplayMemberPath = "Name";
cmbxFacilitator2.ItemsSource = selectedItem.Facilitator2;
cmbxFacilitator2.DisplayMemberPath = "Name";
}
private void cmbxCourse_SelectionChanged_1(object sender, SelectionChangedEventArgs e)
{
}
}
public class Course
{
public string CourseName { get; set; }
public List<Location> Locations { get; set; }
public List<Facilitator1> Facilitator1 { get; set; }
public List<Facilitator2> Facilitator2 { get; set; }
}
public class Location
{
public string Name { get; set; }
}
public class Facilitator1
{
public string Name { get; set; }
}
public class Facilitator2
{
public string Name { get; set; }
}
}
enter code here