Forum Xamarin.Forms

How to set a classname to the StyleClass by {Binding ...} from code behind

berkqberkq Member ✭✭

Hi, i need to set a class name to the StyleClass dynamically

Ctmlst.Add(new CtrMemCat()
{
FrClass=fr
}
this is in a for loop and when the page get load in this step exception thrown (NullReferenceException)

Answers

  • berkqberkq Member ✭✭

    no one knows!!???

  • NMackayNMackay GBInsider, University mod
    edited February 10

    You question is pretty vague, you can cast easily to a style at app level or page level

    (Color)Application.Current.Resources["MyColor"];
    (Style)Application.Current.Resources["MyStyle"];
    
  • berkqberkq Member ✭✭
    @NMackay when want to pass the name of css class from code behind to the xaml
    <Frame StyleClass={Binding xxx}>
    runtime errorobjectrefrence exception happen
  • NMackayNMackay GBInsider, University mod

    @berkq said:
    @NMackay when want to pass the name of css class from code behind to the xaml

    runtime errorobjectrefrence exception happen

    StyleProperty is bindable so your probably doing something wrong. You'd have to provide a sample as no one can help with the information you have provided

  • ColeXColeX Member, Xamarin Team Xamurai
    edited February 11

    @NMackay He was probably asking how to set StyleClass in code behind .

    Xaml

    <Label x:Name="label" Text="{Binding Name}" StyleClass="detailPageTitle" />
    

    Code behind

    label.StyleClass = new List<string> { "detailPageTitle" };
    

    Test with official sample , works perfectly .

  • berkqberkq Member ✭✭
    @ColeX u r right.
    I want to thats be like this
    <Label StyleClass="{Binding cssclassname}>
    In code behind i did this
    cssclassname =new List<string> { "xxx" };

    Cssclassname is a property of my class.
  • berkqberkq Member ✭✭
    > @berkq said:
    > @ColeX u r right.
    > I want to thats be like this
    > <Label StyleClass="{Binding cssclassname}>

    > In code behind i did this
    > cssclassname =new List<string> { "xxx" };
    >
    > Cssclassname is a property of my class.
    >
  • berkqberkq Member ✭✭
    > > @ColeX u r right.
    > > I want to thats be like this
    > > <Label StyleClass="{Binding cssclassname}>
    >
    > > In code behind i did this
    > > cssclassname =new List<string> { "xxx" };
    > >
    > > Cssclassname is a property of my class.
    > >
    >
    >
    >
  • berkqberkq Member ✭✭
    @ColeX u r right.
    I want to thats be like this
    <Label StyleClass="{Binding cssclassname}>

    In code behind i did this
    cssclassname =new List<string> { "xxx" };

    Cssclassname is a property of my class.
  • ColeXColeX Member, Xamarin Team Xamurai

    Cssclassname should be the property in css file .

    Check my sample below .

Sign In or Register to comment.