Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 58056

How To set a Content View Dynamically

$
0
0

So I have my page:

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
                       xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
                       x:Class="MyProject.Page">
    <ContentView x:Name="ContextButtons"/>
  </ContentPage>

and another ContentView:

<?xml version="1.0" encoding="utf-8" ?>
<ContentView xmlns="http://xamarin.com/schemas/2014/forms"
                       xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
                       x:Class="MyProject.Views>
<Label Text="Hello World/>
</ContentView>

and in my code behind of my page I would like to dynamically set the value of ContextButtons

public Page()
{
        InitializeComponent();
        if (MyBoolean)
        {
        ContextButtons = new Views();
        }
        else
        {
        ContextButtons = //Something else;
        }
}

But sadly this doesnt work and my page never displays. What have I missed?

also Trying

ContextButtons.Content = new Views();

doesn't work as ContextButtons is null


Viewing all articles
Browse latest Browse all 58056

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>