我想一個button
內調整content
這樣,當我「調整」我的窗口,buttons
也得到調整,但內button
的content
大小保持不變?
我應該怎麼做才能使內容調整WRT按鈕的大小。
感謝,費薩爾
PS:我使用GRID佈局WPF。
我想一個button
內調整content
這樣,當我「調整」我的窗口,buttons
也得到調整,但內button
的content
大小保持不變?
我應該怎麼做才能使內容調整WRT按鈕的大小。
感謝,費薩爾
PS:我使用GRID佈局WPF。
最簡單的,我能想到的,你這樣做的方式是讓你使用一個ViewBox
元素你Button
的內線:
<Button>
<ViewBox>
<!--Your Button content-->
</ViewBox>
</Button>
我認爲這個問題的最好辦法是實際上使一個很小的轉換器,它會動態地控制文本大小。
這裏是這種轉換器的一個例子:
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();
}
}
然後在這裏是這個類的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>
希望這有助於,讓我知道你是否會有任何問題。
K.
-1。這應該通過一個簡單的'Viewbox'來實現,而不必訴諸於程序代碼。 –
它是一個問題的另一個解決方案,以及一個有效的解決方案,如果您不能使用ViewBox,那麼這個解決方案可以作爲一個很好的選擇。 – kosdos
創建類似下面的解決方案字號的行爲。 [如何自動縮放的一組控制字體大小] [1] [1]:http://stackoverflow.com/questions/15641473/how-to-automatically-scale-字體大小爲一組控件 –
@FaisalAshfaq,雖然我讚賞你回到這裏並想向用戶展示你的最終解決方案的事實,但我應該指出這樣做是不正確的通過編輯別人的答案。最好在你的問題*的底部添加一個問題編輯或更新來展示那種東西。 – Sheridan
我明白了。下次我會按照同樣的方式[當然如你所說]。非常感謝你! –