I have a TextBlock that’s on top of a Button in a Grid. I’d like to have then displayed thus:
"some very long text" <-- text
"that doesn't fit" <-- text wrapped
[my button text size] <-- button
However, what I’ve got is this:
"some very long text that doesn't fit" <-- text
[my button text size] <-- button
My issue is that the text in the Button is dynamically set through localized resource and therefore the width of the button changes dynamically.
The static solution that works for non-dynamic Button resize is:
<TextBlock
Margin="5"
TextWrapping="Wrap"
Width="{Binding ElementName=requestDemoButton, Path=RenderSize.Width}"
Text="{Binding Path=Resource.Text, Source={StaticResource LocalizedStrings }}"
/>
<Button
x:Name="requestDemoButton"
Margin="5"
Height="Auto"
Width="Auto"
HorizontalAlignment="Right"
Content="{Binding Path=Resource.Button, Source={StaticResource LocalizedStrings }}" />
Ideas, anyone? I’m currently thinking of sticking a Behavior class to the TextBlock that listens for the SizeChanged event on the Button. I’d like to have a built-in solution if it exists.
If anyone’s interested, here’s how I’ve done in in a behaviour.
I pass on
HeightorWidthaccording to the property I want bound.Here’s the class:
And here’s how it’s used:
Hope that might help someone else.