我正在创建一个应用程序,其中应该拦截和翻译对象列表,然后才能在一组控件上显示.为此,我创建了一个ObservableCollection类型的DependencyProperty(BackupEntry是一个定义数据库信息的自定义类).我想要发生的是控件将绑定到MVVM中的ObservableCollection.此集合可用于初始加载控件.然后,当通过控制接口添加一个条目时,它应该被添加到内部的ObservableCollection中,该内部ObservableCollection被定义为DependencyProperty并且由于它们被绑定而显示在MVVM的集合中.这是我正在使用的代码:
protected ObservableCollection<BackupEntry> _BackupItems = new ObservableCollection<BackupEntry>();
public static readonly DependencyProperty BackupItemsProperty = DependencyProperty.Register("BackupItems", typeof(ObservableCollection<BackupEntry>), typeof(ExplorerWindow));
public ObservableCollection<BackupEntry> BackupItems
{
get { return (ObservableCollection<BackupEntry>)GetValue(BackupItemsProperty); }
set { SetValue(BackupItemsProperty, value); }
}
public ExplorerWindow()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(ExplorerWindow), new FrameworkPropertyMetadata(typeof(ExplorerWindow)));
SetValue(BackupItemsProperty, _BackupItems);
_BackupItems.CollectionChanged += new NotifyCollectionChangedEventHandler(BackupItems_CollectionChanged);
}
void BackupItems_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
{
throw new NotImplementedException();
}
Run Code Online (Sandbox Code Playgroud)
在测试应用程序中:
<my:ExplorerWindow Name="ew" HorizontalAlignment="Left" VerticalAlignment="Top" Width="503" Height="223" BackupItems="{Binding BackupListItems}" />
Run Code Online (Sandbox Code Playgroud)
我在测试应用中在屏幕上创建了一个按钮.单击它时,会将一个项添加到BackupListItems.永远不会调用BackupItems_CollectionChanged,并且我的控件中的新集合不会显示在我的集合中.我完全偏离了这里吗?为了让这个工作,我需要做什么?
我有一个我从C#项目引用的Managed C++ dll.C#项目将编译为AnyCPU.有没有办法编译32位和64位版本的托管C++ DLL,然后在运行时告诉C#项目加载正确的一个,具体取决于它运行的架构?
我在Windows 2012中有一个WPF项目,我需要在Window Loaded事件中加载一些信息.不过,我需要在View Model中而不是在CodeBehind中执行此操作.我试图使用以下代码:
在我的xaml中:
<interactivity:Interaction.Behaviors>
<behaviors:WindowLoadedBehavior LoadedCommand="{Binding WindowLoadedCommand}" />
</interactivity:Interaction.Behaviors>
Run Code Online (Sandbox Code Playgroud)
在我的视图模型中:
private DelegateCommand _WindowLoadedCommand;
public DelegateCommand WindowLoadedCommand
{
get
{
return _WindowLoadedCommand;
}
private set
{
_WindowLoadedCommand = value;
}
}
public ShellViewModel()
{
WindowLoadedCommand = new DelegateCommand(WindowLoadedAction);
}
protected void WindowLoadedAction()
{
...
}
Run Code Online (Sandbox Code Playgroud)
我附加的行为:
public class WindowLoadedBehavior : Behavior<FrameworkElement>
{
[SuppressMessage("Microsoft.StyleCop.CSharp.MaintainabilityRules", "SA1401:FieldsMustBePrivate", Justification = "Dependency Property. Allow public.")]
public static DependencyProperty LoadedCommandProperty = DependencyProperty.Register("LoadedCommand", typeof(ICommand), typeof(WindowLoadedBehavior), new PropertyMetadata(null));
public ICommand LoadedCommand
{
get { return (ICommand)GetValue(LoadedCommandProperty); } …Run Code Online (Sandbox Code Playgroud) 我有一个xsd文件,我从中生成一个C#类.为了便于维护,我想在xsd文件中定义一个枚举,这样当我必须更改枚举时,我只需要在一个地方更新它.我知道如何创建枚举,但是当生成C#代码时,我需要枚举成员拥有自定义值,因此结果类似于:
public enum SetupTypeEnum {
None = 0,
NewInstall = 1,
Modify = 2,
Upgrade = 4,
Uninstall = 8
}
Run Code Online (Sandbox Code Playgroud)
有没有办法写xsd来实现这个目标?
我有一个WebForms站点,它已在内部服务器上运行,并根据我们的内部Active Directory对用户进行身份验证.由于我们正在实施一些新功能,因此需要将此站点移动到外部服务器,然后更改身份验证,以便根据我们的Office 365帐户对用户进行身份验证.为此,我有:
修改了Startup.Auth.cs,如下所示:
public void ConfigureAuth(IAppBuilder app)
{
app.CreatePerOwinContext(ApplicationDbContext.Create);
app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create);
app.CreatePerOwinContext<ApplicationSignInManager>(ApplicationSignInManager.Create);
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/Account/Login"),
Provider = new CookieAuthenticationProvider
{
OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser>(
validateInterval: TimeSpan.FromMinutes(30),
regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager))
}
});
app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
app.UseOpenIdConnectAuthentication(new OpenIdConnectAuthenticationOptions { ClientId = "MyApplicationGUID", Authority = "https://login.windows.net/MyDomain.com" });
Run Code Online (Sandbox Code Playgroud)当我转到默认页面并单击"登录"时,它会转到正确的"登录"页面,并显示OpenID按钮.如果我单击该按钮,我将进入Microsoft登录页面,在那里我可以输入我的凭据.但是,在那时,我被重定向回我网站的登录页面,它仍然要求输入用户名/密码.
我希望发生的是设置网站,以便在用户未经过身份验证时,将其直接重定向到Microsoft登录页面,成功登录后会重定向回原来请求的页面.如果做不到这一点,我会对使默认登录页面工作感到满意,这样当我点击OpenID时,我没有重定向回登录页面.
我没有时间在这一点上学习MVC并把整个事情移植过来,所以这条路线目前不是一个选择.
我对这个过程不太了解,所以如果我的问题没有意义,或者你需要更多信息,请告诉我,我很乐意尝试找到你需要的东西来帮助我.
我已经注意到在C#中看到的事件的所有示例中,触发事件的内容如下:
PropertyChangedEventHandler handler = PropertyChanged;
if(handler != null)
handler(this, new PropertyChangedEventArgs(propertyName));
Run Code Online (Sandbox Code Playgroud)
这和刚写的有什么不同:
if(PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
Run Code Online (Sandbox Code Playgroud)