Why my code don't work when it should? - windows-phone-7

problem is when i want to write something in textbox i can't focus on it.
thanks for cooperate:)
<!--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>-->

Try explicitly setting the property "IsEnabled" to true.
EDIT: I actually tried it and it doesn't look like it works. Strangely enough if you call Focus() on it from the code behind it works.
EDIT: Figured it out! You need to set proper "RowDefintions" on your Grid. Check out this code:
<!--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>

Related

How to implement <Grid> in Universal Windows Platform App?

How to use Gird in Windows Apps?
I want to create a Login form. I have used grid and used but the Rows are not aligned properly, How can I do that?
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="67*"/>
<ColumnDefinition Width="293*"/>
</Grid.ColumnDefinitions>
<StackPanel>
<TextBlock Text="Name" Height="32" Margin="0,0,0.333,0" ></TextBlock>
<TextBlock Text="Last Name" Height="30" Margin="0,0,0.333,0" ></TextBlock>
<TextBlock Text="Address"></TextBlock>
</StackPanel>
<StackPanel Grid.Column="1">
<TextBox></TextBox>
<TextBox></TextBox>
<TextBox></TextBox>
</StackPanel>
</Grid>
You should define the rows and columns in Grid.
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="67*"/>
<ColumnDefinition Width="293*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="45"></RowDefinition>
<RowDefinition Height="45"></RowDefinition>
<RowDefinition Height="45"></RowDefinition>
</Grid.RowDefinitions>
<TextBlock Text="Name" Grid.Column="0" Grid.Row="0" VerticalAlignment="Center"></TextBlock>
<TextBlock Text="Last Name" Grid.Column="0" Grid.Row="1" VerticalAlignment="Center"></TextBlock>
<TextBlock Text="Address" Grid.Column="0" Grid.Row="2" VerticalAlignment="Center"></TextBlock>
<TextBox Grid.Column="1" Grid.Row="0" Height="30"></TextBox>
<TextBox Grid.Column="1" Grid.Row="1" Height="30"></TextBox>
<TextBox Grid.Column="1" Grid.Row="2" Height="30"></TextBox>
</Grid>

phone:WebBrowser how we can set Auto Height and Width?

<StackPanel Orientation="Vertical">
<TextBlock x:Name="articleDate" Foreground="Black" FontSize="20"
Text="Timefzdsaf" />
<Image x:Name="image" Stretch="Uniform" />
<StackPanel Orientation="Vertical">
<phone:WebBrowser Name="webBrowser1"
IsScriptEnabled="False" Background="White"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
VerticalContentAlignment="Center"
HorizontalContentAlignment="Center"
></phone:WebBrowser>
</StackPanel>
phone:WebBrowser will not show in my page(if am not giving Height and Width i want it should take automatically). can any one help me to show html in phone WebBrowser?
Don't use the StackPanel. Try Grid with RowDefinitions. For WebBrowser set it to "*"
From your code (added Source just to demonstrate):
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<TextBlock x:Name="articleDate"
Foreground="Black"
FontSize="20"
Text="Timefzdsaf" />
<Image x:Name="image"
Grid.Row="1"
Stretch="Uniform" />
<phone:WebBrowser Name="webBrowser1"
Source="http://msdn.microsoft.com/en-US/"
IsScriptEnabled="False"
Grid.Row="2"
Background="White"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
VerticalContentAlignment="Center"
HorizontalContentAlignment="Center">
</phone:WebBrowser>
</Grid>

Windows Phone : Text in textblock not showing fully

Problem solved!
Anyway, I just figured out the problem. I did a .Trim() on the values and surprisingly they can be wrapped. Thanks and sorry for all the trouble. =)
I am doing some data binding to my textblock in a grid.
However, some of the texts are not showing fully.
I tried the Text Wrapping and setting a maximum width to my textblock. But none of them worked.
EDIT : Hi again. I noticed that when I changed the text of the textblock manually via codes like
txtDesc.Text = "This is a job for Stackers. If you like stacking, please contact me.
The text wrapping actually works. So somehow the databind result text can't be wrap?
The XAML code for my textblock.
<TextBlock Name="Description" Grid.Row="4" Text="{Binding Description}" FontSize=" {StaticResource PhoneFontSizeSmall}" Height="auto" Width="220" Margin="0,0,0,0" TextWrapping="Wrap" HorizontalAlignment="Left" VerticalAlignment="Top" MaxWidth="220"></TextBlock>
Any help here?
<!--LayoutRoot is the root grid where all page content is placed-->
<Grid x:Name="LayoutRoot">
<Grid.Background>
<ImageBrush Stretch="Fill" ImageSource="images/SmallLogoNTitle.png"/>
</Grid.Background>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition/>
</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" Style="{StaticResource PhoneTextNormalStyle}"/>
<TextBlock x:Name="PageTitle" 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">
<toolkit:ListPicker ItemsSource="{Binding}" Name="lpkTypeOfService" Margin="0,116,12,0" Height="65" VerticalAlignment="Top" HorizontalAlignment="Right" Width="210" SelectionChanged="lpkTypeOfService_SelectionChanged">
</toolkit:ListPicker>
<ListBox Margin="8,210,8,26" Name="listBox1" Width="450">
<ListBox.ItemTemplate>
<DataTemplate>
<Grid ShowGridLines="True">
<Grid.RowDefinitions>
<RowDefinition Height="50"/>
<RowDefinition Height="50"/>
<RowDefinition Height="30"/>
<RowDefinition Height="30"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="60"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="300"/>
<ColumnDefinition Width="150"/>
</Grid.ColumnDefinitions>
<TextBlock HorizontalAlignment="Left" Grid.Row="0" Grid.Column="0" Name="Date" Text="{Binding Date}" FontSize="{StaticResource PhoneFontSizeLarge}"></TextBlock>
<TextBlock HorizontalAlignment= "Left" Grid.Row="1" Grid.Column="0" Name="Creator" Text="{Binding CreatorID}" FontSize="{StaticResource PhoneFontSizeLarge}"></TextBlock>
<TextBlock Name="Type" Grid.Row="2" Text="{Binding Type}" FontSize="{StaticResource PhoneFontSizeSmall}"></TextBlock>
<TextBlock Name="Amount" Grid.Row="3" Text="{Binding Amount}" FontSize="{StaticResource PhoneFontSizeSmall}"></TextBlock>
<TextBlock Name="Description" Grid.Row="4" Text="{Binding Description}" FontSize="{StaticResource PhoneFontSizeSmall}" Height="auto" Width="220" Margin="0,0,0,0" TextWrapping="Wrap" HorizontalAlignment="Left" VerticalAlignment="Top" MaxWidth="220"></TextBlock>
<Button Content="Apply" Height="70" Width="140" Name="btn1" Click="btn_Click" Grid.Row="5" Grid.Column="1"></Button>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<TextBlock Height="65" HorizontalAlignment="Left" Margin="12,116,0,0" Name="textBlock1" Text="Find Service :" VerticalAlignment="Top" Width="216" FontSize="36" />
</Grid>
</Grid>
It comes from poor / over-complicated layout architecture and the way your objects are positioning each other. Might try something like this for your DataTemplate
<DataTemplate>
<Grid ShowGridLines="True">
<Grid.RowDefinitions>
<RowDefinition Height="50"/>
<RowDefinition Height="50"/>
<RowDefinition Height="30"/>
<RowDefinition Height="30"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="60"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<!-- Don't worry, you already had your 450 Width set on the parent -->
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<TextBlock Name="Date" Text="{Binding Date}" FontSize="{StaticResource PhoneFontSizeLarge}"/>
<TextBlock Name="Creator" Grid.Row="1" Text="{Binding CreatorID}" FontSize="{StaticResource PhoneFontSizeLarge}"/>
<TextBlock Name="Type" Grid.Row="2" Text="{Binding Type}" FontSize="{StaticResource PhoneFontSizeSmall}"/>
<TextBlock Name="Amount" Grid.Row="3" Text="{Binding Amount}" FontSize="{StaticResource PhoneFontSizeSmall}"/>
<TextBlock Name="Description" Grid.Row="4" Text="{Binding Description}" FontSize="{StaticResource PhoneFontSizeSmall}" TextWrapping="Wrap"/>
<Button Name="btn1" Click="btn_Click" Grid.Row="5" Grid.Column="1" Content="Apply" Height="70" Width="140" Margin="5,0"/>
</Grid>
</DataTemplate>
Also for the sake of cleaner xaml, remember things like Margin="0", Grid.Column="0", HorizontalAlignment="Left" etc. are default dependency properties, so no need to set them to each individual object. Even in the case you need to, you can apply them as Setters to the TargetType in the parent Object.Resources and avoid setting them to each individual object. Another tip would be, don't rely on a bunch of obfuscated random Margins etc to create your layout. It's best to do it right the first time instead of hunting down discrepancies between a bunch of inter-dependent little "fixes"
I didn't test it, but should work fine unless you got something else somewhere pushing stuff around. Hope this helps.
Can you disable horizontal scrolling in your listbox control?
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
Use VerticalAlignment="Stretch" instead of VerticalAlignment="Top". This way the textblock will stretch to the height of the row.

Bing map covered the Title Panel!Why?

I put a MapControl in a scrollviewer, but when I pulled up the MapControl, the MapControl covered the TitlePanel!Like this photo
How to fix this?Is it a system bug?Thx~~~
Here is My xaml code
<Grid x:Name="LayoutRoot" Background="Transparent">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<!--TitlePanel 包含應用程式的名稱和頁面標題-->
<StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
<TextBlock x:Name="ApplicationTitle" Text="我的應用程式" Style="{StaticResource PhoneTextNormalStyle}"/>
<TextBlock x:Name="PageTitle" Text="頁面名稱" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
</StackPanel>
<!--ContentPanel - 其他內容置於此-->
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<ScrollViewer>
<Grid Width="440" Height="258" VerticalAlignment="Top">
<msMap:Map x:Name="Map" CopyrightVisibility="Collapsed" LogoVisibility="Collapsed" ScaleVisibility="Collapsed" CredentialsProvider="Al1klJ_w8MPrZ0kntZyMogTJkXb79xyNKVC2XpJuwSPp0NmAbrIuAthSzs5xbomJ">
</msMap:Map>
</Grid>
</ScrollViewer>
</Grid>
</Grid>
there is definitely some problem in your grid margins. If you paste your xaml code. Maybe I will be help you out in a more better way
[Updated]
Try: This is working for me.
<Grid x:Name="LayoutRoot" Background="Transparent">
<Grid.RowDefinitions>
<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="page name" 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">
<ScrollViewer>
<Grid MaxHeight="400" VerticalAlignment="Top">
<my:Map HorizontalAlignment="Stretch" Name="map1" VerticalAlignment="Stretch" />
</Grid>
</ScrollViewer>
</Grid>
</Grid>

Grid inside scroll viewer not working

I have added a grid control (I have added about 20 rows, each row contains 2 columns and each of them having text blocks as a child, and I am setting RowHeight as Auto) on top of scroll viewer. It's scrolling but not showing the full content of the grid. What could be the reason?
The issue will be that the framework can't determine the overall height to allocate to the control. Try setting the explicit height of the scrollviewer and/or the grid (if you can).
Update
Please post your exact code. (Or, at least code which recreates the issue.)
The following code is my understanding of what you've described but does not create the behaviour you are experiencing
<Grid x:Name="LayoutRoot" Background="Transparent">
<controls:Pivot Title="MY APPLICATION">
<controls:PivotItem Header="first">
<ScrollViewer>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<TextBlock Style="{StaticResource PhoneTextHugeStyle}" Text="A1" Grid.Column="0" Grid.Row="0" />
<TextBlock Style="{StaticResource PhoneTextHugeStyle}" Text="A2" Grid.Column="1" Grid.Row="0" />
<TextBlock Style="{StaticResource PhoneTextHugeStyle}" Text="B1" Grid.Column="0" Grid.Row="1" />
<TextBlock Style="{StaticResource PhoneTextHugeStyle}" Text="B2" Grid.Column="1" Grid.Row="1" />
<TextBlock Style="{StaticResource PhoneTextHugeStyle}" Text="C1" Grid.Column="0" Grid.Row="2" />
<TextBlock Style="{StaticResource PhoneTextHugeStyle}" Text="C2" Grid.Column="1" Grid.Row="2" />
<TextBlock Style="{StaticResource PhoneTextHugeStyle}" Text="D1" Grid.Column="0" Grid.Row="3" />
<TextBlock Style="{StaticResource PhoneTextHugeStyle}" Text="D2" Grid.Column="1" Grid.Row="3" />
<TextBlock Style="{StaticResource PhoneTextHugeStyle}" Text="E1" Grid.Column="0" Grid.Row="4" />
<TextBlock Style="{StaticResource PhoneTextHugeStyle}" Text="E2" Grid.Column="1" Grid.Row="4" />
<TextBlock Style="{StaticResource PhoneTextHugeStyle}" Text="F1" Grid.Column="0" Grid.Row="5" />
<TextBlock Style="{StaticResource PhoneTextHugeStyle}" Text="F2" Grid.Column="1" Grid.Row="5" />
<TextBlock Style="{StaticResource PhoneTextHugeStyle}" Text="G1" Grid.Column="0" Grid.Row="6" />
<TextBlock Style="{StaticResource PhoneTextHugeStyle}" Text="G2" Grid.Column="1" Grid.Row="6" />
<TextBlock Style="{StaticResource PhoneTextHugeStyle}" Text="H1" Grid.Column="0" Grid.Row="7" />
<TextBlock Style="{StaticResource PhoneTextHugeStyle}" Text="H2" Grid.Column="1" Grid.Row="7" />
<TextBlock Style="{StaticResource PhoneTextHugeStyle}" Text="I1" Grid.Column="0" Grid.Row="8" />
<TextBlock Style="{StaticResource PhoneTextHugeStyle}" Text="I2" Grid.Column="1" Grid.Row="8" />
<TextBlock Style="{StaticResource PhoneTextHugeStyle}" Text="J1" Grid.Column="0" Grid.Row="9" />
<TextBlock Style="{StaticResource PhoneTextHugeStyle}" Text="J2" Grid.Column="1" Grid.Row="9" />
</Grid>
</ScrollViewer>
</controls:PivotItem>
</controls:Pivot>
</Grid>

Resources