Ive got a simple StackPanel
which contains a TextBlock
and ProgressBar
.
On startup, the width of the ProgressBar
is perfect - it has sized itself to fit in its boundaries (stretched to '150' by it's sibling TextBlock
).
However, when the TextBlock
has stretched to a width further than 150 due to additional Text (which the ProgressBar
nicely expands to fill the extra area), and is then shrunk, due to the removal of it's Text, the Width of the progress bar remains.
This only happens when IsIndeterminate = true
The following hastily put together code will show the workings;
<Grid HorizontalAlignment="Center" VerticalAlignment="Center">
<StackPanel>
<TextBlock MinWidth="150" Name="tb" HorizontalAlignment="Left"></TextBlock>
<ProgressBar MinHeight="20" IsIndeterminate="True"/>
</StackPanel>
</Grid>
public MainWindow()
{
InitializeComponent();
new Thread(() =>
{
Thread.Sleep(2000);
App.Current.Dispatcher.Invoke(() =>
{
tb.Text = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
});
Thread.Sleep(1000);
App.Current.Dispatcher.Invoke(() =>
{
tb.Text = "A";
});
}).Start();
}