【问题标题】:Sliding Panel WPF滑动面板 WPF
【发布时间】:2015-09-21 15:29:26
【问题描述】:

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

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

如果我必须创建一个自定义面板,能否为我提供一些关于如何为文本滑动设置动画的方向?

【问题讨论】:

  • 将文本放在工具提示中,这样当有人将鼠标悬停在它上面时它就会显示出来。这是标准的用户界面。
  • @Will 嗨,Will,我之前问过一个类似的问题,我相信也是你在那里回答的!我实现了标准格式,但我想最小化应用程序中的工具提示,因此我试图制作滑动面板。不过还是谢谢。
  • 滑动面板的问题在于,为您提供滚动条的控件 Scrollviewer 需要空间,因此您应该找到一种方法来创建模板以使滚动条非常小,或者您需要创建一个自定义控件,带有文本控件和 2 个按钮,用于在太大时移动文本,但创建起来看起来并不简单。
  • @Sabrina_cs 我的计划是创建一个自定义面板,允许您将其拖到一边以滑动它。这将绕过对滚动查看器的需求。
  • 在这种情况下,将 gridsplitters 放入包含面板的网格中可能会更简单,而无需开发任何其他控件您在状态栏中创建一个网格,将面板放入其中并将 GridSplitter 放入每个面板之间的网格列,拆分器可以移动以放大或缩小内部网格的列。

标签: c# wpf wpf-animation


【解决方案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>

这是带有状态栏和拆分器的窗口,诀窍是您必须将文本块列设置为“自动”,以便拆分器能够移动和更改大小我使用了一些难看的颜色来使内容可见。在后面的代码中没有任何内容,如果您想在拖动拆分器时执行某些操作,则可以处理 DragCompleted 事件。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多