나는 그리드에 버튼이있다. 버튼의 크기는 격자 레이아웃의 구성 요소입니다. 단추의 크기를 변경하지 않고 단추 내용을 프로그래밍 방식으로 변경하고이 단추가 들어있는 표를 다시 레이아웃하려고합니다. ,콘텐츠를 변경하면 버튼의 크기가 변경되는 것을 어떻게 막을 수 있습니까?
BtnInstall.Content = "Cancel Download";
// or
BtnInstall.Content = "Download, Unzip and Install";
내가 "다운로드를 변경하려면 :
<Grid Grid.Row="0" Margin="5">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition />
<RowDefinition />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Label Grid.ColumnSpan="4" Grid.Row="0" Style="{StaticResource IfStyle}">Don't have Apache Ant yet?</Label>
<Label Grid.Column="0" Grid.Row="1" VerticalAlignment="Center" HorizontalAlignment="Right">Download URL:</Label>
<TextBox Name="TxtDownloadUrl" Grid.Column="1" Grid.ColumnSpan="3" Grid.Row="1" VerticalAlignment="Center" />
<Label Grid.Column="0" Grid.Row="2" VerticalAlignment="Center" HorizontalAlignment="Right">Destination Directory:</Label>
<TextBox Name="TxtDestinationDir" Grid.Column="1" Grid.ColumnSpan="2" Grid.Row="2" VerticalAlignment="Center" Margin="0,0,10,0" />
<Button Grid.Row="2" Grid.Column="3" VerticalAlignment="Center" Name="BtnBrowseDestination" HorizontalAlignment="Stretch">...</Button>
<Canvas Name="ProgressCanvas" Grid.Column="0" Grid.ColumnSpan="2" Grid.Row="3" Height="58" Margin="10" SizeChanged="OnCanvasResize">
<Image Canvas.Left="4" Canvas.Top="4" Source="/VSADTWizards;component/images/Globe.png" Stretch="Fill" Height="48" Width="48" />
<Image Canvas.Right="4" Canvas.Top="4" Source="/VSADTWizards;component/images/Computer.png" Stretch="Fill" Height="48" Width="48" />
<Label Canvas.Left="60" Canvas.Top="4" Name="LabelTotalBytes" />
<Label Canvas.Right="60" Canvas.Top="4" Name="LabelReceivedBytes" />
</Canvas>
<Button Name="BtnInstall" Grid.Column="2" Grid.ColumnSpan="2" Grid.Row="3" VerticalAlignment="Center" HorizontalAlignment="Right" Padding="10">Download, Unzip and Install</Button>
</Grid>
내가 같은 간단한 내용 업데이 트를하고있어, 내용을 변경하려면 :
이 그리드에 대한 XAML입니다 압축 해제 및 설치 "텍스트를"취소 다운로드 "및 다시 크기를 조정하지 않고.
다른 DPI 설정이나 언어 등이 있으면 버튼을 올바르게 렌더링하고 싶기 때문에 최소/최대 크기를 설정하고 싶지 않습니다. 나는 그것이 초기에 배치 된 후에 크기를 고정시키는 것이 괜찮을 것이라고 생각하지만, 그렇게하는 방법을 이해할 수는 없었다.
xaml에서 이것을 엄격하게 원하십니까? 아니면 약간의 코드를 사용해도 되겠습니까? –
DPI를 변경해도 고정 된 너비 값으로 단추 크기가 조정되지 않습니다. WPF의 크기는 픽셀 단위가 아니며 시스템 DPI를 조정하는 "장치 독립적 단위"입니다. –
@Meleak : 코드 숨김이 완벽합니다. –