Почему мой код не работает, когда он должен? - PullRequest
0 голосов
/ 01 апреля 2011

проблема в том, что когда я хочу что-то написать в текстовом поле, я не могу сосредоточиться на этом. спасибо за сотрудничество :)

<!--LayoutRoot is the root grid where all page content is placed-->
<Grid x:Name="LayoutRoot" Background="Transparent">
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="*"/>
    </Grid.RowDefinitions>
                <!--TitlePanel contains the name of the application and page title-->
        <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
            <TextBlock x:Name="ApplicationTitle" Text="MY APPLICATION" Style="{StaticResource PhoneTextNormalStyle}"/>
            <TextBlock x:Name="PageTitle" Text="Hello Phone" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
        </StackPanel>

        <!--ContentPanel - place additional content here-->
        <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="Auto"/>
            </Grid.ColumnDefinitions>
            <TextBox Grid.Column="0" Name="MessageTextBox" 
                 FontSize="{StaticResource PhoneFontSizeExtraLarge}" Margin="20,20,10,20" />
            <Button Grid.Column="1" Name="ClickMeButton" Content="Click Me" 
                HorizontalAlignment="Right" Padding="4" Margin="10,20,20,20" Click="ClickMeButton_Click" />
        <Grid Grid.Row="2">
            <TextBlock Name="BannerTextBlock" Style="{StaticResource PhoneTextExtraLargeStyle}" 
           Foreground="#FFFF7A00" HorizontalAlignment="Stretch"
           TextWrapping="Wrap" TextAlignment="Center" FontWeight="Bold" />
        </Grid>
    </Grid>
</Grid>

<!--Sample code showing usage of ApplicationBar-->
<!--<phone:PhoneApplicationPage.ApplicationBar>
    <shell:ApplicationBar IsVisible="True" IsMenuEnabled="True">
        <shell:ApplicationBarIconButton IconUri="/Images/appbar_button1.png" Text="Button 1"/>
        <shell:ApplicationBarIconButton IconUri="/Images/appbar_button2.png" Text="Button 2"/>
        <shell:ApplicationBar.MenuItems>
            <shell:ApplicationBarMenuItem Text="MenuItem 1"/>
            <shell:ApplicationBarMenuItem Text="MenuItem 2"/>
        </shell:ApplicationBar.MenuItems>
    </shell:ApplicationBar>
</phone:PhoneApplicationPage.ApplicationBar>-->

1 Ответ

2 голосов
/ 01 апреля 2011

Попробуйте явно установить для свойства "IsEnabled" значение true.

РЕДАКТИРОВАТЬ: Я на самом деле пробовал, и это не похоже, что это работает. Как ни странно, если вы вызываете Focus () на нем из кода, который работает за ним.

РЕДАКТИРОВАТЬ: Разобрался! Вы должны установить правильные «RowDefintions» на вашей сетке. Проверьте этот код:

<!--TitlePanel contains the name of the application and page title-->
<Grid x:Name="LayoutRoot" Background="Transparent">
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="*"/>
    </Grid.RowDefinitions>
    <!--TitlePanel contains the name of the application and page title-->
    <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
        <TextBlock x:Name="ApplicationTitle" Text="MY APPLICATION" Style="{StaticResource PhoneTextNormalStyle}"/>
        <TextBlock x:Name="PageTitle" Text="Hello Phone" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
    </StackPanel>
    <!--ContentPanel - place additional content here-->
    <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
        <Grid.RowDefinitions>
            <RowDefinition/>
            <RowDefinition/>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="Auto"/>
        </Grid.ColumnDefinitions>
        <TextBox Grid.Row="0" Grid.Column="0" Name="MessageTextBox" Margin="20,20,10,20" IsEnabled="True" />
        <Button Grid.Row="0" Grid.Column="1" Name="ClickMeButton" Content="Click Me" HorizontalAlignment="Right" Padding="4" Margin="10,20,20,20" Click="ClickMeButton_Click" IsEnabled="True" />
        <Grid Grid.Row="1">
            <TextBlock Name="BannerTextBlock" Style="{StaticResource PhoneTextExtraLargeStyle}"            Foreground="#FFFF7A00" HorizontalAlignment="Stretch"           TextWrapping="Wrap" TextAlignment="Center" FontWeight="Bold" />
        </Grid>
    </Grid>
</Grid>
...