WPF => CollectionViewSource bilan binding ContextMenu

Bu nima uchun ishlaydi:

<button x:Name="btnCritereAdd" Content="{Binding Source={x:Static resx:resMain.lblCriterAdd}}" Style="{StaticResource btnStandardClr}" Click="btnMenuPopup_Click" ContextMenuService.Placement="Bottom">
    <button.ContextMenu>
        
            
                
            
            
                
            
        
    
</button>

Ammo bu emas:

<button x:Name="btnCritereAdd" Content="{Binding Source={x:Static resx:resMain.lblCriterAdd}}" Style="{StaticResource btnStandardClr}" Click="btnMenuPopup_Click" ContextMenuService.Placement="Bottom">
    <button.ContextMenu>
        
            
                
            
            
                
            
            
                
            
        
    
</button>

DataContext ni CodeBehind da tugmachasini o'rnatdim:

btnCritereAdd.DataContext = vmFiltresChamps;

Ikkala holatda "UpdateSourceTrigger = PropertyChanged" va "NotifyOnSourceUpdated = True" bilan harakat qildim, lekin hech narsa o'zgarmaydi. Ro'yxat bo'sh ...

Fikringiz bormi?

VM tomoni: Mulk:

public ItemCollection CriteresDispo { get { return _CriteresDispo; } set { _CriteresDispo = value; RaisePropertyChanged(nameof(CriteresDispo)); } }

Kod orqasida chaqirgan buyruq

public RelayCommand LoadCriteresCommand { get; set; }

private void LoadCriteres(ItemCollection obj) {
        var ht = new tblFiltreChamps();
        Classes.clsUtils.GetFiltresSel(obj, ht);
        CriteresDispo = new ItemsControl().Items;
        if (ht.items.Count > 0) {
            foreach (var item in ht.items.OrderBy((x) => x.Desc).ToList()) {
                var mi = new MenuItem() { Header = item.Desc, Tag = item };
                mi.Command = AddCritereCommand;
                mi.CommandParameter = item;
                CriteresDispo.Add(mi);
            }
        }
        if (CriteresAddAction != null) CriteresAddAction();
}
1
bu xato Source = "{Binding CriteresDispo}" bo'lsa, uning o'rniga CollectionViewSource Source = "{Binding CriteresDispo.View}" ni ishlating
qo'shib qo'ydi muallif MikeT, manba
Bundan tashqari, siz bog'lashingiz kerak bo'lgan vaqtning 99,9999999% kodidagi ma'lumotlar kontekstini o'rnatasiz
qo'shib qo'ydi muallif MikeT, manba
Bundan tashqari, siz bog'lashingiz kerak bo'lgan vaqtning 99,9999999% kodidagi ma'lumotlar kontekstini o'rnatasiz
qo'shib qo'ydi muallif MikeT, manba
Bundan tashqari, siz bog'lashingiz kerak bo'lgan vaqtning 99,9999999% kodidagi ma'lumotlar kontekstini o'rnatasiz
qo'shib qo'ydi muallif MikeT, manba
VM kodingizni savolga qo'shing
qo'shib qo'ydi muallif MikeT, manba
VM kodingizni savolga qo'shing
qo'shib qo'ydi muallif MikeT, manba
VM kodingizni savolga qo'shing
qo'shib qo'ydi muallif MikeT, manba
bu xato Source = "{Binding CriteresDispo}" bo'lsa, uning o'rniga CollectionViewSource Source = "{Binding CriteresDispo.View}" ni ishlating
qo'shib qo'ydi muallif MikeT, manba
CollectionViewSourceni tugmachalar manbaiga ko'chirishni harakat qilib ko'ring, manba ingl. Daraxtni yuqoriga ko'tarib, gorizontal terish o'zgacha ko'rinishi mumkin, bajarilmasa, sizning chiqish oynangizni majburiy xatolar tekshiradi
qo'shib qo'ydi muallif MikeT, manba
bu xato Source = "{Binding CriteresDispo}" bo'lsa, uning o'rniga CollectionViewSource Source = "{Binding CriteresDispo.View}" ni ishlating
qo'shib qo'ydi muallif MikeT, manba
gorizontal qidirish ingl. daraxtning bir xil darajasida belgilangan resurslarni qidiradi
qo'shib qo'ydi muallif MikeT, manba
gorizontal qidirish ingl. daraxtning bir xil darajasida belgilangan resurslarni qidiradi
qo'shib qo'ydi muallif MikeT, manba
gorizontal qidirish ingl. daraxtning bir xil darajasida belgilangan resurslarni qidiradi
qo'shib qo'ydi muallif MikeT, manba
CollectionViewSourceni tugmachalar manbaiga ko'chirishni harakat qilib ko'ring, manba ingl. Daraxtni yuqoriga ko'tarib, gorizontal terish o'zgacha ko'rinishi mumkin, bajarilmasa, sizning chiqish oynangizni majburiy xatolar tekshiradi
qo'shib qo'ydi muallif MikeT, manba
Ushbu xabarni chiqdim: "System.Windows.Data Error: 5: BindingExpression tomonidan ishlab chiqarilgan qiymat maqsadli obyekt uchun tegishli emas; Value = 'System.Windows.Controls.ItemCollection' BindingExpression: Yo'l = Kritik qiymatlar; DataItem = 'ViewModelFiltresChamp '(HashCode = 6263136);' Object '(HashCode = 6263136);' CollectionViewSource '(HashCode = 56403320);
qo'shib qo'ydi muallif david, manba
Ushbu xabarni chiqdim: "System.Windows.Data Error: 5: BindingExpression tomonidan ishlab chiqarilgan qiymat maqsadli obyekt uchun tegishli emas; Value = 'System.Windows.Controls.ItemCollection' BindingExpression: Yo'l = Kritik qiymatlar; DataItem = 'ViewModelFiltresChamp '(HashCode = 6263136);' Object '(HashCode = 6263136);' CollectionViewSource '(HashCode = 56403320);
qo'shib qo'ydi muallif david, manba
Ushbu xabarni chiqdim: "System.Windows.Data Error: 5: BindingExpression tomonidan ishlab chiqarilgan qiymat maqsadli obyekt uchun tegishli emas; Value = 'System.Windows.Controls.ItemCollection' BindingExpression: Yo'l = Kritik qiymatlar; DataItem = 'ViewModelFiltresChamp '(HashCode = 6263136);' Object '(HashCode = 6263136);' CollectionViewSource '(HashCode = 56403320);
qo'shib qo'ydi muallif david, manba
Yaxshi fikr, lekin bu emas. System.Windows.Data xatosi: 40: BindingExpression yo'l xatosi: 'Object' '(HashCode = 52346362)' ob'ektida topilmadi 'View' xususiyati. BindingExpression: Yo'l = KriterlarDispo.View; DataItem = 'ViewModelFiltresChamps' (HashCode = 40764587); maqsad element "CollectionViewSource" (HashCode = 36662967); target xususiyati "Source" ("Ob'ektni" turi). ItemCollection obyekti "View" xususiyati yo'q
qo'shib qo'ydi muallif david, manba
Yaxshi fikr, lekin bu emas. System.Windows.Data xatosi: 40: BindingExpression yo'l xatosi: 'Object' '(HashCode = 52346362)' ob'ektida topilmadi 'View' xususiyati. BindingExpression: Yo'l = KriterlarDispo.View; DataItem = 'ViewModelFiltresChamps' (HashCode = 40764587); maqsad element "CollectionViewSource" (HashCode = 36662967); target xususiyati "Source" ("Ob'ektni" turi). ItemCollection obyekti "View" xususiyati yo'q
qo'shib qo'ydi muallif david, manba
Yaxshi fikr, lekin bu emas. System.Windows.Data xatosi: 40: BindingExpression yo'l xatosi: 'Object' '(HashCode = 52346362)' ob'ektida topilmadi 'View' xususiyati. BindingExpression: Yo'l = KriterlarDispo.View; DataItem = 'ViewModelFiltresChamps' (HashCode = 40764587); maqsad element "CollectionViewSource" (HashCode = 36662967); target xususiyati "Source" ("Ob'ektni" turi). ItemCollection obyekti "View" xususiyati yo'q
qo'shib qo'ydi muallif david, manba
Salom MikeT, men allaqachon button.resource ni qo'ydim, lekin hech narsa o'zgarmaydi. Landshaft qidirish nima?
qo'shib qo'ydi muallif david, manba
Salom MikeT, men allaqachon button.resource ni qo'ydim, lekin hech narsa o'zgarmaydi. Landshaft qidirish nima?
qo'shib qo'ydi muallif david, manba

6 javoblar

Fikringiz bormi?

PropertyChanged hodisasini Manba ga bog'laydigan xususiyat uchun StaticResource ga bog'lashda, maqsad funktsiyasi yangilanmaydi, CollectonViewSource xususiyatini tekshiring.

Bu farq.

Yangilash uchun ItemsSource to'plami uchun ushbu xususiyat uchun xususiyatiga bog'lang va PropertyChanged hodisasini ko'taring.

0
qo'shib qo'ydi

Fikringiz bormi?

PropertyChanged hodisasini Manba ga bog'laydigan xususiyat uchun StaticResource ga bog'lashda, maqsad funktsiyasi yangilanmaydi, CollectonViewSource xususiyatini tekshiring.

Bu farq.

Yangilash uchun ItemsSource to'plami uchun ushbu xususiyat uchun xususiyatiga bog'lang va PropertyChanged hodisasini ko'taring.

0
qo'shib qo'ydi

Fikringiz bormi?

PropertyChanged hodisasini Manba ga bog'laydigan xususiyat uchun StaticResource ga bog'lashda, maqsad funktsiyasi yangilanmaydi, CollectonViewSource xususiyatini tekshiring.

Bu farq.

Yangilash uchun ItemsSource to'plami uchun ushbu xususiyat uchun xususiyatiga bog'lang va PropertyChanged hodisasini ko'taring.

0
qo'shib qo'ydi

CollectionViewSource does not implement IEnumerable, and therefore cannot be set to the ItemsSource property of a ContextMenu, which is of type IEnumerable.

Shuning uchun siz o'zgartirishingiz kerak:


    

Kimga:


    

This will set the ItemsSource to the CollectionViewSource's View property, which is of type CollectionView and does implement IEnumerable

0
qo'shib qo'ydi

CollectionViewSource does not implement IEnumerable, and therefore cannot be set to the ItemsSource property of a ContextMenu, which is of type IEnumerable.

Shuning uchun siz o'zgartirishingiz kerak:


    

Kimga:


    

This will set the ItemsSource to the CollectionViewSource's View property, which is of type CollectionView and does implement IEnumerable

0
qo'shib qo'ydi

CollectionViewSource does not implement IEnumerable, and therefore cannot be set to the ItemsSource property of a ContextMenu, which is of type IEnumerable.

Shuning uchun siz o'zgartirishingiz kerak:


    

Kimga:


    

This will set the ItemsSource to the CollectionViewSource's View property, which is of type CollectionView and does implement IEnumerable

0
qo'shib qo'ydi