Frage

How is it possible to set MultiApplicationBarBehavior.IsVisible binding in code?

The problem: if to bind it via xaml, it would be blinking even if binded value is false.

EDIT1: So, what i'm binding to?

<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.

Appbar is just binded to Splashscreen's Opacity. No codebehind at all (just commented out everything). However, appbar is blinking during the page load. That's why i want to set it false by default and later to bind by code.

The only case, when appbar is not blinking is when it is binded to custom property, which is set to false during initialization

<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);
    }
}
War es hilfreich?

Lösung

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)

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top