question

yugandharlakkaraju-9535 avatar image
0 Votes"
yugandharlakkaraju-9535 asked DaisyTian-1203 commented

WPF Combobox editor style binding is not working

I have the following xaml code.

I am trying to bind custom class UnitCategory to combo box.

But seems to be there is an issue in code.


 <Grid>
     <Grid.Resources>
         <local:ComboSourceConverter x:Key="cscconv" />
    
         <Style x:Key="UnitCategoryStyle" TargetType="{x:Type igEditors:XamComboEditor}">
             <Setter Property="ItemsSource" Value="{Binding Path=DataContext.UnitCategories, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}}" />
             <Setter Property="SelectedItem" Value ="{Binding Path=DataItem.UnitCategory}" />
             <Setter Property="DisplayMemberPath" Value="Name" />
         </Style>
            
         <Style x:Key="UnitStyle" TargetType="{x:Type igEditors:XamComboEditor }">
             <Setter Property="ItemsSource" Value="{Binding Path=DataItem.UnitCategory, Converter={StaticResource cscconv}}" />
         </Style>
    
     </Grid.Resources>
     <igWPF:XamDataGrid DataSource="{Binding data}" CellChanged="XamDataGrid_CellChanged">
         <igWPF:XamDataGrid.FieldLayoutSettings>
             <igWPF:FieldLayoutSettings AutoGenerateFields="False" />
         </igWPF:XamDataGrid.FieldLayoutSettings>
         <igWPF:XamDataGrid.FieldLayouts>
             <igWPF:FieldLayout>
                 <igWPF:FieldLayout.Fields>
                     <igWPF:Field Name="Item"></igWPF:Field>
                     <igWPF:Field Name="UnitCategory">
                         <igWPF:Field.Settings>
                             <igWPF:FieldSettings EditorStyle="{StaticResource UnitCategoryStyle}" />
                         </igWPF:Field.Settings>
                     </igWPF:Field>
                     <igWPF:Field Name="Unit">
                         <igWPF:Field.Settings>
                             <igWPF:FieldSettings EditorStyle="{StaticResource UnitStyle}" />
                         </igWPF:Field.Settings>
                     </igWPF:Field>
                 </igWPF:FieldLayout.Fields>
             </igWPF:FieldLayout>
         </igWPF:XamDataGrid.FieldLayouts>
     </igWPF:XamDataGrid>
 </Grid>

Following view model. Here Unit category is not binding. Drop down in combo box is not showing. Is there any binding issue?


  public class ViewModel : INotifyPropertyChanged
 {
     public ObservableCollection<DataModel> data { get; set; }
     public List<UnitCategory> UnitCategories { get; set; }
     public static List<string> WeightUnits { get; set; }
     public static List<string> DistanceUnits { get; set; }
    
     public ViewModel()
     {
         this.data = new ObservableCollection<DataModel>();
    
         this.UnitCategories = new List<UnitCategory>();
    
         UnitCategory u1 = new UnitCategory();
         u1.Name = "Wt";
    
         UnitCategory u2 = new UnitCategory();
         u2.Name = "Dt";
    
    
         this.UnitCategories.Add(u1);
         this.UnitCategories.Add(u2);
    
    
    
         WeightUnits = new List<string>()
         {
             "mg",
             "g",
             "kg"
         };
    
         DistanceUnits = new List<string>()
         {
             "cm",
             "m",
             "km"
         };
    
         DataModel data1 = new DataModel();
         data1.Item = "Item 1";
          
         DataModel data2 = new DataModel();
         data2.Item = "Item 2";
     
         this.data.Add(data1);
         this.data.Add(data2);
     }
    
     public event PropertyChangedEventHandler PropertyChanged;
     protected void OnPropertyChanged([CallerMemberName] string propertyName = "")
     {
         if (PropertyChanged != null)
             PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
     }
 }
    
 public class DataModel 
 {
     public string Item { get; set; }
     public UnitCategory UnitCategory { get; set; }
     public string Unit { get; set; }
    
     public DataModel()
     {
     }
 }
    
 public class UnitCategory
 {
     public string Name { get; set; }
 }




windows-wpf
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@yugandharlakkaraju-9535
I can't reproduce your error based on your code. What does your igWPF refer to? Could you provide infos for igWPF , XamDataGrid and ComboSourceConverter ? Please provide the related code for me to make a demo to analyze the issue.

0 Votes 0 ·

0 Answers