2015-09-21 120 views
0

我有一個狀態欄,裏面有三個標籤。有時候標籤需要很多文字才能放在屏幕上。我希望能夠拖動和滑動每個標籤中的文字,以使不適合在屏幕上顯示的文字顯示出來。滑動面板WPF

有沒有一種方法可以在標籤中做到這一點?或者我應該爲此創建一些類型的自定義滑動面板?

如果我將不得不創建一個自定義面板,可以向我提供有關如何動畫文本滑動的一些指示?

+3

將文本置於工具提示中,以便在有人將鼠標懸停在工具提示上時顯示該文本。這是標準的用戶界面。 – Will

+0

@嗨你好,我早些時候問過類似的問題,我相信你也是在那裏回答的!我實現了標準格式,但我想盡量減少應用程序中的工具提示,所以我試圖製作滑動面板。不過謝謝。 – user3204416

+0

滑動面板的問題是滾動查看器是爲您提供滾動條的控件,需要空間,因此您應該找到一種方法來創建模板以使滾動條非常小,或者您需要使用文本控件創建自定義控件,並且2個按鈕用於在文字過大時移動文本,但看起來不是很容易創建。 –

回答

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事件。