|
Hi All,
I am new to the Silverlight world. can anybody please help me in wrapping the text in the textblock which is there in the Canvas.
Is there any way to do it, please help me.
Thanks in Advance.
Thanks & Regards,
Abdul Aleem Mohammad
St Louis MO - USA
modified 25-Oct-11 20:56pm.
|
|
|
|
|
Set the TextBlock's TextWrapping property to TextWrapping.Wrap. A Canvas parent won't resize or clip the TextBlock so you'll need to handle that yourself.
Mark Salsbery
|
|
|
|
|
But if I use anyother container like stackpanel or grid then the text is taking all the browser width and making all the page uncomfortable.
What can I do, can you please help me, I am working around it, any link or any kind of help is greatly appreciated.
Thanks in advance. In no way I am getting it, please help me.
Thanks & Regards,
Abdul Aleem Mohammad
St Louis MO - USA
|
|
|
|
|
Set the width and height of the textblock explicitly.
Mark Salsbery
|
|
|
|
|
Hi,
Can you please help me little bit by using any link or code snippet please.
I request you, I have been trying it so severely.
Thanks,
Abdul.
Thanks & Regards,
Abdul Aleem Mohammad
St Louis MO - USA
|
|
|
|
|
<TextBlock TextWrapping="Wrap" Width="100" Height="100" Canvas.Left="20" Canvas.Top="20" />
Mark Salsbery
|
|
|
|
|
Hi,
This width should depend upon the parent elements width or it should depend upon the ViewModel property that is binding to this textblock.
According to any of them it should able to take the value and wrap the text and fit within the browser but should not stretch beyond the browser size or monitor size.
Thanks,
Abdul
Thanks & Regards,
Abdul Aleem Mohammad
St Louis MO - USA
|
|
|
|
|
indian143 wrote: This width should depend upon the parent elements width
Then a Canvas isn't necessarily the proper parent element - it rarely is except for drawings and shapes etc. There's better panel elements for layout if you don't need pixel-level positioning.
If you must use a canvas then you could handle the canvas' SizeChanged event and in your handler code resize and/or reposition the textblock based on the values of the canvas' ActualWidth/ActualHeight properties.
Mark Salsbery
|
|
|
|
|
Hi,
Please by using anything if it works thats fine for me, its taking lot of time to resolve this bug than creating really something.
I dont know what to do its effecting my SLAs
Thanks,
Abdul
Thanks & Regards,
Abdul Aleem Mohammad
St Louis MO - USA
|
|
|
|
|
Hi
I have a class library with code that is compatible with both Silverlight and standard .net libraries. (the minor incompatibilities can be solved with #if)
How I can compile the code for both of these platforms? I mean - how do I set up Visual Studio to have two output configurations - one for .net, one for silverlight, so that my bin folder will contain two compiled .dlls?
The project was initially created as Widnows Class Library and now I don't even know how to tell the VS to use Silverlight libraries to begin with
|
|
|
|
|
|
I want to create a control and use its size as data input from user. So adjust the control size by user's mouse is required, just like what we do to the window? Is there any existing property we can set to do this in WPF ?
|
|
|
|
|
Here[^] is an excellent article on how to move and reshape controls in your app.
Good Luck!
When I was a coder, we worked on algorithms. Today, we memorize APIs for countless libraries — those libraries have the algorithms - Eric Allman
|
|
|
|
|
Thank you ! That's exactly what I want !
|
|
|
|
|
No Problem
When I was a coder, we worked on algorithms. Today, we memorize APIs for countless libraries — those libraries have the algorithms - Eric Allman
|
|
|
|
|
I have styled a list so that the list items appear as hyperlinks. Here's my xaml:
<UserControl.Resources>
<converters:ProjectTypeImageValueConverter x:Key="projectTypeConverter"/>
<!--This is the template for the Recent projects list items-->
<DataTemplate DataType="{x:Type local:RecentProjectModel}">
<StackPanel Orientation="Horizontal"
Margin="2">
<Image Source="{Binding ProjectType, Converter={StaticResource projectTypeConverter}}"
Margin="0,0,5,0"/>
<TextBlock Width="150">
<Hyperlink Foreground="RoyalBlue">
<TextBlock Text="{Binding Caption}"/>
</Hyperlink>
</TextBlock>
</StackPanel>
</DataTemplate>
</UserControl.Resources>
and
<ListBox x:Name="lstRecent"
Grid.Row="1"
Grid.Column="0"
ItemsSource="{Binding RecentProjects}"
SelectedItem="{Binding SelectedRecentProject}"
BorderThickness="0"
Margin="3"
MinWidth="235"/>
When I click the link, the SelectedRecentProject is not set. If I click the image of the list item, it is set. How do I set the SelectedRecentProject when the link is clicked?
Thanks
Everything makes sense in someone's mind
|
|
|
|
|
It doesn't work. No response.
Everything makes sense in someone's mind
|
|
|
|
|
Wow, I had to write a quick sample app for this one. The Hyperlink / TextBlock combo is eating the mouse down. You'll notice that the selection changed event never gets fired. You can set IsHitTestVisible="False" on the TextBlock (but you will lose the hand cursor)... or you need to derive a "HyperlinkEx" class from Hyperlink and set the focus to the parent yourself, or you can change controls to something else . If you are OK with losing the hand cursor when they mouse over the link, the the IsHitTestVisible="False" is the quickest fix.
EDIT: actually, you probably need to do the derived class thing on TextBlock since Hyperlink isn't a UI element. Just derive a class from TextBlock and override PreviewMouseLeftButtonDown and chase up the visual tree til you hit the ListBoxItem. I whipped this out in a few seconds and it works without losing the hand cursor. I'll leave the clean up / error checking to you .
public class TextBlockEx : TextBlock
{
public TextBlockEx()
: base()
{
this.PreviewMouseLeftButtonDown += new MouseButtonEventHandler(HyperlinkEx_PreviewMouseLeftButtonDown);
//this.MouseLeftButtonDown += new MouseButtonEventHandler(HyperlinkEx_MouseLeftButtonDown);
}
void HyperlinkEx_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
object v = this;
while (v != null)
{
if (v is ListBoxItem)
{
((ListBoxItem)v).IsSelected = true;
((ListBoxItem)v).Focus();
break;
}
v = VisualTreeHelper.GetParent((DependencyObject)v);
}
e.Handled = true;
}
}
|
|
|
|
|
ya, that did it. I'll deal with the cursor some other time. It's not that big of a deal right now.
Thanks
Everything makes sense in someone's mind
|
|
|
|
|
I edited the message as you responded... I've got the "TextBlockEx" working for you... just needs a bit of clean up and doesn't lose the mouse cursor .
|
|
|
|
|
Excellent. I'll throw it in later today
Many thanks
Everything makes sense in someone's mind
|
|
|
|
|
This worked perfectly. Thank you!!!
Everything makes sense in someone's mind
|
|
|
|
|
I have this data template
<UserControl.Resources>
<!--
<DataTemplate DataType="{x:Type local:RecentProjectModel}">
<StackPanel Orientation="Horizontal">
<Image Source="/...;component/Media/Graphics/abtech_triangle_blue_small.png"
Margin="0,0,5,0"/>
<TextBlock Width="150">
<Hyperlink>
<TextBlock Text="{Binding Caption}"/>
</Hyperlink>
</TextBlock>
</StackPanel>
</DataTemplate>
</UserControl.Resources>
I would like to change the image based off the value of a property called ProjectType on the RecentProjectModel class.
How do I do this?
Thanks
Everything makes sense in someone's mind
modified 24-Oct-11 13:44pm.
|
|
|
|
|
Just bind to ProjectType and use a value converter, or have your VM expose an ImageSource property and bind to that directly. Is your binding to Caption working? I seem to recall there are some issues when using binding inside of a data template, but I can't recall off the top of my head.
|
|
|
|
|
Yes the caption is working.
Never used a converter before. Got an exmaple?
Everything makes sense in someone's mind
|
|
|
|