WPF 앱의 디스플레이 속성으로 인해 다른 글꼴 크기 처리?
문제
우리 그룹은 WPF에서 편집기 유형 앱을 구축하고 있습니다. 우리가 알아 차린 한 가지는 "Wind 그러나 "Wind
텍스트에 맞게 컨트롤을 자동으로 크기를 조정하는 것과 같이 이것을 멋지게 처리 할 수있는 방법이 있습니까?
다른 사람이 디스플레이 속성 및 접근성 옵션을 통해 완전히 다른 설정을 가질 수 있으므로 자신의 레이아웃에 맞게 버튼을 수동으로 크기를 조정하는 것을 망설입니다.
감사!
해결책
WPF 버튼 ~ 할 것이다 주어진 컨텐츠에 맞게 자동 크기를 조정하지만 크기를 시행하지 않고 크기가 수동으로 설정되지 않은 컨테이너 내부에있을 때만이 작업을 수행합니다. 다음 코드 스 니펫에서 글꼴 크기 로이 혼란을 입증하려면 다음과 같습니다.
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Button
Grid.Column="1"
Grid.Row="1"
FontSize="24"
Content="QWERTY"/>
</Grid>
버튼이 제한되어 있기 때문에 해당 버튼이 크게 표시되지 않은 것 같습니다. 이 문제를 해결하려면 크기 조정 방법을 결정해야합니다 (요소가 맹목적으로 자라면 요소가 겹칠 때 매우 복잡 할 수 있습니다). 제공된 패널 유형이 원하는 성장 동작을 수행하지 않으면 필요할 수 있습니다. 자신의 글을 쓰기 위해.
다른 팁
너비와 높이 특성을 사용하여 하드 코딩 된 요소 크기가 있습니까? WPF에서 권장되는 방법은 여러 레이아웃 컨테이너를 사용하는 것입니다.
다음은 하단에 두 개의 버튼을 놓고 상단에 텍스트 상자를 놓는 그리드의 예입니다.
<Grid>
<Grid.RowDefinitions>
<!-- TextBox row with unspecified height. -->
<RowDefinition Height="*"/>
<!-- Button row with automated height so it resizes to
fit the content -->
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<!-- Textbox on first row. -->
<TextBox Margin="3" Name="textBox1" Grid.Row="0" AcceptsReturn="True" />
<!-- StackPanel which lays the two buttons at the bottom horizontally.
RightToLeft is specified so that the first button appears on right.
-->
<StackPanel Grid.Row="1" HorizontalAlignment="Right"
Orientation="Horizontal" FlowDirection="RightToLeft">
<!-- The buttons. Only padding and margin are hardcoded so these
can resize to the contents -->
<Button Padding="3" Margin="3">OK</Button>
<Button Padding="3" Margin="3">Cancel</Button>
</StackPanel>
</Grid>
제휴하지 않습니다 StackOverflow