This is a migrated thread and some comments may be shown as answers.

Styles in codebehind (.vb)

3 Answers 21 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Pan hal
Top achievements
Rank 1
Pan hal asked on 25 Mar 2010, 10:34 PM

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.

 

 

 

3 Answers, 1 is accepted

Sort by
0
Tina Stancheva
Telerik team
answered on 30 Mar 2010, 04:34 PM
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.
0
Pan hal
Top achievements
Rank 1
answered on 30 Mar 2010, 10:19 PM

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

 

 

 

 

 

 

 

 

0
Milan
Telerik team
answered on 31 Mar 2010, 07:58 AM
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.
Tags
General Discussions
Asked by
Pan hal
Top achievements
Rank 1
Answers by
Tina Stancheva
Telerik team
Pan hal
Top achievements
Rank 1
Milan
Telerik team
Share this question
or