- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
Xamarin Forms 中的可视元素通过设置它们的 IsVisible 属性变得可见/不可见。更改视觉元素上的某些属性或数据可能会导致界面重绘,这可能会很昂贵。
我正在尝试提高我的应用程序的性能,因此我引入了缓存并尝试进行一些布局简化,但我必须使许多视觉元素可见/不可见,并且想知道优化它的最佳方法是什么。
哪个操作更有效?
var myButton.IsVisible = true;
或者:
if(!myButton.IsVisible) myButton.IsVisible = true;
如果 Xamarin 已检查状态并决定是否重绘,则第二个选项是多余的,因此效率低下。如果每次设置属性时都发生重绘,那么效率会更高。我找不到任何文件来告诉我是哪种情况。
最佳答案
DependencyProperty
的任何良好实现(或 INotifyPropertyChanged
)成员应该忽略连续的 set
如果那 value
是一样的。出于这个原因,让 IsVisible
弄清楚该怎么做,而不是将责任放在来电者身上。
If Xamarin already checks the state and decides whether to redraw then the second option is redundant and therefore inefficien
button.IsVisible
例如使它下降到
BindableObject.SetValueActual
(
Button
在其继承图中具有
BindableObject
),其中检查相同性。仅当值不同或
SetValueFlags.RaiseOnEqual
时才应用新值设置。
OnPropertyChanged
和
PropertyChanged
在不同的值上调用或者如果
RaiseOnEqual
设置。
void SetValueActual(BindableProperty property, BindablePropertyContext context, object value, bool currentlyApplying, SetValueFlags attributes, bool silent = false)
{
object original = context.Value;
bool raiseOnEqual = (attributes & SetValueFlags.RaiseOnEqual) != 0;
bool clearDynamicResources = (attributes & SetValueFlags.ClearDynamicResource) != 0;
bool clearOneWayBindings = (attributes & SetValueFlags.ClearOneWayBindings) != 0;
bool clearTwoWayBindings = (attributes & SetValueFlags.ClearTwoWayBindings) != 0;
bool same = ReferenceEquals(context.Property, BindingContextProperty) ? ReferenceEquals(value, original) : Equals(value, original);
if (!silent && (!same || raiseOnEqual))
{
property.PropertyChanging?.Invoke(this, original, value);
OnPropertyChanging(property.PropertyName);
}
if (!same || raiseOnEqual)
{
context.Value = value; // <---------- assignment
}
.
.
.
if (!silent && (!same || raiseOnEqual)) // <------- notifications guard
{
if (binding != null && !currentlyApplying)
{
_applying = true;
binding.Apply(true);
_applying = false;
}
OnPropertyChanged(property.PropertyName);
property.PropertyChanged?.Invoke(this, original, value);
关于c# - 我应该在设置之前检查 VisualElement.IsVisible 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62790904/
我正在尝试验证元素是否存在。我使用的是 isVisible 但它抛出错误消息“TypeError: Object # has no method 'isVisible'” it('should ver
这是一个通用问题。如果我添加一些 UI 对象(例如 JButton 等)并检查 isVisible 属性,它将返回 true。但是,它是否能保证对象实际渲染并在显示器上正确可见?如果没有,是否有更好的
我有一个父 DIV (.box) 和一个子 DIV (#display)。如果 child 被隐藏,我想淡出 parent 。但它仍然有效:S if( $('#display').is(':visib
我有一个 NSWindow,其“停用时隐藏”设置为 TRUE。 当我的应用程序失去焦点时,窗口消失,但是,通过“isVisible”进行测试给出了 TRUE。这是怎么回事? 最佳答案 isVisibl
以下代码给我一个错误:找不到符号 public static boolean playerTurn = true; public static boolean playerWon = false; p
我的表如下所示。通过使用 visible() 如何选择两个不同 div(hidden_source1 和hidden_source2)上第一个可见 tr 的单选按钮?我已经这样做了,首先,在两
我基本上是在尝试进行表单验证。一切都很好。除了一件事。首先,这是我的代码: $('#submit_btn').click(function(){ $("input:n
我想在共享点站点中隐藏一个快速启动节点,但它没有按预期工作。 :( 我的代码如下: using (SPSite spSiteTest = new SPSite(serv
我有一个带有 fragment 容器的 Activity 和两个 fragment ,如“列表 fragment -> 详细 fragment ” private boolean isFirstFra
我在 DB 方面工作过很多次,但从未设计过一个。我在最常见的表格之一的结构上苦苦挣扎,个人数据: 主表名为 user,只有几列。然后我有 General,其中有(id、userRef、姓名、姓氏、年龄
我看到 Region.IsVisible(rectangle) 没有按我预期的那样工作。 所以,是我谁期望不应该,或者是方法那不是应该的吗??! 我有以下情况: alt text http://lh4
我有一个 xamarin用户滚动 ListView 搜索部分时的堆栈布局应该像 WhatsApp 搜索区域一样隐藏。但现在我 m using可见 e property to hide the area
Xamarin Forms 中的可视元素通过设置它们的 IsVisible 属性变得可见/不可见。更改视觉元素上的某些属性或数据可能会导致界面重绘,这可能会很昂贵。 我正在尝试提高我的应用程序的性能,
有什么办法可以让几个不同的 wicket 组件具有相同的 isVisible() 实现 例如,我有标签、文本字段、DropdownChoices 等,它们具有相同的 isVisible 方法,但我不会
我正在尝试设置一个覆盖 fragment ,该 fragment 会在触摸按钮时出现并在再次单击按钮时消失。我没有使用支持库 fragment ,而是使用常规 fragment 。因此,当您单击按钮附
我有一个 MyDialog 类,它是 QDialog 的子类,它本身是 QWidget 的子类。所以它看起来像这样: QObject | V QWidget | V QDial
我有一个具有以下结构的 View : GrandView -Parent View1 -Parent View2 --Child View1 --Child View2 subview 几乎占据了 P
我遇到了一个奇怪的性能问题,如果能对我所遇到的行为做出解释,那就太好了。 我正在使用System.Drawing.Region.IsVisible(PointF)确定某个点是否在多边形内。这通常效果很
Microsoft 的在线文档指出,此 Graphics 方法返回“如果由 rect 参数指定的矩形包含在此 Graphics 的可见剪辑区域内,则返回 true;否则,返回 false”。 他们真的
我意识到这个问题以前曾被问过,但我还没有找到我理解的答案。我对异步编程还是新手,并且很难弄清楚如何在 Protractor/Javascript 中做最简单的事情。 例如,如何按照此算法构造函数“is
我是一名优秀的程序员,十分优秀!