我试图在组合框中定义所选项目。如果我只是使用String来声明所选项而不是使用对象,那么它工作正常。
<ComboBox HorizontalAlignment="Left"
VerticalAlignment="Top" Width="81" materialDesign:HintAssist.Hint="Woche" Margin="10"
ItemsSource="{Binding weekSelection}"
DisplayMemberPath="name"
SelectedItem="{Binding nodeWeek, Mode=TwoWay}"
SelectedValue="name" />
-
private week _nodeWeek;
public week nodeWeek
{
get
{
return _nodeWeek;
}
set
{
_nodeWeek = value;
RaisePropertyChanged("nodeWeek");
}
}
-
public class week
{
public int val { get; set; }
public String name { get; set; }
}
- 设置所选项目
this.nodeWeek = new week() { val = times.GetIso8601WeekOfYear(DateTime.Now), name = "KW " + times.GetIso8601WeekOfYear(DateTime.Now).ToString() };
有没有办法解决这个问题?
答案 0 :(得分:2)
所选项目必须始终是您的商品来源列表之一。您无法创建新对象并将其分配给SelectedItem
。 Combobox只是比较对象引用而不是内容。