简体   繁体   English

如何通过代码绑定appbar的可见性?

[英]How to bind appbar's visibility by code?

How is it possible to set MultiApplicationBarBehavior.IsVisible binding in code? 如何在代码中设置MultiApplicationBarBehavior.IsVisible绑定?

The problem: if to bind it via xaml, it would be blinking even if binded value is false. 问题是:如果通过xaml绑定它,即使绑定的值为false,它也会闪烁。

EDIT1: So, what i'm binding to? EDIT1:那么,我要绑定到什么?

<mainPivot:SplashScreenControl 
        Opacity="1"
        Name="SplashScreen"
        Visibility="{Binding Opacity, ElementName=SplashScreen, Converter={StaticResource DoubleToVisibilityConverter}}"
        />

 <cimbalino:MultiApplicationBarBehavior 
            SelectedIndex="{Binding PivotIndex}" 
            IsVisible="{Binding Opacity, ElementName=SplashScreen, Converter={StaticResource DoubleToBooleanInversedConverter}}"
            >

Splashscreen: Visibility is binded to Opacity, because Visible object with Opacity=0 is still handling input. 闪屏:可见性已绑定到不透明度,因为不透明度= 0的可见对象仍在处理输入。

Appbar is just binded to Splashscreen's Opacity. Appbar刚刚绑定到了Splashscreen的不透明度。 No codebehind at all (just commented out everything). 根本没有任何代码隐藏(只需注释掉所有内容)。 However, appbar is blinking during the page load. 但是,在页面加载期间,appbar闪烁。 That's why i want to set it false by default and later to bind by code. 这就是为什么我要在默认情况下将其设置为false,然后再通过代码绑定。

The only case, when appbar is not blinking is when it is binded to custom property, which is set to false during initialization appbar不闪烁的唯一情况是将其绑定到自定义属性,该属性在初始化期间设置为false

<cimbalino:MultiApplicationBarBehavior 
            SelectedIndex="{Binding PivotIndex}" 
            IsVisible="{Binding IsSplashScreenVisible, Converter={StaticResource BooleanInversedConverter}}"
            >

Converter: 转换器:

public class DoubleToBooleanInversedConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        if (value == null)
            return true;

        return !((value as double?) > 0);
    }
}

I don't think doing the binding in code will help, did you made sure that the value your are binding to is set to false when the contructor of the page is executed (and that the DataContext is set in the contructor)? 我认为用代码进行绑定不会有帮助,您是否确定要在执行页面的构造方法时将要绑定的值设置为false(并且在构造方法中设置了DataContext)?
If you are binding to some object proeperty which is null in the contructor you could add FallbackValue=false on the binding. 如果要绑定到某个对象属性(在构造器中为null),则可以在绑定上添加FallbackValue = false。

If you don't find any other solution here is how to create the same binding in code: 如果您找不到其他解决方案,请按以下步骤在代码中创建相同的绑定:

Binding binding = new Binding("Opacity");
binding.ElementName = "SplashScreen";
binding.Converter =  new DoubleToBooleanInversedConverter();
multiAppBarBehavior.SetBinding(MultiApplicationBarBehavior.IsVisibleProperty, binding);

(where multiAppBarBehavior will be the MultiApplicationBarBehavior control name) (其中multiAppBarBehavior将是MultiApplicationBarBehavior控件名称)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Windows应用商店应用如何绑定appbar项目的可见性? - windows store apps How to bind visibility of an appbar item? 如何将 DataGridTemplateColumn 的 Visibility 绑定到 textBlock 的 Visibility - How to bind DataGridTemplateColumn's Visibility to textBlock's Visibility 如何将数据绑定到控件的Visibility属性 - How to bind data to a control's Visibility property 如何将ListBox的可见性绑定到ApplicationBar按钮? - How can I bind a ListBox's Visibility to an ApplicationBar button? 如何使用 WPF 中的代码绑定 DataGridTextColumn 的可见性属性? - How do I bind the visibility property of a DataGridTextColumn using code in WPF? 如何在cs代码中将布尔值数组绑定到其相应椭圆的可见性? - How to bind a array of bool value to the visibility of their corresponding ellipse in cs code? 你能否将GroupBox的可见性绑定到它的孩子的可见性? - Can you bind the visibility of a GroupBox to the visibility of it's children? WPF:如何使用selecteditem信息将Button的可见性绑定到ListBox ItemsControl中? - WPF : How to bind Button's visibility inside ListBox ItemsControl using selecteditem information ? 如何在代码中绑定GridViewColumn的DisplayMemberBinding - How to bind GridViewColumn's DisplayMemberBinding in code MvvmCross Windows Store如何将不同的ViewModel绑定到Appbar? - MvvmCross Windows Store How to bind different ViewModels to Appbar?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM