滑动面板WPF

时间:2015-09-21 15:29:27

标签: c# wpf wpf-animation

我有一个状态栏,里面有三个标签。有时标签必须有很多文字才能适合屏幕。我希望能够拖动和滑动每个标签中的文字,以显示不适合显示在屏幕上的文字。

我有没有办法在标签上做到这一点?或者我应该为此创建某种类型的自定义滑动面板?

如果我必须创建一个自定义面板,可以为我提供一些关于动画如何滑动的方向吗?

1 个答案:

答案 0 :(得分:1)

好的,看看GridSplitter不是大多数样本的控件,我在WPF项目上做了样本:

<Window x:Class="ScrollBarsSplitter.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:local="clr-namespace:ScrollBarsSplitter"
    mc:Ignorable="d"
    Title="MainWindow" Height="640" Width="1024">
<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="*"/>
        <RowDefinition Height="Auto"/>

    </Grid.RowDefinitions>
    <TextBlock Grid.Row="0" Text="Test the Title" Background="Navy" Foreground="White" Padding="4" FontSize="14" />
    <TextBlock Grid.Row="1" Text="Test contents" Background="White" Foreground="Navy" Padding="4" FontSize="14" />
    <StatusBar Grid.Row="2" MinHeight="48" Background="Aquamarine">
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="10"/>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="10"/>
                <ColumnDefinition Width="Auto"/>

            </Grid.ColumnDefinitions>
            <TextBlock Grid.Column="0" Text="This is the text of the first panel of the grid" Margin="10 2 10 2" VerticalAlignment="Center"/>
            <GridSplitter Grid.Column="1" ResizeBehavior="PreviousAndNext" HorizontalAlignment="Stretch"  Background="Red" VerticalAlignment="Stretch" MinHeight="48"/>
            <TextBlock Grid.Column="2" Text="This is the text of the second panel of the grid" Margin="10 2 10 2" VerticalAlignment="Center"/>
            <GridSplitter Grid.Column="3" ResizeBehavior="PreviousAndNext" HorizontalAlignment="Stretch"  VerticalAlignment="Stretch" Background="Red" MinHeight="48"/>
            <TextBlock Grid.Column="4" Text="This is the text of the third panel of the grid" Margin="10 2 10 2" VerticalAlignment="Center"/>
        </Grid>

    </StatusBar>
</Grid>

这是带有状态栏和分割器的窗口,诀窍是你必须将textblock列设置为Auto,以便分割器能够移动并改变我使用一些难看的颜色以使事物可见的大小。在后面的代码中没有任何东西,如果你想在拖动分割器时做某事,你可以处理DragCompleted事件。