【发布时间】:2011-07-19 23:39:44
【问题描述】:
我只是无法使以下情况起作用: 我有一个类,具有以下实现:
public class SelectionItem<T> : ViewModelBase where T : Entity
{
private bool? _isSelected;
public bool? IsSelected
{
get { return _isSelected; }
set
{
_isSelected = value;
RaisePropertyChanged("IsSelected");
}
}
public T Item { get; set; }
}
我的 ViewModel 上有以下属性:
private IEnumerable<SelectionItem<DB_Aux_Pessoas>> _vendedores;
public IEnumerable<SelectionItem<DB_Aux_Pessoas>> Vendedores
{
get
{
return _vendedores;
}
set
{
_vendedores = value;
RaisePropertyChanged("Vendedores");
}
}
然后,在我的视图中,我有 ComboBox:
<ComboBox Margin="3,0,0,0"
Height="23"
Width="200"
ItemsSource="{Binding Vendedores, Mode=TwoWay}"
Grid.Column="1"
Grid.Row="1"
HorizontalAlignment="Left">
<ComboBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<CheckBox IsChecked="{Binding IsSelected, Mode=TwoWay}" />
<TextBlock Text="{Binding Item.NomeRazaoSocial}" />
</StackPanel>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
但是当我更改 ComboBoxItem 上的 CheckBox 时,它不会反映在属性上。
DB_Aux_Pessoas 的代码如下:
[MetadataTypeAttribute(typeof(DB_Aux_Pessoas.DB_Aux_PessoasMetadata))]
public partial class DB_Aux_Pessoas
{
// This class allows you to attach custom attributes to properties
// of the DB_Aux_Pessoas class.
//
// For example, the following marks the Xyz property as a
// required property and specifies the format for valid values:
// [Required]
// [RegularExpression("[A-Z][A-Za-z0-9]*")]
// [StringLength(32)]
// public string Xyz { get; set; }
internal sealed class DB_Aux_PessoasMetadata
{
// Metadata classes are not meant to be instantiated.
private DB_Aux_PessoasMetadata()
{
}
public Nullable<short> Cliente { get; set; }
public string Id_Numero { get; set; }
public string NomeRazaoSocial { get; set; }
public Nullable<short> Supervisor { get; set; }
public Nullable<short> Vendedor { get; set; }
}
}
我在这里做错了什么? 提前谢谢。
【问题讨论】:
-
肯定还有其他一些细节遗漏,因为我根本无法重现您的错误。您能否提供 DB_Aux_Pessoas 的代码,并且当您说“不反映属性”时,您能否准确地告诉我们您是如何寻找这种变化的?谢谢。
-
嗨,马丁,我已经用 DB_Aux_Pessoas 的代码编辑了问题。问题是我有一个ComboBox,它的ItemsSource是一个SelectionItem的集合,而属性IsSelected是绑定到ComboBox的ItemTemplate的一个CheckBox上的。当我检查 CheckBox 并读取 ItemsSource 的值时,属性 IsSelected 没有更改值。
标签: silverlight binding combobox