C# 带ItemsSource的WPF组合框-我应该设置什么路径来访问此数据绑定?
在XAML中设置绑定/路径属性时遇到问题 我知道这个组合框的C# 带ItemsSource的WPF组合框-我应该设置什么路径来访问此数据绑定?,c#,wpf,xaml,data-binding,combobox,C#,Wpf,Xaml,Data Binding,Combobox,在XAML中设置绑定/路径属性时遇到问题 我知道这个组合框的ItemSource属性正在正确更新,因为我在更新viewmodel时得到了一堆空文本框(而不是我所期望的带有文本的文本框) 因此,我认为组合框的DataTemplate部分中的绑定需要不同的绑定路径,但我不确定要将绑定路径设置为什么 <ComboBox ItemsSource="{Binding Path=Locations}" Visibility="{Binding SettingsOptionsVisibility}" G
ItemSource
属性正在正确更新,因为我在更新viewmodel
时得到了一堆空文本框(而不是我所期望的带有文本的文本框)
因此,我认为组合框的DataTemplate
部分中的绑定需要不同的绑定路径,但我不确定要将绑定路径设置为什么
<ComboBox ItemsSource="{Binding Path=Locations}" Visibility="{Binding SettingsOptionsVisibility}" Grid.Column="0" x:Name="locationCB" VerticalAlignment="Top" SelectionChanged="locationCB_SelectionChanged" HorizontalAlignment="Left" Width="350" Height="30" IsHitTestVisible="False" IsEnabled="False" Focusable="False">
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Name}"></TextBlock>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
将位置对象的字段更改为属性:
public class Location
{
public Guid LocationID { get; set; }
public Guid ParentID { get; set; }
public String Name { get; set; }
public bool isValid { get; set; }
}
将位置对象的字段更改为属性:
public class Location
{
public Guid LocationID { get; set; }
public Guid ParentID { get; set; }
public String Name { get; set; }
public bool isValid { get; set; }
}
将位置对象的字段更改为属性:
public class Location
{
public Guid LocationID { get; set; }
public Guid ParentID { get; set; }
public String Name { get; set; }
public bool isValid { get; set; }
}
将位置对象的字段更改为属性:
public class Location
{
public Guid LocationID { get; set; }
public Guid ParentID { get; set; }
public String Name { get; set; }
public bool isValid { get; set; }
}
您应该绑定到属性,而不是变量。而不是
public string Name;
您应该将上述内容更改为
public string Name {get;set;}
更好的是,可以实现INotifyPropertyChanged..您应该绑定到属性而不是变量。而不是
public string Name;
您应该将上述内容更改为
public string Name {get;set;}
更好的是,可以实现INotifyPropertyChanged..您应该绑定到属性而不是变量。而不是
public string Name;
您应该将上述内容更改为
public string Name {get;set;}
更好的是,可以实现INotifyPropertyChanged..您应该绑定到属性而不是变量。而不是
public string Name;
您应该将上述内容更改为
public string Name {get;set;}
更好的是,可以实现INotifyPropertyChanged..是否
Name
是在Location
类中定义的属性?发布代码。去掉
元素,它应该只是itemtemplateRohit中的一个文本框,Post,yes;Netscape,完成了,但出现了相同的问题。您已将IsitTestVisible
和IsEnabled
设置为false。您似乎无法打开组合框。@John-如前所述,Name
应该是属性,而不是字段。将字段转换为属性,它将正常工作。Name
是在Location
类中定义的属性吗?发布代码。去掉
元素,它应该只是itemtemplateRohit中的一个文本框,Post,yes;Netscape,完成了,但出现了相同的问题。您已将IsitTestVisible
和IsEnabled
设置为false。您似乎无法打开组合框。@John-如前所述,Name
应该是属性,而不是字段。将字段转换为属性,它将正常工作。Name
是在Location
类中定义的属性吗?发布代码。去掉
元素,它应该只是itemtemplateRohit中的一个文本框,Post,yes;Netscape,完成了,但出现了相同的问题。您已将IsitTestVisible
和IsEnabled
设置为false。您似乎无法打开组合框。@John-如前所述,Name
应该是属性,而不是字段。将字段转换为属性,它将正常工作。Name
是在Location
类中定义的属性吗?发布代码。去掉
元素,它应该只是itemtemplateRohit中的一个文本框,Post,yes;Netscape,完成了,但出现了相同的问题。您已将IsitTestVisible
和IsEnabled
设置为false。您似乎无法打开组合框。@John-如前所述,Name
应该是属性,而不是字段。将字段转换为属性将正常工作。您可能希望将Location
实现INotifyPropertyChanged
以及字段和属性设置为不同的内容。get代码>和设置代码>语法创建具有默认支持字段的属性。WPF不绑定到字段。您可能希望使位置
实现INotifyPropertyChanged
以及字段和属性是不同的东西。get代码>和设置代码>语法创建具有默认支持字段的属性。WPF不绑定到字段。您可能希望使位置
实现INotifyPropertyChanged
以及字段和属性是不同的东西。get代码>和设置代码>语法创建具有默认支持字段的属性。WPF不绑定到字段。您可能希望使位置
实现INotifyPropertyChanged
以及字段和属性是不同的东西。get代码>和设置代码>语法创建具有默认支持字段的属性。WPF不绑定到字段。