开发者

Auto clip TextBlock in WPF

开发者 https://www.devze.com 2023-03-05 13:15 出处:网络
I have a TextBlock which is resizing itself depending on its Text which is causing my entire window to resize. I want the text to truncate instead - but I don\'t want to explicitly set the MaxWidth of

I have a TextBlock which is resizing itself depending on its Text which is causing my entire window to resize. I want the text to truncate instead - but I don't want to explicitly set the MaxWidth of the TextBlock in case the user resizes the window.

Before import button pressed:

Auto clip TextBlock in WPF

Current output:

Auto clip TextBlock in WPF

Desired output:

Auto clip TextBlock in WPF

   <Grid Grid.Row="3">
        <Grid.ColumnDefinitions>
            <ColumnDefinition></ColumnDefinition>
            <ColumnDefinition></ColumnDefinition>
            <ColumnDefinition Width="Auto"></ColumnDefinition>
            <ColumnDefinition Width="Auto"></ColumnDefinition>
        </Grid.ColumnDefinitions>
        <TextBlock Name="status" Margin="3" HorizontalAlignment="Stretch" TextTrimming="CharacterEllipsis"></TextBlock>
        <Label Name="lblPercentage" Grid.Colum开发者_开发百科n="1" HorizontalAlignment="Right" ></Label>
        <Button Grid.Column="2" Margin="3" Name="cmdImport" Click="import_Click" HorizontalAlignment="Right">Import</Button>
        <Button Grid.Column="3" Margin="3" Name="cmdCancel" Click="cancel_Click" HorizontalAlignment="Right">Close</Button>
    </Grid>


Just don't set SizeToContent on your Window.

0

精彩评论

暂无评论...
验证码 换一张
取 消