我一直在努力使用那些comboBox属性
我正在构建一个主详细信息表单.
我遇到的问题我已经使它工作但我不明白这些属性和差异.是否有一个简单的例子解释他们做了什么?
我的ComboBox中的SelectedItem有问题.
<ComboBox Name="cbxSalesPeriods"
ItemsSource="{Binding SalesPeriods}"
DisplayMemberPath="displayPeriod"
SelectedItem="{Binding SelectedSalesPeriod}"
SelectedValuePath="displayPeriod"
IsSynchronizedWithCurrentItem="True"/>
Run Code Online (Sandbox Code Playgroud)
如果我打开ComboBox,我会看到值.
如果我选择一个项目,则不会显示所选项目.
有人有想法吗?
在我的ViewModel中,我有以下两个属性:
public ObservableCollection<SalesPeriodVM> SalesPeriods { get; private set; }
private SalesPeriodVM selectedSalesPeriod;
public SalesPeriodVM SelectedSalesPeriod
{
get { return selectedSalesPeriod; }
set
{
if (selectedSalesPeriod != value)
{
selectedSalesPeriod = value;
RaisePropertyChanged("SelectedSalesPeriod");
}
}
}
Run Code Online (Sandbox Code Playgroud)
这些是该类的一些属性:
public SalesPeriodVO Vo
{
get { return period; }
}
public int Year
{
get { return period.Year; }
set
{
if (period.Year != value)
{
period.Year …Run Code Online (Sandbox Code Playgroud) 我有两个属性,一个是字符串列表,另一个是字符串.
private List<String> _property;
public List<String> Property
get
{
return new List<string>(){"string1", "string2"};
}
set{_property = value
}
public String SimpleStringProperty{get;set;}
Run Code Online (Sandbox Code Playgroud)
我也有一个在XAML中定义的Combobox
<Combobox ItemsSource="{Binding Property , Mode="TwoWay"}" Text="Select Option" />
Run Code Online (Sandbox Code Playgroud)
现在组合框正确显示两个选项:"string1"和"string2"
当用户选择一个或另一个时,我想设置SimpleStringProperty该值.然而,通过双向绑定从组合框中返回的"值"不是selectedItem,而是List<String>.我怎么能这样做?我对wpf很新,所以请原谅业余爱好者.
我在WPF中使用MVVM模式并遇到了一个问题,我可以将其简化为以下内容:
我有一个CardType模型.
public class CardType
{
public int Id { get; set; }
public string Name { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我有一个使用CardType的viewmodel.
public class ViewModel : INotifyPropertyChanged
{
private CardType selectedCardType;
public CardType SelectedCardType
{
get { return selectedCardType; }
set
{
selectedCardType = value;
OnPropertyChanged(nameof(SelectedCardType));
}
}
public IEnumerable<CardType> CardTypes { get; set; }
// ... and so on ...
}
Run Code Online (Sandbox Code Playgroud)
我的XAML有一个ComboBox,它的项目基于CardTypes,应该根据SelectedCardType预选一个项目.
<ComboBox ItemsSource="{Binding CardTypes}"
DisplayMemberPath="Name"
SelectedItem="{Binding SelectedCardType}"/>
Run Code Online (Sandbox Code Playgroud)
由于我无法控制的原因,SelectedCardType对象将是CardTypes中项目的引用不等份副本.因此,WPF无法将SelectedItem与ItemsSource中的项匹配,当我运行应用程序时,ComboBox最初显示时未选中任何项.
我尝试覆盖CardType上的Equals()和GetHashCode()方法,但WPF仍然无法匹配项目.
鉴于我特有的限制,我如何让ComboBox选择正确的项目?
我们的团队在Winforms和ASP.net项目上工作经验丰富.
正如程序员堆栈交换中的其他程序员一样,建议我为我们团队的下一个项目跳转到WPF,而不是将WinForms用于基于客户端的业务应用程序.
现在我开始使用WPF开发我的第一个项目,这对我来说有点棘手,因为它是我第一次尝试使用它.
您能否提供更深入的信息,为什么我们需要跳转到WPF而不是使用winforms?
我需要说服我们的经理,我们可以为我们基于客户的项目挖掘WPF.
我们正在使用VS 2008.
我有这张桌子:

我在项目中使用了称为NewItem的视图,在此视图中有两个组合框。

我想这样做:在组合框组中有表GROUP的所有Description,当我选择(第一个组合框)此描述的项目时,第二个组合框填充的描述仅与我之前选择的描述有关。
这是一些代码:
XAML NewItemView:
<ComboBox Height="21" HorizontalAlignment="Left" Margin="89,99,0,0"
VerticalAlignment="Top" Width="106" x:Name="Group" SelectedItem="{Binding SelectedGroup}" />
Run Code Online (Sandbox Code Playgroud)
ViewModel代码类似于:
[Export(typeof(IScreen))]
public class NewItemViewModel : Screen
{
public string SelectedGroup { get; set; }
public String[] Group { get { return Groups; } }
[..]
//Constructor
public NewArticleViewModel()
{
Groups = GetGroups();
}
//Method
private string[] GetGroups()
{
OleDbConnection conn = new OleDbConnection(StringConn);
List<Group> groups = new List<Group>();
conn.Open();
groups = conn.Query<Group>(Q_SELECT_GROUPS,null,null).ToList();
conn.Close();
string[] array = new string[groups.Count];
for (int i = 0; …Run Code Online (Sandbox Code Playgroud)