如何在代码中设置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}}"
>
启动画面:可见性绑定到不透明度,因为Opacity = 0的可见对象仍在处理输入。
Appbar刚刚与Splashscreen的Opacity绑定。根本没有代码隐藏(只是注释掉了所有内容)。但是,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);
}
}
答案 0 :(得分:0)
我不认为在代码中进行绑定会有所帮助,是否确保在执行页面的构造函数时将绑定的值设置为false(并且在构造函数中设置了DataContext) ?
如果绑定到某个对象proeperty,它在构造函数中为null,则可以在绑定上添加FallbackValue = false。
如果你在这里找不到任何其他解决方案,那么如何在代码中创建相同的绑定:
Binding binding = new Binding("Opacity");
binding.ElementName = "SplashScreen";
binding.Converter = new DoubleToBooleanInversedConverter();
multiAppBarBehavior.SetBinding(MultiApplicationBarBehavior.IsVisibleProperty, binding);
(其中multiAppBarBehavior将是MultiApplicationBarBehavior控件名称)