在StatusBar中使用分隔符

时间:2012-01-26 21:10:30

标签: wpf xaml statusbar

我有一个带有StatusBar控件的WPF窗口。下面是状态栏的xaml。我想在StatusBarItems之间放置一个Separator。但是会发生的是所有分隔符都位于第一个StatusBarItem之后。

如何在StatusBar中的每个项目之后定位分隔符?

我注意到如果我没有使用ItemsPanelTemplate分隔符正常工作。如何让下面的xaml中的分隔符正确定位?

        <StatusBar Grid.Row="2" Height="23" Name="myStatusBar" VerticalAlignment="Bottom" >
        <StatusBar.ItemsPanel>
            <ItemsPanelTemplate>
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="*"/>
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="100"/>
                        <ColumnDefinition Width="*"/>
                        <ColumnDefinition Width="100"/>
                        <ColumnDefinition Width="100"/>
                        <ColumnDefinition Width="100"/>
                    </Grid.ColumnDefinitions>
                </Grid>
            </ItemsPanelTemplate>
        </StatusBar.ItemsPanel>
        <StatusBarItem Grid.Column="0">
            <StackPanel Orientation="Horizontal">
                <Image Source="..\Images\bullet_green.png" Height="15" Width="15" />
                <TextBlock Name="txtStatus" Height="18" Width="77" Text="{Binding StatusBarStatus}"/>
            </StackPanel>
        </StatusBarItem>
<Separator Width="1"/>
        <StatusBarItem Grid.Column="1">
            <StackPanel Orientation="Horizontal">
                <Image Source="..\Images\user_add.png" Height="15" Width="15" />
                <TextBlock Name="txtCurrentContact" Text="{Binding StatusBarCurrentContact}" />
            </StackPanel>
        </StatusBarItem>
<Separator Width="1"/>
        <StatusBarItem Grid.Column="2">
            <!--<ProgressBar Value="30" Width="80" Height="18"/>-->
            <StackPanel Orientation="Horizontal">
                <Image Source="..\Images\database03.png" Height="15" Width="15" />
                <TextBlock Name="txtDatabase" Text="{Binding StatusBarDatabase}" />
            </StackPanel>
        </StatusBarItem>
<Separator Width="1"/>
        <StatusBarItem Grid.Column="3">
            <TextBlock Name="txtMode" Text="{Binding StatusBarMode}"/>
        </StatusBarItem>

        <StatusBarItem Grid.Column="4">
            <TextBlock Name="txtTally" Text="{Binding StatusBarTally}"/>
        </StatusBarItem>
    </StatusBar>

1 个答案:

答案 0 :(得分:10)

所有分隔符都在第0列中。将它们放在一列中,即:

 <StatusBarItem Grid.Column="0">
        <StackPanel Orientation="Horizontal">
            <Image Source="..\Images\bullet_green.png" Height="15" Width="15" />
            <TextBlock Name="txtStatus" Height="18" Width="77" Text="{Binding StatusBarStatus}"/>
        </StackPanel>
    </StatusBarItem>
    <Separator Width="1" Grid.ColumnSpan="2" Grid.Column="0" HorizontalAlignment="Center"/>
    <StatusBarItem Grid.Column="1">
        <StackPanel Orientation="Horizontal">
            <Image Source="..\Images\user_add.png" Height="15" Width="15" />
            <TextBlock Name="txtCurrentContact" Text="{Binding StatusBarCurrentContact}" />
        </StackPanel>
    </StatusBarItem>