Example #1
0
        public void StaticResourceLookForApplicationResources()
        {
            Device.PlatformServices = new MockPlatformServices();
            Application.Current     = null;

            Application.Current = new MyApp();
            var xaml   = @"
				<ContentView
				  xmlns=""http://xamarin.com/schemas/2014/forms""
				  xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"">
				  <ContentView.Resources>
                    <ResourceDictionary>
                      <x:String x:Key=""bar"">BAZ</x:String>
                    </ResourceDictionary>
				  </ContentView.Resources>
				  <StackLayout>
				    <Label x:Name=""label0"" Text=""{StaticResource foo}""/>
				    <Label x:Name=""label1"" Text=""{StaticResource bar}""/>
				  </StackLayout>
                </ContentView>";
            var layout = new ContentView().LoadFromXaml(xaml);
            var label0 = layout.FindByName <Label> ("label0");
            var label1 = layout.FindByName <Label> ("label1");

            //resource from App.Resources
            Assert.AreEqual("FOO", label0.Text);

            //local resources have precedence
            Assert.AreEqual("BAZ", label1.Text);
        }
        private void AddTitleBar(ContentView layout, MobilePage page)
        {
            var nav = layout.FindByName <StackLayout>("NavBar");

            if (nav != null)
            {
                nav.IsVisible = true;
                if (page.Attributes.ContainsKey("AccentColor") && !string.IsNullOrEmpty(page.Attributes["AccentColor"]))
                {
                    nav.BackgroundColor = (Color) new ColorTypeConverter().ConvertFromInvariantString(page.Attributes["AccentColor"]);
                }

                StackLayout stackLayout = new StackLayout
                {
                    HeightRequest   = 44,
                    Orientation     = StackOrientation.Horizontal,
                    VerticalOptions = LayoutOptions.Center
                };

                nav.Children.Add(stackLayout);

                if (App.Current.MainPage.Navigation.NavigationStack.Count > 1)
                {
                    IconLabel icon = new IconLabel
                    {
                        Text = "fa fa-chevron-left",
                        HorizontalOptions = LayoutOptions.Start,
                        VerticalOptions   = LayoutOptions.Center,
                        FontSize          = 30,
                        Margin            = new Thickness(10, 7, 0, 0),
                        TextColor         = Color.Black
                    };

                    TapGestureRecognizer tgr = new TapGestureRecognizer()
                    {
                        NumberOfTapsRequired = 1
                    };
                    tgr.Tapped += (s, ee) =>
                    {
                        AvalancheNavigation.RemovePage();
                    };
                    nav.GestureRecognizers.Add(tgr);

                    stackLayout.Children.Add(icon);
                }

                Label label = new Label
                {
                    Text = page.Title,
                    HorizontalTextAlignment = TextAlignment.Center,
                    HorizontalOptions       = LayoutOptions.CenterAndExpand,
                    VerticalOptions         = LayoutOptions.Center,
                    FontSize  = 20,
                    Margin    = new Thickness(0, 6, 0, 0),
                    TextColor = Color.Black
                };
                stackLayout.Children.Add(label);

                BoxView boxview = new BoxView
                {
                    HeightRequest     = 0.5,
                    HorizontalOptions = LayoutOptions.FillAndExpand,
                    BackgroundColor   = Color.Black
                };
                nav.Children.Add(boxview);
            }
        }