2017-05-20 3 views
0

現在、私はWPFアプリケーションで作業しています.2つのパート(パート1 |パート2など)があります。パート1ではアイテムのリストがあり、アイテムIパート2でそのアイテムの詳細を取得します。ウィンドウページのサイズを小さくすると、その詳細がポップアップされます。どのように達成できますか?助けてください!WPFでページサイズが小さくなるとポップアップを作成

+0

これを実装しながら、あなたが経験している任意の特定の問題があります動作?コードが動作しない?それ以外の場合、この形式の質問はSOの要件を満たしません。 – Karolis

答えて

0

シンプルな、純粋なWPFのimplemenationは次のように仕事ができる:

ビュー:

<Window x:Class="WpfApplication2.MainWindow" 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     xmlns:local="clr-namespace:WpfApplication2" 
     Title="MainWindow" Height="350" Width="525"> 
    <Grid> 
     <Grid.ColumnDefinitions> 
      <ColumnDefinition/> 
      <ColumnDefinition Width="Auto"/> 
     </Grid.ColumnDefinitions> 
     <Grid x:Name="PartOne" Grid.Column="0" Background="Red"/> 
     <Grid x:Name="PartTwoContainer" Grid.Column="1"> 
      <!--PartTwoControl is just UserControl without any special logic in it--> 
      <local:PartTwoControl x:Name="PartTwo" /> 
     </Grid> 
    </Grid> 
</Window> 

そして、それのためにいくつかのロジック:

private const int MaxXToPopup = 300; 
private Window _popup; 

public MainWindow() 
{ 
    InitializeComponent(); 
} 

protected override void OnRenderSizeChanged(SizeChangedInfo sizeInfo) 
{ 
    if (ShouldDisplayInPopup()) 
    { 
     DetachPartTwo(); 
     OpenPopup(); 
    } 
    else if (ShouldDisplayInGrid()) 
    { 
     ClosePopup(); 
     ShowPartTwo(); 
    } 

    base.OnRenderSizeChanged(sizeInfo); 
} 

private void ClosePopup() 
{ 
    _popup.Content = null; 
    _popup.Close(); 
    _popup = null; 
} 

private void OpenPopup() 
{ 
    _popup = new Window {Content = PartTwo}; 
    _popup.Show(); 
} 

private void ShowPartTwo() 
{ 
    PartTwoContainer.Children.Add(PartTwo); 
} 

private void DetachPartTwo() 
{ 
    PartTwoContainer.Children.Remove(PartTwo); 
} 

private bool ShouldDisplayInGrid() 
{ 
    return _popup != null && RenderSize.Width > MaxXToPopup; 
} 

private bool ShouldDisplayInPopup() 
{ 
    return _popup == null && RenderSize.Width < MaxXToPopup; 
} 
関連する問題