1

I want to resize content within a button so that when I "resize" my window, buttons also gets resized but size of content within button remains unchanged?

What should I do in order to make contents resized WRT button size.

Thanks, Faisal

PS: I am using GRID layout in WPF. enter image description here

Faisal Ashfaq
  • 2,545
  • 4
  • 28
  • 41
  • Create font size behavior like below solution. [How to automatically scale font size for a group of controls][1] [1]: http://stackoverflow.com/questions/15641473/how-to-automatically-scale-font-size-for-a-group-of-controls – Majid gharaei Nov 21 '13 at 17:00
  • @FaisalAshfaq, while I applaud the fact that you have come back here and want to show the users your final solution, I should point out that it is not correct to do that by editing someone else's answer. It's probably best to add a question edit or update to the bottom of *your question* to show that kind of stuff. – Sheridan Nov 21 '13 at 17:28
  • I got it. I will do the same way[of course as you told] next time. Thank you very much! – Faisal Ashfaq Nov 21 '13 at 17:35

2 Answers2

3

The easiest way that I can think of you doing that is for you to use a ViewBox element inside your Buttons:

<Button>
    <ViewBox>
        <!--Your Button content--> 
    </ViewBox>
</Button>
Sheridan
  • 68,826
  • 24
  • 143
  • 183
0

I believe the best approach to this issue would be to actually make a tiny converter which would be dynamically controlling the text size.

Here is an example of such a converter:

C#

using System.Globalization;

public class FontSizeConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        double actualHeight = System.Convert.ToDouble(value);
        int fontSize = (int)(actualHeight * .5);
        return fontSize;
    }

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        throw new NotImplementedException();
    }
}

And then here is the usage of this class within your xaml:

XAML

...
<Window.Resources>
    <l:FontSizeConverter x:Key="FSConverter" />
</Window.Resources>
...
<Grid>   
    <Button Content="Dat Button" FontSize="{Binding Path=ActualHeight, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=Grid}, Converter={StaticResource FSConverter}}"/>    
</Grid>

Hope this helps, let me know if you will have any issues with that.

K.

kosdos
  • 358
  • 3
  • 12