如何在ContentDialog中使用ListView

0 c# windows-runtime windows-phone-8.1

我试图通过"HardCode"使用ContentDialog不在XAML页面中,我有很多TextBlocks要使用,所以我可能需要在ContentDialog中使用ScrollView或ListView,这是我的代码!

TextBlock txt = new TextBlock();
            txt.Text = "TI Cajueiro Seco / Rua do Sol";
            txt.FontSize = 25;
            txt.Foreground = new SolidColorBrush(Colors.White);
            txt.HorizontalAlignment = Windows.UI.Xaml.HorizontalAlignment.Center;
            txt.VerticalAlignment = VerticalAlignment.Top;
            txt.FontFamily = new FontFamily("/Fonts/MYRIADPRO-BOLD.OTF#Myriad Pro");

TextBlock txt2 = new TextBlock();
            txt2.Text = "Rotas da Linha";
            txt2.FontSize = 25;
            txt2.Foreground = new SolidColorBrush(Colors.White);
            txt2.HorizontalAlignment = Windows.UI.Xaml.HorizontalAlignment.Left;
            txt2.VerticalAlignment = VerticalAlignment.Bottom;
            txt2.FontFamily = new FontFamily("/Fonts/Exo-Regular.ttf#Exo");

Grid grid = new Grid();
            grid.Children.Add(txt2);
            grid.Background = new SolidColorBrush(Colors.Red); 

StackPanel stk = new StackPanel();
            //stk.Children.Add(bar);
            stk.Children.Add(txt);
            stk.Children.Add(espaco);
            stk.Children.Add(grid);
            //stk.Children.Add(txt3);
            stk.VerticalAlignment = Windows.UI.Xaml.VerticalAlignment.Top;

Grid contentGrid = new Grid();
            contentGrid.Height = Window.Current.Bounds.Height;
            contentGrid.Width = Window.Current.Bounds.Width;  
            contentGrid.Width -= 40;
            contentGrid.Children.Add(stk);

ContentDialog dlg = new ContentDialog();
              dlg.Content = contentGrid;
              SolidColorBrush color = new SolidColorBrush(Colors.Black);
              color.Opacity = 0.9;
              dlg.Background = color;
              dlg.ShowAsync();
Run Code Online (Sandbox Code Playgroud)

Blu*_*TOM 5

有人来到这里寻找在Windows 10 Universal项目中的ContentDialog中拥有Scrollable ListView的方法,请参阅此处.基本上需要对ContentDialog模板进行一些修改.您可以从该答案中粘贴修改后的版本,然后将该模板应用于ContentDialog.