#WPF# binding 動態資源

目的:針對下拉框控件,每次使用都會查詢後臺數據,獲取最新的選項

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}}"/>
               

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章