Steve's correct, Canvas doesn't really care how wide/high its children
are in regards to itself. Encapsulating the TextBlock inside a border
and using that as your Source of Truth should get you the results you
desire, but yeah you have a ghetto border now :)

Not sure why FontSize doesn't trigger SizeChanged though? in theory
the ActualWidth/ActualHeight should still trigger this event but given
FontSize may act differently to other FrameworkElements given it uses
glyphs etc.



Regards,

Scott Barnes

http://www.riagenic.com



On Wed, Sep 15, 2010 at 3:46 PM, Stephen Price <[email protected]> wrote:
> Without trying anything in code, I'd be guessing that putting the
> textblock onto/into the canvas makes it behave differently than when
> its in the border. I've seen quite a lot of sizing things behave
> differently depending upon the parent container.
>
> Have you tried it in a grid instead of a canvas? It might work
> (guessing, have not tried it out)
>
> On Wed, Sep 15, 2010 at 11:23 AM, Colin Savage <[email protected]> 
> wrote:
>> Before this list turns entirely into an ausdotnet trollfest, how about a
>> Silverlight question?
>>
>>
>>
>> Does anyone know why a textblock is not firing SizeChanged event when the
>> fontsize changes?
>>
>>
>>
>> Example:
>>
>> <Grid x:Name="LayoutRoot" Background="White">
>>
>>         <StackPanel>
>>
>>         <Button Content="Resize"
>>
>>                 Name="button1"
>>
>>                 Click="button1_Click" />
>>
>>         <TextBlock Name="result"
>>
>>                    Text="Size goes here"/>
>>
>>         <TextBlock Name="actual"
>>
>>                    Text="Actual goes here" />
>>
>>         </StackPanel>
>>
>>         <Canvas Height="200"
>>
>>                 HorizontalAlignment="Left"
>>
>>                 Margin="57,92,0,0"
>>
>>                 Name="canvas1"
>>
>>                 VerticalAlignment="Top"
>>
>>                 Width="311">
>>
>>             <!--<Border  Canvas.Top="10"
>>
>>                      Canvas.Left="10"
>>
>>                      BorderBrush="Green" BorderThickness="1">-->
>>
>>             <TextBlock Canvas.Top="10"
>>
>>                 Canvas.Left="10"
>>
>>                 Name="textblock1"
>>
>>                        Width="180"
>>
>>                         Text="Some Text" />
>>
>>             <!--</Border>-->
>>
>>         </Canvas>
>>
>>     </Grid>
>>
>>
>>
>>     public partial class MainPage : UserControl
>>
>>     {
>>
>>         public MainPage()
>>
>>         {
>>
>>             InitializeComponent();
>>
>>
>>
>>             textblock1.SizeChanged += textblock1_SizeChanged;
>>
>>         }
>>
>>
>>
>>         void textblock1_SizeChanged(object sender, SizeChangedEventArgs e)
>>
>>         {
>>
>>             result.Text = e.NewSize.ToString();
>>
>>         }
>>
>>
>>
>>         private void button1_Click(object sender, RoutedEventArgs e)
>>
>>         {
>>
>>             textblock1.FontSize += 1;
>>
>>
>>
>>             actual.Text = textblock1.ActualHeight.ToString();
>>
>>         }
>>
>>     }
>>
>>
>>
>>
>>
>> Note that if I increase the fontsize, the ActualHeight changes,  but the
>> SizeChanged event doesn’t. Uncomment the border around the textblock and it
>> does start firing.
>>
>>
>>
>> Regards,
>>
>> Colin Savage
>>
>> _______________________________________________
>> ozsilverlight mailing list
>> [email protected]
>> http://prdlxvm0001.codify.net/mailman/listinfo/ozsilverlight
>>
>>
> _______________________________________________
> ozsilverlight mailing list
> [email protected]
> http://prdlxvm0001.codify.net/mailman/listinfo/ozsilverlight
>
_______________________________________________
ozsilverlight mailing list
[email protected]
http://prdlxvm0001.codify.net/mailman/listinfo/ozsilverlight

Reply via email to