0

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);
    }
}
Vitalii Vasylenko
  • 4,776
  • 5
  • 40
  • 64

1 Answers1

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)

Benoit Catherinet
  • 3,335
  • 1
  • 13
  • 12
  • Hi, nice to see ya. Updated question. – Vitalii Vasylenko Oct 23 '13 at 14:05
  • Is the DataContext of your page set in xaml? If that the case when are you setting IsSplashScreenVisible? – Benoit Catherinet Oct 23 '13 at 17:52
  • Added the code to create the binding in code even though I think you would need to do that if IsSplashScreenVisible is properly set to false when the page is build – Benoit Catherinet Oct 23 '13 at 18:01
  • Yep, DataContext is set in xaml by ViewModelLocator. I'm setting IsSplashScreenVisible by default: var isSplashScreenVisible = false; – Vitalii Vasylenko Oct 24 '13 at 11:26
  • Sorry, i was sleepy yesterday. Updated cases, now its more clear. – Vitalii Vasylenko Oct 24 '13 at 11:33
  • 1
    ok it's more clear now, I updated the code to create the same binding in code. If you are using a storyboard to change "progressively" the opacity value, it's probably not a good idea to bind directly to that value like you do, as it would force execution of the converter code every time the storyboard modify the opacity value (so the opacity animation will look less fluid). In that case it's probably better to just set the value appropriately in the storyboard. – Benoit Catherinet Oct 24 '13 at 14:50
  • Nice point! I guess, i should just bind to the property and change it once splashscreen is faded away. – Vitalii Vasylenko Oct 24 '13 at 15:07