1
我試圖將所選值綁定到字符串屬性,以便將項目源綁定到枚舉值列表的組合框。但是,所選值不會顯示在組合框中。將Enum值列表綁定爲C#中的ItemSource時,未更新選定值Wpf
public enum FilterOperation
{
Includes,
NotIncludes,
Equals,
NotEquals
}
// Adding the Values to the list in constructor
StringFilterList.Add(FilterOperation.Includes);
StringFilterList.Add(FilterOperation.NotIncludes);
StringFilterList.Add(FilterOperation.Equals);
StringFilterList.Add(FilterOperation.NotEquals);
// Initially assigning first value as default value.
FilterSelected = StringFilterList.FirstOrDefault().ToString();
// XAML.
<ComboBox HorizontalAlignment="Left"
ItemsSource="{Binding StringFilterList}"
SelectedValue="{Binding FilterSelected,UpdateSourceTrigger=PropertyChanged,Mode=TwoWay}"
/>
但是,即使列表已加載,所選值也未列出。
請嘗試解決此問題。