Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF Statusbar, stretch textblock to take as much space as possible

I created my own simple statusbarcontrol with 3 TextBlocks. Now I would like that the first Textblock takes as much space as it has available. That I don't seem to get done.. Now it only takes the space needed to display the text.

XAML:

  <StatusBar Background="{StaticResource GradientBrush}">
<StatusBar.ItemsPanel>
  <ItemsPanelTemplate>
    <Grid>
      <Grid.RowDefinitions>
        <RowDefinition Height="Auto" />
      </Grid.RowDefinitions>
      <Grid.ColumnDefinitions>
        <ColumnDefinition Width="*" />
        <ColumnDefinition Width="Auto" />
        <ColumnDefinition Width="Auto" />
        <ColumnDefinition Width="Auto" />
        <ColumnDefinition Width="Auto" />
      </Grid.ColumnDefinitions>
    </Grid>
  </ItemsPanelTemplate>
</StatusBar.ItemsPanel>
<StatusBarItem HorizontalAlignment="Left"
               HorizontalContentAlignment="Right">
  <Border BorderThickness="1"
          BorderBrush="Black"
          Padding="5 0 5 0"
          Background="White">
    <TextBlock Text="{Binding Message, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
             Foreground="{Binding TextColorMessage}"
             Background="White"
             />
  </Border>
</StatusBarItem>
<Separator Grid.Column="1" />
<StatusBarItem Grid.Column="2"
               HorizontalAlignment="Right">
  <TextBlock Text="{Binding Path=DatabaseName, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
</StatusBarItem>
<Separator Grid.Column="3" />
<StatusBarItem Grid.Column="4"
               HorizontalAlignment="Right">
  <TextBlock Text="{Binding Path=ComputerName}" />
</StatusBarItem>

My StatusBar

like image 265
PitAttack76 Avatar asked Dec 14 '12 13:12

PitAttack76


2 Answers

Try setting the StatusBarItem's HorizontalAlignment and HorizontalContentAlignment to Stretch.

like image 27
Florian Gl Avatar answered Sep 20 '22 17:09

Florian Gl


Well this is pretty straight forward: you had set the StatusBarItem HorizontalAlignment="Left" when it should be "strech", same for the HorizontalContentAlignment. Also would suggest setting margin=0 on the border. this is what i did so it will work for me:

<StatusBarItem HorizontalAlignment="Stretch"
               HorizontalContentAlignment="Stretch">
    <Border BorderThickness="1"
            BorderBrush="Black"
            Margin="0"
            Padding="5 0 5 0"
            Background="White">
        <TextBlock Text="{Binding Message, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                   Foreground="{Binding TextColorMessage}"
                   Background="White"/>
    </Border>
</StatusBarItem>

if this is helpful please mark as answer

like image 51
Eyal H Avatar answered Sep 21 '22 17:09

Eyal H