我知道这是基本的,但我正在从vb.net跳转到C#,而我在vb.net中使用的方法似乎并不起作用.我用自定义类服务创建了一个.dll.
在我的项目中,我正在使用Service实例填充ObservableCollection.我想在XAML(WPF)中使用DisplayMemberPath在组合框中显示实例.
我的服务实例正在填充ComboBox,但每个项目的显示都是空白的; 我只是得到一堆空行可供选择.
我已经尝试了这个,有没有在类本身上实现INotifyPropertyChanged,虽然我不认为此时应该是必要的,因为我仍然非常在第1方.
这是我的代码:
<Grid>
<ComboBox Name="TopService"
VerticalAlignment="Top"
ItemsSource="{Binding}"
DisplayMemberPath="{Binding ServCode}"></ComboBox>
</Grid>
Run Code Online (Sandbox Code Playgroud)
这是我的代码背后:
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
Execute();
}
private void Execute()
{
SA.franchiseID = "HOL010";
ObservableCollection<Service> ocService = Service.InitializeServiceList();
TopService.DataContext = ocService;
}
}
Run Code Online (Sandbox Code Playgroud)
和类的代码(通过.dll引用)
public class Service : INotifyPropertyChanged
{
#region INotifyPropertyChanged implementation
public event PropertyChangedEventHandler PropertyChanged;
protected void Notify(string propertyName)
{
if (this.PropertyChanged != null)
{ PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); }
}
#endregion
private string servCode;
public string ServCode …Run Code Online (Sandbox Code Playgroud) 我在观看教程的同时遇到了这个问题.之前没见过,我想知道这里发生了什么.
Application["ApplicationStartDateTime"] = DateTime.Now;
Run Code Online (Sandbox Code Playgroud)
这是在上下文中:
public class MvcApplication : System.Web.HttpApplication
{
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
RouteConfig.RegisterRoutes(RouteTable.Routes);
Application["ApplicationStartDateTime"] = DateTime.Now;
}
protected void Application_End()
{
Application.Clear();
}
}
Run Code Online (Sandbox Code Playgroud)
application_Start方法是锅炉板,除了StartDateTime行之外,它几乎没有解释原因.具体来说,我想知道方括号.我知道数组,我知道注释,但这看起来不同.