为什么不调用OnActivate?(Why isn't OnActivate being called?)
我在这里问这个问题,因为我试图解决这个问题我感到很茫然。 我搜索过,所有出现的内容都是有意义的,但也不适用于我的情况。
我正在使用
WPF
和MVVM
以及Caliburn.Micro
。 我有一个带有相应视图模型的shell窗口,它是一个Conductor<Screen>.Collection.OnceActive
和一个继承自Screen
。 我在Conductor的构造函数中调用ActivateItem
来显示后续屏幕,它正确显示屏幕但从未调用Screen的OnActivate
覆盖,并且屏幕的IsActive
属性设置为False
。这只发生在我第一次从Conductor调用
ActivateItem
,所有其他调用将正确调用OnActivate
和OnDeactivate
。这对我来说毫无意义,我不知道发生了什么。 我清理了解决方案,重建,甚至重新启动但它仍然无法正常工作。 以下是代码:
家长指挥
[Export] public sealed class ShellViewModel : Conductor<Screen>.Collection.OneActive, IHandle<SimpleMessage> { private readonly DashboardViewModel m_Dash; private readonly LoginViewModel m_Login; private readonly IEventAggregator m_MsgBus; [ImportingConstructor] public ShellViewModel(DashboardViewModel dash, LoginViewModel login, IEventAggregator msgBus) { this.m_MsgBus = msgBus; this.m_Dash = dash; this.m_Login = login; this.ActivateItem(this.m_Login); } protected override void OnActivate() { this.m_MsgBus.Subscribe(this); //called correctly } protected override void OnDeactivate(bool close) { this.m_MsgBus.Unsubscribe(this); //called correctly } public void Handle(SimpleMessage message) { switch (message) { case SimpleMessage.LoginSuccess: this.ActivateItem(this.m_Dash); break; case SimpleMessage.Logout: this.ActivateItem(this.m_Login); break; } } }
儿童屏幕
[Export] public sealed class LoginViewModel : Screen { private readonly IEventAggregator m_MsgBus; [ImportingConstructor] public LoginViewModel(IEventAggregator msgBus) { this.m_MsgBus = msgBus; } protected override void OnActivate() { //NOT called the first time, but is called every other time MessageBox.Show("ACTIVATE TEST"); } protected override void OnDeactivate(bool close) { //NOT called the first time, but is called every other time MessageBox.Show("DEACTIVATE TEST"); } public void CmdLogin(string password) { this.m_MsgBus.PublishOnUIThread(SimpleMessage.LoginSuccess); } public string Username { get; set; } public string Password { get; set; } }
UPDATE
我下载了Caliburn Micro源代码,因此我可以进入
ActivateItem
函数,看看发生了什么。 出于某种原因,当我第一次从Conductor调用ActivateItem
,Conductor的IsActive
属性设置为false,这会导致Caliburn跳过调用OnActivate
覆盖。 我不知道为什么财产会是假的。ConductorBaseWithActiveItem.cs
protected virtual void ChangeActiveItem(T newItem, bool closePrevious) { ScreenExtensions.TryDeactivate(activeItem, closePrevious); newItem = EnsureItem(newItem); //Problem is here, IsActive is false the first time around in the conductor if(IsActive) ScreenExtensions.TryActivate(newItem); activeItem = newItem; NotifyOfPropertyChange("ActiveItem"); OnActivationProcessed(activeItem, true); }
看起来导体中
IsActive
为假的原因是因为我的Conductor是使用DisplayRootViewFor
创建的根视图,看起来该函数没有将IsActive
属性设置为true。所以,知道这一点,我只是实现了这个错误而且指挥不能/不应该是根视图? 我需要有第二个孩子视图,这是指挥(看起来有点多)?
I'm asking this here because I'm at a loss for trying to figure this out. I've searched and all that comes up are things that make sense but also don't apply to my situation.
I'm using
WPF
withMVVM
andCaliburn.Micro
. I have a shell window with a corresponding view model which is aConductor<Screen>.Collection.OnceActive
and a screen which is inheriting fromScreen
. I'm callingActivateItem
within the Conductor's constructor to show the subsequent screen, it shows the screen correctly but never calls the Screen's override forOnActivate
and the screen'sIsActive
property is set toFalse
.This only happens the very first time I call
ActivateItem
from the Conductor, all additional calls will properly callOnActivate
andOnDeactivate
.This makes no sense to me and I have no idea what is going on. I cleaned the solution, rebuilt, and even rebooted but it still doesn't work properly. Below is the code:
Parent Conductor
[Export] public sealed class ShellViewModel : Conductor<Screen>.Collection.OneActive, IHandle<SimpleMessage> { private readonly DashboardViewModel m_Dash; private readonly LoginViewModel m_Login; private readonly IEventAggregator m_MsgBus; [ImportingConstructor] public ShellViewModel(DashboardViewModel dash, LoginViewModel login, IEventAggregator msgBus) { this.m_MsgBus = msgBus; this.m_Dash = dash; this.m_Login = login; this.ActivateItem(this.m_Login); } protected override void OnActivate() { this.m_MsgBus.Subscribe(this); //called correctly } protected override void OnDeactivate(bool close) { this.m_MsgBus.Unsubscribe(this); //called correctly } public void Handle(SimpleMessage message) { switch (message) { case SimpleMessage.LoginSuccess: this.ActivateItem(this.m_Dash); break; case SimpleMessage.Logout: this.ActivateItem(this.m_Login); break; } } }
Child Screen
[Export] public sealed class LoginViewModel : Screen { private readonly IEventAggregator m_MsgBus; [ImportingConstructor] public LoginViewModel(IEventAggregator msgBus) { this.m_MsgBus = msgBus; } protected override void OnActivate() { //NOT called the first time, but is called every other time MessageBox.Show("ACTIVATE TEST"); } protected override void OnDeactivate(bool close) { //NOT called the first time, but is called every other time MessageBox.Show("DEACTIVATE TEST"); } public void CmdLogin(string password) { this.m_MsgBus.PublishOnUIThread(SimpleMessage.LoginSuccess); } public string Username { get; set; } public string Password { get; set; } }
UPDATE
I downloaded the Caliburn Micro source so I could step into the
ActivateItem
function and see what is going on. For some reason, when I first callActivateItem
from the Conductor the Conductor'sIsActive
property is set to false which causes Caliburn to skip calling theOnActivate
override. I have no idea why the property would be false.ConductorBaseWithActiveItem.cs
protected virtual void ChangeActiveItem(T newItem, bool closePrevious) { ScreenExtensions.TryDeactivate(activeItem, closePrevious); newItem = EnsureItem(newItem); //Problem is here, IsActive is false the first time around in the conductor if(IsActive) ScreenExtensions.TryActivate(newItem); activeItem = newItem; NotifyOfPropertyChange("ActiveItem"); OnActivationProcessed(activeItem, true); }
It looks like the reason
IsActive
is false in the Conductor is because my Conductor is the root view which is created usingDisplayRootViewFor
and it looks like that function does not set theIsActive
property to true.So, knowing that, am I simply just implementing this wrong and a Conductor can't/shouldn't be the root view? Do I need to have a 2nd child view which is the conductor (that seems like a bit much)?
原文:https://stackoverflow.com/questions/38019227
最满意答案
尝试这个
setcookie('cookie_name', 'cookie_value', time()); echo $_COOKIE['cookie_name'];
现在检查cookie是否存在。
if(isset($_COOKIE['cookie_name'])) { echo "your cookie is set"; } else { echo "return error or any thing you want"; }
这将为您提供所有浏览器信息。
echo $_SERVER['HTTP_USER_AGENT'];
try this
setcookie('cookie_name', 'cookie_value', time()); echo $_COOKIE['cookie_name'];
Now check the cookie if it exists.
if(isset($_COOKIE['cookie_name'])) { echo "your cookie is set"; } else { echo "return error or any thing you want"; }
This will give you all browser(s) information.
echo $_SERVER['HTTP_USER_AGENT'];
相关问答
更多-
如果你想有很多预构建库,Zend框架是很好的,但是可以自由地与你自己或第三方混合搭配。 Zend框架包含Zend_Auth ,它完整且可以使用。 The Zend framework is good if you want to have a lot of pre-buildt libraries, but be free to mix and match with your own or third-party. The Zend framework includes Zend_Auth, which i ...
-
CI每隔x秒自动重新生成会话标识,您可以在配置中设置该标识。 您可以在Session.php中创建一个与sess_update()相同的新函数,但是会从顶部删除以下函数,并将函数重命名为regenerate_id()。 // We only update the session every five minutes by default if (($this->userdata['last_activity']+$this->sess_time_to_update) >= $this->now) { ret ...
-
通过Memcache的Django会话:无法手动查找会话密钥(Django Sessions via Memcache: Cannot find session key manually)[2023-06-18]
是的,Django内部使用的缓存密钥通常与发送到缓存后端的密钥不同(在本例中为pylibmc / memcached)。 我们分别将这两个密钥称为django缓存密钥和最终缓存密钥。 request.session.cache_key给出的django缓存键用于Django的低级缓存API,例如: >>> from django.core.cache import cache >>> cache.get(request.session.cache_key) {'_auth_user_hash': '1ay2 ... -
您必须进行第二次卷曲尝试,这次将URL和post字段更改为您在步骤2中提取的字段。 为了获得所需的字段,您可以使用dom(例如, Simple HTML Dom Parser )库,该库使用在步骤2中获得的代码初始化或简单的常规表达式( preg_match ) You have to do a second curl attempt, this time changing the url and post fields into the ones you fetched in the step 2. In ...
-
您可以使用Wix Harvest Tool(Heat)进行自动.wxs编写。 用法(来自社区教程 ): heat dir文件夹-cg SampleGroup -out SampleGroup.wxs 将以递归方式收集指定的文件夹,创建一个由ComponentGroup组成的片段,其名称由-cg开关指定。 该组将包含与文件一样多的组件,每个组件在其中具有单个文件,如规则所规定的那样,并且将分配在同一输入集上重新生成时保持相同的唯一生成的组件,目录和文件标识符。 除非-gg开关明确指示,否则不会生成GUID(仅 ...
-
解决了: 我们可以像这样实现这个方法: $text = '123456'; $key = "ygXa6pBJOWSAClY/CFEdOTjvJpMIiPAMQiTMjBrcOGw="; $key = (string)base64_decode($key); $iv = random_bytes(16); $value = \openssl_encrypt(serialize($text), 'AES-256-CBC', $key, 0, $iv); $bIv = base64_encode($iv); ...
-
尝试这个 setcookie('cookie_name', 'cookie_value', time()); echo $_COOKIE['cookie_name']; 现在检查cookie是否存在。 if(isset($_COOKIE['cookie_name'])) { echo "your cookie is set"; } else { echo "return error or any thing you want"; } 这将为您提供所有浏览器信息。 echo $_SERVE ...
-
看看AJAX响应可以设置cookie吗? 。 没有必要通过json和javascript设置cookie。 PHP和http将为您完成。 Look at Can an AJAX response set a cookie?. There's no need to set the cookie via json and javascript. PHP and http will do it for you.
-
我不确定(现在不能测试),但是 if(!isset($_SESSION)) session_start(); 似乎永远不会发生因为$ _SESSION总是被设置。 如果没有,请尝试: session_start(); 而且不要这样做 $_SESSION = array(); 因为这是不好的做法。 I'm not sure (and can't test it now), but if(!isset($_SESSION)) session_start(); seems to never ...
-
session_set_save_handler手动设置$ _SESSION数据?(session_set_save_handler set $_SESSION data manually?)[2022-07-07]
不需要.PHP从read()处理程序获取返回值,对其进行反序列化并自动填充$ _SESSION。 No. PHP takes the return value from the read() handler, unserializes it and populates $_SESSION with the result automatically.