Styles in codebehind (.vb)

4 posts, 0 answers
  1. Pan hal
    Pan hal avatar
    61 posts
    Member since:
    Aug 2009

    Posted 25 Mar 2010 Link to this post


    We need to set the background color and other properties  of few controls in runtime

    How to set this in .vb file.

     

     

    I tried this

    control.style = Me.Resources ("Stylename")

    I get the error for this.

    Immediate reply will be appreciated as its urgent.

     

     

     

  2. Tina Stancheva
    Admin
    Tina Stancheva avatar
    3299 posts

    Posted 30 Mar 2010 Link to this post

    Hi Pan Hal,

    Setting control's style in code-behind shouldn't cause any problems. Can you please elaborate on the scenario you need to implement? if you can send us a sample of your code, we will be able to further investigate the issue you are facing.

    I attached an example of how you can set the style for RadButton and RadTreeView in code-behind. Can you please take a look at it and modify it to illustrate your scenario?

    Let me know how it goes.

    Regards,
    Tina Stancheva
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  3. Pan hal
    Pan hal avatar
    61 posts
    Member since:
    Aug 2009

    Posted 30 Mar 2010 Link to this post

    Here is my requirement.

     I have added a bitmapimage in Resource Dictionary
    <BitmapImage x:Key="ImgBlackout" UriSource="/Images/Blackout.png"/>

    Binding the bitmap in below in Bold.
    <ControlTemplate x:Name="OffTemplate">

     

    <Grid x:Name="PART_LayoutRoot" HorizontalAlignment="Stretch" VerticalAlignment="Center" Margin="4">

     

    <Grid.ColumnDefinitions>

     

     

    <ColumnDefinition Width="*" />

     

     

    </Grid.ColumnDefinitions>

     

     

    <Image Name="PART_Image" Source="{Binding Bitmap}" Grid.Column="0" Width="35" Height="35" ></Image>

     

     

    <Grid Grid.Column="1" HorizontalAlignment="Stretch" Margin="4,0,4,0" >

     

     

    <Grid.RowDefinitions>

     

    <RowDefinition Height="15" />

     

    </Grid.RowDefinitions>

     

     

    <HyperlinkButton Name="PART_EditButton" Content="{Binding Activity}" Grid.Row="0" FontSize="12" />

     

     

    <TextBlock Text="{Binding Description}" Grid.Row="1" FontSize="9" />

     

     

    <StackPanel Orientation="Horizontal" Grid.Row="2">

     

     

    <TextBlock Text="{Binding DisplayDate}" FontSize="9" />

     

     

    </StackPanel>

     

     

    </Grid>

     

    </Grid>

     

    </ControlTemplate>


    Then need to set Bitmap  in .vb(codebehind)  

     

    Public Overrides ReadOnly Property Bitmap() As System.Windows.Media.Imaging.BitmapImage

    Get 

     

    -----How to get the bitmapimage which is in ResourceDictionary

    Return New Bitmap(??????)
    End
    Get 

     

    End Property

     

     

     

     

     

     

     

     

  4. Milan
    Admin
    Milan avatar
    1989 posts

    Posted 31 Mar 2010 Link to this post

    Hello Pan hal,

    You could move the BitmapImage to the resources section of your UserControl and then you could easily get access to the resource:

    1.Dim image As BitmapImage
    2.image = Me.Resources("ImgBlackout")


    Regards,
    Milan
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Back to Top