2017-06-19 73 views
0

我有一个向左和向右扩展的窗口。将窗口向左和向右扩展,但将主要内容保留在相同位置

简单的例子:

<Window x:Class="Application1.Windows.Test" 
    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" 
    mc:Ignorable="d" 
    Title="MainWindow" 
    SizeToContent="Width" Height="250"> 
    <Grid> 
     <Grid.ColumnDefinitions> 
      <ColumnDefinition Width="Auto" />    <!--Expander LEFT--> 
      <ColumnDefinition Width="25"/> 
      <ColumnDefinition Width="175" />    <!--Red Content --> 
      <ColumnDefinition Width="25"/> 
      <ColumnDefinition Width="Auto"/>    <!--Expander RIGHT--> 
     </Grid.ColumnDefinitions> 
     <Grid.RowDefinitions> 
      <RowDefinition Height="25"/> 
      <RowDefinition Height="*"/> 
      <RowDefinition Height="25"/> 
     </Grid.RowDefinitions>  
    <Expander Grid.Column="0" 
       Grid.Row="0" 
       Grid.RowSpan="3" 
       Margin="5" 
       ExpandDirection="Left"> 
     <Grid Width="200">     
     </Grid> 
    </Expander> 
    <Grid Grid.Column="2"     
      Grid.RowSpan="3" 
      Background="Red"/> 
     <Expander Grid.Column="4" 
        Grid.Row="0" 
        Grid.RowSpan="3" 
        Margin="5" 
        ExpandDirection="Right"> 
     <Grid Width="200"> 
     </Grid> 
    </Expander> 
    </Grid> 

在这里你可以看到的问题是什么:

enter image description here

我已经对WPF - Expand Window to the Left看看。

解决方案的作品,但只解决了一半的问题。

如何做左和右?

UPDATE

  • 我不希望扩展列加以固定。他们应该只显示所需要的扩展

回答

0

一种方法,将工作的最小空间是这样的:

(但我用这个解决方案在某种程度上不满意)

创建Enum存储最后行动:

public enum ExpandActions 
{ 
    ExpandRight, 
    ExpandLeft, 
    CollapsRight, 
    CollapseLeft 
} 

然后,我添加了处理程序Expand & CollapseExpanders xaml。

最后覆盖SizeChanged在窗口上,如WPF - Expand Window to the Left

我们只想要这种行为,当向左扩展 - 否则我们会杀死我们的'扩展到正确'的行为。

protected override void OnRenderSizeChanged(SizeChangedInfo sizeInfo) 
{ 
    if (!sizeInfo.WidthChanged) 
    { 
     base.OnRenderSizeChanged(sizeInfo); 
     return; 
    } 

    Hide(); 
    base.OnRenderSizeChanged(sizeInfo); 

    //Last action was on left expander 
    if(_lastAction == ExpandActions.CollapseLeft || _lastAction == ExpandActions.ExpandLeft) 
    { 
     Left -= (sizeInfo.NewSize.Width - sizeInfo.PreviousSize.Width); 
    }      
    Show(); 
} 

关于这点的好处是可以处理屏幕外扩展。

它的工作原理,但我想这不是最好的解决方案。

结果是这样的:

enter image description here

+0

它看起来相当整洁我,应该是一个很好的解决方案。 PS,我喜欢你展示你的问题的动画:P –

相关问题