请参阅下面的 CustomView 窗口
当我从组合框中选择项目时,与该项目关联的客户端应自动显示在那里。
在 Combobox 的选择更改事件中,我做到了
private string client
{
get
{
return ClientText.Text;
}
set
{
ClientText.Text = value;
}
}
public Harvest_Project projectClass
{
set
{
ProjectText.Text = value.ToString();
Harvest_Project proj = (Harvest_Project)ProjectText.Text; // shows error here. casting is not possible. What can I do here?
this.client = Globals._globalController.harvestManager.getClientEntriesThroughId(proj._client_id)._name;
PropertyChanged(this, new PropertyChangedEventArgs("client"));
}
}
public int project
{
get
{
return int.Parse(ProjectText.Text);
}
set
{
ProjectText.Text = value.ToString();
}
}
private void ProjectComboBoxChanged(object sender, SelectionChangedEventArgs e)
{
if (sender is ComboBoxItem)
{
ComboBoxItem item = (ComboBoxItem)sender;
}
}
在xaml中,我使用了这样的绑定,
<ComboBox x:Name="ProjectText" SelectionChanged="ProjectComboBoxChanged" ItemsSource="{Binding Path=projectList}" SelectedValuePath="_id" DisplayMemberPath="_name" SelectedItem="{Binding ProjectComboBoxChanged, Mode=OneWayToSource}" Background="Yellow" BorderThickness="0" Width="66"/>