0

如何在代码中设置 MultiApplicationBarBehavior.IsVisible 绑定?

问题:如果通过 xaml 绑定它,即使绑定值为 false,它也会闪烁。

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 绑定到 Opacity,因为 Opacity=0 的 Visible 对象仍在处理输入。

Appbar 只是绑定到 Splashscreen 的不透明度。根本没有代码隐藏(只是注释掉了所有内容)。但是,appbar 在页面加载期间闪烁。这就是为什么我想将其默认设置为 false 并稍后通过代码绑定。

唯一的情况是,appbar 不闪烁是绑定到自定义属性时,该属性在初始化期间设置为 false

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

转换器:

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);
    }
}
4

1 回答 1

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)?
If you are binding to some object proeperty which is null in the contructor you could add FallbackValue=false on the binding.

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)

于 2013-10-23T00:03:35.607 回答