-
Jan 30th, 2014, 05:01 PM
#1
Thread Starter
Hyperactive Member
button text
I am working on WPF program and I have a button which display 2 lines of text. What I need help on is, I want the top line of the text to have bigger font than the bottom text but how. I would be grateful if anyone can help. thanks
-
Jan 30th, 2014, 05:39 PM
#2
Re: button text
that's a WPF question, which should be asked in the WPF forum. i'll notify a moderator
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jan 30th, 2014, 05:56 PM
#3
Re: button text
The thing that comes to my mind is the FlowDocument. You could do something like this:
Code:
<Button Name="Button1">
<FlowDocument>
<Paragraph>
<Span FontSize="20">Hello</Span>
<LineBreak></LineBreak>
<Span FontSize="10">World</Span>
</Paragraph>
</FlowDocument>
</Button>
Last edited by dday9; Jan 30th, 2014 at 06:04 PM.
-
Jan 31st, 2014, 11:31 AM
#4
Thread Starter
Hyperactive Member
Re: button text
Originally Posted by dday9
The thing that comes to my mind is the FlowDocument. You could do something like this:
Code:
<Button Name="Button1">
<FlowDocument>
<Paragraph>
<Span FontSize="20">Hello</Span>
<LineBreak></LineBreak>
<Span FontSize="10">World</Span>
</Paragraph>
</FlowDocument>
</Button>
Thanks dday's. Is it possible to do it in code because the data will be pull from sqlserver. Thanks
-
Jan 31st, 2014, 11:43 AM
#5
Re: button text
Originally Posted by wiadus
Thanks dday's. Is it possible to do it in code because the data will be pull from sqlserver. Thanks
I don't understand, this is the XAML code.
Last edited by dday9; Jan 31st, 2014 at 11:44 AM.
Reason: Extensible Application Markup Language, Not Extensible Markup Language
-
Jan 31st, 2014, 12:42 PM
#6
Re: button text
I think what the OP is asking for is that the text will be coming from a database... so the XAML should only need a placeholder, and then through the vb code, replaced with the value retrieved from the database. So the button would be templated in the XAML, with the actual text inserted later.
-tg
-
Jan 31st, 2014, 01:07 PM
#7
Re: button text
Thread moved to the WPF forum.
-
Jan 31st, 2014, 03:56 PM
#8
Thread Starter
Hyperactive Member
Re: button text
Sorry dday's what I meant was code in vb as the text will come from database. Thanks
-
Jan 31st, 2014, 04:21 PM
#9
Re: button text
Then you would do what TG suggested in post #6. I'm not good with WPF but I think that you could do something like this:
Code:
<Paragraph>
<Span FontSize="20" Name="Line1" />
<LineBreak></LineBreak>
<Span FontSize="10" Name="Line2" />
</Paragraph>
But I wouldn't know how to set the text of those spans. That would be left to some WPF experts.
-
Feb 1st, 2014, 03:15 AM
#10
Re: button text
You could put two TextBlock inside the Button and give them different names
Code:
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Button Content="Button" Height="44" HorizontalAlignment="Left" Margin="316,125,0,0" Name="button1" VerticalAlignment="Top" Width="114" Click="button1_Click" />
<Button Height="69" HorizontalAlignment="Left" Margin="94,76,0,0" Name="button2" VerticalAlignment="Top" Width="112" >
<StackPanel>
<TextBlock Name="Label1" FontSize="20" Text="test"></TextBlock>
<TextBlock Name="Label2" FontSize="12" Text="test"></TextBlock>
</StackPanel>
</Button>
</Grid>
</Window>
And set the Text like
Code:
private void button1_Click(object sender, RoutedEventArgs e)
{
Label2.Text = "Dee-u";
Label1.Text = "Experiment";
}
-
Feb 1st, 2014, 11:40 AM
#11
Thread Starter
Hyperactive Member
-
Feb 1st, 2014, 05:31 PM
#12
Re: button text
Originally Posted by techgnome
I think what the OP is asking for is that the text will be coming from a database... so the XAML should only need a placeholder, and then through the vb code, replaced with the value retrieved from the database. So the button would be templated in the XAML, with the actual text inserted later.
-tg
It can easily be done by binding button to property or method in the view model. Sorry I don't have tool make quick sample so here is a link (one of many):
http://stackoverflow.com/questions/3...button-content
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|