locked
Is this a Windows Store XAML Bug??

    Question

  • Tried this on a couple Windows 8.1 Pro systems patched with the latest updates, it's a Windows 8.1 store app.

    There appears to be a windows store XAML bug.  In trying to isolate this problem I have reduced things to the following.

    Here is my "Simple" apps MainPage:

    <Page x:Class="Simple.MainPage"
          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:local="using:Simple"
          xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
          mc:Ignorable="d">
     
        <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
            <StackPanel Margin="0,160,0,0"
                        HorizontalAlignment="Center"
                        Orientation="Horizontal">
                <Rectangle Width="0" Height="0" />
                <Button x:Name="FileOpen"
                        Margin="2"
                        Click="OnFileOpen"
                        Content="Open File" />
            </StackPanel>
            <TextBlock x:Name="OutputMsg"
                       Margin="0,200,0,0"
                       HorizontalAlignment="Center"
                       FontSize="18" />
        </Grid>
    </Page>

    And here is the code behind:

    using System;
    using System.Collections.Generic;
    using System.IO;
    using System.Linq;
    using System.Runtime.InteropServices.WindowsRuntime;
    using Windows.Foundation;
    using Windows.Foundation.Collections;
    using Windows.Storage;
    using Windows.Storage.Pickers;
    using Windows.UI.Xaml;
    using Windows.UI.Xaml.Controls;
    using Windows.UI.Xaml.Controls.Primitives;
    using Windows.UI.Xaml.Data;
    using Windows.UI.Xaml.Input;
    using Windows.UI.Xaml.Media;
    using Windows.UI.Xaml.Navigation;
     
    namespace Simple
    {
        /// <summary>
        /// An empty page that can be used on its own or navigated to within a Frame.
        /// </summary>
        public sealed partial class MainPage : Page
        {
            StorageFile _inputFile = null;
     
            public MainPage()
            {
                this.InitializeComponent();
            }
     
            private async void OnFileOpen(object sender, RoutedEventArgs e)
            {
                FileOpenPicker fileOpenPicker = new FileOpenPicker()
                {
                    SuggestedStartLocation = PickerLocationId.MusicLibrary
                };
     
                fileOpenPicker.FileTypeFilter.Add("*");
     
                StorageFile file = await fileOpenPicker.PickSingleFileAsync();
     
                if (file != null)
                {
                    Windows.Storage.Streams.IRandomAccessStream stream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read);
     
                    _inputFile = file;
     
                    OutputText("Selected file format must be different from output.");
                }
            }
     
            async void OutputText(string text)
            {
                await Window.Current.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                {
                    OutputMsg.Text = text;
                });
            }
        }
    }
    

    The application is hung after selecting a file. If we move the button outside the StackPanel, or move the TextBlock into the StackPanel everything works as expected.  I am mystified by why the XAML below works and the above does not??

    <Page x:Class="Simple.MainPage"
          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:local="using:Simple"
          xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
          mc:Ignorable="d">
     
        <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
            <StackPanel Margin="0,160,0,0"
                        HorizontalAlignment="Center"
                        Orientation="Horizontal">
                <Rectangle Width="0" Height="0" />
                <Button x:Name="FileOpen"
                        Margin="2"
                        Click="OnFileOpen"
                        Content="Open File" />
                <TextBlock x:Name="OutputMsg"
                       Margin="0,200,0,0"
                       HorizontalAlignment="Center"
                       FontSize="18" />
            </StackPanel>
        </Grid>
    </Page>
    

    Looks like a bug, given all that was done is change the layout containers of some of the elements.  Anyone have any ideas?

    Sunday, February 22, 2015 2:34 PM

Answers

  • The application doesn't hang but the TextBlock ends up on top the Button when you set its Text property. That's why you cannot click on the Button.

    If you set the Text property of the TextBlock in the XAML markup you won't be able to click the Button when you run the app because of the same reason:

            <TextBlock x:Name="OutputMsg" Text="sample text"
                       Margin="0,200,0,0"
                       HorizontalAlignment="Center"
                       FontSize="18" />

    The solution is, like you have already discovered, to put the TextBlock in the StackPanel so it ends up below the Button and not on top of it in the same Grid.

    Please remember to mark helpful posts as answer to close your threads and then start a new thread if you have a new question.

    Sunday, February 22, 2015 2:45 PM

All replies

  • The application doesn't hang but the TextBlock ends up on top the Button when you set its Text property. That's why you cannot click on the Button.

    If you set the Text property of the TextBlock in the XAML markup you won't be able to click the Button when you run the app because of the same reason:

            <TextBlock x:Name="OutputMsg" Text="sample text"
                       Margin="0,200,0,0"
                       HorizontalAlignment="Center"
                       FontSize="18" />

    The solution is, like you have already discovered, to put the TextBlock in the StackPanel so it ends up below the Button and not on top of it in the same Grid.

    Please remember to mark helpful posts as answer to close your threads and then start a new thread if you have a new question.

    Sunday, February 22, 2015 2:45 PM
  • Doh!! I feel like a total idiot!  How stupid of me.

    I suppose this is what I really should have done given the layout I had:

            <TextBlock x:Name="OutputMsg"
                       Height="30"
                       Margin="0,240,0,0"
                       HorizontalAlignment="Center"
                       FontSize="18"
                       />

    I rarely use StackPanel unless I'm trying to test something quickly because of these sorts of issues.

    Thanks for the quick reply Magnus.

    Sunday, February 22, 2015 2:58 PM