2014-03-31 20 views
2

我有一個itemscontrol,其中我所有的元素是PopUps。問題是我不知道如何將它們放置在放置項目控件的網格中。我試過使用水平和垂直對齊方式,但這沒有幫助。我到目前爲止的xaml代碼是:放置PopUp,這是在一個ItemsControl

<Grid>  
<ItemsControl Grid.Row="1" VerticalContentAlignment="Top" HorizontalAlignment="Left" ItemsSource="{Binding PopUp}"> 
      <ItemsControl.ItemTemplate> 
       <DataTemplate> 
         <ViewModel:PopUpTemplateSelector.EndTurnMenuTemplate> 
          <DataTemplate> 
           <Popup IsOpen="{Binding PU.IsOpen}" HorizontalAlignment="Left" VerticalAlignment="Top"> 
            <Design:InGame_NextTurn_UserControl/> 
           </Popup> 
          </DataTemplate> 
         </ViewModel:PopUpTemplateSelector.EndTurnMenuTemplate> 
        </ViewModel:PopUpTemplateSelector> 
       </DataTemplate> 
      </ItemsControl.ItemTemplate> 
     </ItemsControl> 
</Grid> 
+1

對不起的人,有麻煩形象化什麼「怎麼o將它們放置在與放置項目控件的網格相比「應該看起來像。想要提供某種你想要的快速和骯髒的圖像,比你得到什麼? –

+0

@ JonasN89,我的答案是否解決了你的問題:) – JTIM

回答

1

我建議也許使用下面的覆蓋方法代替。

From this Nokia page

覆蓋XMAL:

<UserControl x:Class="WindowsPhoneSample7.OverLay" 
    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" 
    FontFamily="{StaticResource PhoneFontFamilyNormal}" 
    FontSize="{StaticResource PhoneFontSizeNormal}" 
    d:DesignHeight="800" d:DesignWidth="480"> 

    <Grid x:Name="LayoutRoot" Background="Transparent"> 
     <Grid.RowDefinitions> 
      <RowDefinition Height="400"/> 
      <RowDefinition Height="400"/> 
     </Grid.RowDefinitions> 
     <StackPanel Grid.Row="1"> 
      <ProgressBar IsIndeterminate="True" Foreground="Orange" Height="50" Width="480" VerticalAlignment="Center"/> 
      <TextBlock Text="Wait" Foreground="Orange" HorizontalAlignment="Center"/> 
     </StackPanel> 
    </Grid> 
</UserControl> 

覆蓋後臺代碼:

public OverLay() 
{ 
    InitializeComponent(); 
    this.LayoutRoot.Height = Application.Current.Host.Content.ActualHeight; 
    this.LayoutRoot.Width = Application.Current.Host.Content.ActualWidth; 
    SystemTray.IsVisible = false; //to hide system tray 
} 

的MainPage代碼隱藏:

public partial class MainPage : PhoneApplicationPage 
{ 
    private Popup popup; 
    // Constructor 
    public MainPage() 
    { 
     InitializeComponent(); 
     this.popup = new Popup(); 
    } 

    private void BtnStart_Click(object sender, RoutedEventArgs e) 
    { 
     this.LayoutRoot.Opacity = 0.2; 
     OverLay ovr = new OverLay(); 
     this.popup.Child = ovr; 
     this.popup.IsOpen = true; 
     BackgroundWorker worker = new BackgroundWorker(); 
     worker.DoWork += (s, a) => 
     { 
      Thread.Sleep(5000); 
     }; 
     worker.RunWorkerCompleted += (s, a) => 
     { 
      popup.IsOpen = false; 
      this.LayoutRoot.Opacity = 1.0; 
     }; 
     worker.RunWorkerAsync(); 
    } 

    protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e) 
    { 
     this.popup.IsOpen = false; 
    } 
} 
+1

從技術上講,這個答案是一個「僅鏈接答案」...並且鏈接被破壞。找到一個存檔鏈接,並拉入相關的代碼片段。只是想確保你意識到這總是存在鏈接唯一答案的風險,這就是爲什麼他們不鼓勵在這裏。 – Anthony

相關問題