은 뷰 박스에 관계없이 크기의 사용 가능한 공간을 채우기 위해 설계되었습니다 당신이 버튼 콘텐츠의 크기를 조정할 수 있습니다 뷰 박스 컨트롤을 사용 : 여기
예 (Viewbox added
코멘트 확인)입니다 .
첫번째 방법
<Button Content="Long Text Long Text Long Text Long Text Long Text Long Text" Foreground="Red" Height="30">
<Button.ContentTemplate>
<DataTemplate>
<Viewbox >
<TextBlock Margin="5,0,5,0" Text="{Binding Path=Content,RelativeSource={RelativeSource AncestorType={x:Type Button}}}" ></TextBlock>
</Viewbox>
</DataTemplate>
</Button.ContentTemplate>
</Button>
참고 : 또한 X 사용하여 자원이 DataTemplate을 저장할 수 있습니다 : 키를 누른 다음 버튼을 <Button ContentTemplate={StaticResource DatatemplateKeyname}/>
두번째 방법에 할당
<Button Height="30" Width="200" Foreground="Red">
<Button.Content>
<Viewbox>
<TextBlock Margin="5,0,5,0" Text="Long Text Long Text Long Text Long Text Long Text Long Text" ></TextBlock>
</Viewbox>
</Button.Content>
</Button>
참고 : 당신은 뷰 박스에 TextBlock의 콘텐츠를 저장하고 바인딩 여기에 태그 속성을 사용할 수 있습니다 TextBlock Text="{Binding Path=Tag,RelativeSource={RelativeSource AncestorType={x:Type Button}}}"
세번째 방법
<!--Here Width is store in Button "Tag" property.-->
<Viewbox Height="30" Width="{Binding ElementName=Buttonname,Path=Tag}">
<Button x:Name="Buttonname" Content="Long Text Long Text Long Text Long Text Long Text Long Text Long Text Long Text Long Text Long Text Long Text Long Text" Tag="200" Foreground="Red"/>
</Viewbox>