Skip to main content
Home Forums Silverlight Programming Programming with .NET - General textblock foreground problem
9 replies. Latest Post by hansmukh999 on January 31, 2008.
(1)
hansmukh999
Member
14 points
19 Posts
01-30-2008 2:26 AM |
hi all.. can any body help in findaing way that vil help me to change foregroung property dinamacly from code behind(C#)i have following text block in mt MyTest.xaml <TextBlock Opacity="0.0" RenderTransformOrigin="0.5,0.5" Width="140" Height="43"
<
// Setting/Getting textpublic string TextElementText{get{ return textElement.Text;}set{ textElement.Text = value;}}// Setting/Getting Font Sizepublic double TextElementFontSize{get{ return textElement.FontSize;}set{ textElement.FontSize = value;}}// Setting/Getting Opacity public double TextElementOpacity{get{ return textElement.Opacity;}set{ textElement.Opacity = value;}}
but stuck here, dont know how to assign foreground value by this..public string TextElementForeground{set{textElement.Foreground = value}get{return textElement.Foreground;}}
i will be very thankful of positive reply that let me fix this..thx all
mchlsync
Star
14606 points
2,730 Posts
01-30-2008 2:58 AM |
hansmukh999:can any body help in findaing way that vil help me to change foregroung property dinamacly from code behind
Page.xaml
<TextBlock x:Name="myTextBlock" Text="This is my test!" />
Page.xaml.cs ( Page_Loaded event)
myTextBlock.Foreground = new SolidColorBrush (Colors.Red);
but your code looks like you are trying to create your own control.
01-30-2008 3:16 AM |
thx for the reply..it is workig cool..now the problem is that how come i convert string to color. i am geting color name in string format
string colorToApply=""Yellow";
TextElementForeground = new SolidColorBrush(Color.xxxx);
01-30-2008 5:24 AM |
hansmukh999:thx for the reply..it is workig cool.
Your welcome. Please mark as answered on that post if it's working. Thanks. :)
hansmukh999: how come i convert string to color. i am geting color name in string format
Normally, we used to convert the string to known-color by using TypeDescriptor. Unfortunately, I'm not able to use it in Silverlight project.
bluearc
Participant
1500 points
325 Posts
01-30-2008 6:40 AM |
Ttyr this..
this will help you a lot..
using
{
}
Save above code in any .cs file
to use this in your code
use it like this
Ravs.
TextElementForeground = new SolidColorBrush(cr.GetThisColor(colorToApply));
IF this answer helps you the mark it answered
01-30-2008 7:27 AM |
Great job..
BTW, what is "theType"?
01-30-2008 7:35 AM |
Sorry, I just forgot to change the variable.. initially i used theType , then i renamed to colorType... did a mistake in hurry...
Now it is fine.. have a look to the code given below...
using System;
"If this answer helps you then mark it answered"
mchlSync
01-30-2008 7:40 AM |
Great.. Thanks a lot. (I can't mark it as answered since I'm not thread starter. However, I'm appreciate your code. I've learnt something today. :) I was looking too much for TypeDescriptor and ColorConverter. )
01-30-2008 8:00 AM |
Thanks for the comments, well it it don't matter that much if it is not marked as answered...
as long as i can contribute my part to the community....
Well, normally we don't look at thr Reflection... but i belive it is the most powerfull.... Namespace...
01-31-2008 8:17 AM |
thx both of you, it is working cool now, as new to silver light ist is nt possible for me to do this, but your experienced help me , cant help saying u guys thanx again..
i vill disturb u guys again in future..heheh.chill n god bless u