簡體   English   中英

布爾變量未更新

[英]Bool variables not being updated

我有一個類型為ImageButton的對象。 我也有以下代碼:

 LogManager.GetCurrentClassLogger().Log(LogLevel.Info, "###payWithVisa.Enabled ={0}; payWithVisa.Visible ={1}; canPayWithCard={2}", payWithVisa.Enabled, payWithVisa.Visible, canPayWithCard);

 payWithVisa.Enabled = canPayWithCard;
 payWithVisa.Visible = canPayWithCard;

 LogManager.GetCurrentClassLogger().Log(LogLevel.Info, "payWithVisa.Enabled ={0}; payWithVisa.Visible ={1}; canPayWithCard={2}", payWithVisa.Enabled, payWithVisa.Visible, canPayWithCard);

這是相應的日志條目:

2016-03-29 11:37:49.1308|INFO|###payWithVisa.Enabled =True; payWithVisa.Visible =False; canPayWithCard=True
2016-03-29 11:37:49.1348|INFO|payWithVisa.Enabled =True; payWithVisa.Visible =False; canPayWithCard=True

您可以看到變量payWithVisa.Visible沒有得到更新。 盡管為其分配了值為true的變量,它仍然為false。

有人可以幫我弄清楚什么是錯的嗎?

PS。 使用的.NET Framework:4.0

一種可能性(來自MSDN上的文檔 ):

如果未呈現容器控件,則即使將單個控件的Visible屬性設置為true,也不會呈現其中包含的任何控件。 在這種情況下,即使您已將Visible屬性顯式設置為true,單個控件也將返回false。 (也就是說,如果父控件的Visible屬性設置為false,則子控件將繼承該設置,並且該設置優先於任何本地設置。)

因此,您可能要檢查是否先呈現了父控件。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM