目的:針對下拉框控件,每次使用都會查詢後臺數據,獲取最新的選項
1.引入引用
xmlns:core="clr-namespace:System;assembly=mscorlib"
2.在cs文件寫下相關查詢方法,如GetPowerIdList方法
public List<int> GetPowerIdList()
{
List<int> IdList=new List<int>();
//todo
return IdList;
}
3.在xaml文件引入資源
<Grid.Resources>
<ObjectDataProvider x:Key="IdList" ObjectType="{x:Type local:CVM}" MethodName="GetPowerIdList" />
</Grid.Resources>
Tips:別忘記引入域Local所在命名空間
4.使用該資源
<DataGridComboBoxColumn Header="權限" SelectedValueBinding="{Binding ExecutableCode }" SelectedItemBinding="{Binding ExecutableCode ,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" ItemsSource="{Binding Source={StaticResource IdList}}"/>