How to add multiple controls inside a Frame in Silverlight - c#

I am new to silverlight. I have to add multiple controls in a Navigation Frame. When i do like this ,i am getting error.
<Navigation:Frame Name="ContentFrame" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="0,55,12,12" BorderThickness="1" BorderBrush="Black" Grid.Column="1" Grid.ColumnSpan="3" Grid.RowSpan="5">
<TextBlock Grid.Column="1" Height="23" HorizontalAlignment="Left" Margin="9,129,0,0" Name="textBlock2" Text="UserName:" VerticalAlignment="Top" />
<TextBlock Grid.Column="1" Height="23" HorizontalAlignment="Left" Margin="12,22,0,0" Name="textBlock3" Text="Password:" VerticalAlignment="Top" Grid.Row="1" />
</Navigation:Frame>
The Error is The property 'Content' cannot be set more than once. Where i am wrong. How to achieve this?

Frame is a ContentControl which means that it can only have a single child. You need to add a child control that is able to hold multiple children. Try a Grid for example:
<Navigation:Frame >
<Grid>
<TextBlock Grid.Column="1" Height="23" HorizontalAlignment="Left" Margin="9,129,0,0" Name="textBlock2" Text="UserName:" VerticalAlignment="Top" />
<TextBlock Grid.Column="1" Height="23" HorizontalAlignment="Left" Margin="12,22,0,0" Name="textBlock3" Text="Password:" VerticalAlignment="Top" Grid.Row="1" />
</Grid>
</Navigation:Frame>

Related

TextBlock when run not displaying entire text

I am building a wpf application, where my text block text is fading out when the application is run.
Code is
<Grid>
<TextBlock Text="RSP Level" Width="78" Height="Auto" HorizontalAlignment="Left" Margin="54.2,3,0,398.6" Grid.Column="3"/>
<TextBlock Text="Hex" Width="60" Height="Auto" HorizontalAlignment="Left" Grid.Column="3" Margin="157.2,36,0,367.6" RenderTransformOrigin="0.993,0.976" Grid.ColumnSpan="2"/>
<TextBlock Text="Hex" Width="29" Height="20" TextWrapping="Wrap" HorizontalAlignment="Left" Grid.Column="3" Margin="31.2,35,0,368.6" RenderTransformOrigin="1.91,0.08" />
<TextBlock Text="Link" Width="29" Height="20" HorizontalAlignment="Left" Grid.Column="3" Margin="31.2,59,0,344.6" RenderTransformOrigin="0.993,0.976"/>
<TextBlock Text="Application" Width="61" Height="20" HorizontalAlignment="Left" Grid.Column="3" Margin="32.2,83,0,320.6" RenderTransformOrigin="0.993,0.976"/>
<TextBlock Text="Physical" Width="66" Height="Auto" HorizontalAlignment="Left" Grid.Column="3" Margin="158.2,61,0,342.6" RenderTransformOrigin="0.993,0.976" Grid.ColumnSpan="2"/>
<TextBlock Text="Link" Width="35" Height="Auto" HorizontalAlignment="Left" Grid.Column="3" Margin="158.2,85,0,318.6" RenderTransformOrigin="0.993,0.976"/>
<TextBlock Text="Application" Width="69" Height="Auto" HorizontalAlignment="Left" Grid.Column="3" Margin="157.2,108,0,295.6" RenderTransformOrigin="0.993,0.976" Grid.ColumnSpan="2"/>
</Grid>
This is not the right way to align contents. You can use StackPanel to place child elements below or beside each other. If you use Grid, define Rows and Columns. Using margins is not a proper way. Read more WPF about layouts here.

Unable to scroll in WPF textblocks using ScrollViewer

I have 2 textblocks on my form. I need to have vertical scrollbars in each of them. Due to some reason, I am not able to get the scrollbars on both. Kindly provide me with some idea.
<Grid>
<Button Content="COMPARE" HorizontalAlignment="Left" Margin="216,30,0,0" VerticalAlignment="Top" Width="75" Click="Button_Click"/>
<TextBox x:Name="TextBox1" ScrollViewer.HorizontalScrollBarVisibility="Visible" ScrollViewer.VerticalScrollBarVisibility="Auto" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="10,69,0,0" TextWrapping="Wrap" RenderTransformOrigin="-1.351,-2.164" Height="242" Width="226" Loaded="TextBox1_Loaded" />
<ScrollViewer>
<TextBlock x:Name="TextBlock1" HorizontalAlignment="Left" Margin="10,69,0,0" TextWrapping="Wrap" VerticalAlignment="Top" RenderTransformOrigin="-1.351,-2.164" Height="242" Width="226" Loaded="TextBlock1_Loaded" />
</ScrollViewer>
<TextBox x:Name="TextBox2" ScrollViewer.HorizontalScrollBarVisibility="Visible" ScrollViewer.VerticalScrollBarVisibility="Auto" HorizontalAlignment="Left" Margin="258,69,0,0" TextWrapping="Wrap" VerticalAlignment="Top" RenderTransformOrigin="-1.351,-2.164" Height="242" Width="226" Loaded="TextBox2_Loaded"/>
<ScrollViewer>
<TextBlock x:Name="TextBlock2" HorizontalAlignment="Left" Margin="258,69,0,0" TextWrapping="Wrap" VerticalAlignment="Top" RenderTransformOrigin="-1.351,-2.164" Height="242" Width="226" Loaded="TextBlock2_Loaded_1"/>
</ScrollViewer>
<Button Content="EDIT" HorizontalAlignment="Left" Margin="409,30,0,0" VerticalAlignment="Top" Width="75" Click="Button_Click_1"/>
<Button Content="HOME" HorizontalAlignment="Left" Margin="21,26,0,0" VerticalAlignment="Top" Width="75" RenderTransformOrigin="0.23,0.986" Click="Button_Click_2"/>
</Grid>
Try to check this out:
1. XAML Code:
<ScrollViewer Grid.Column="0" Grid.Row="0">
<TextBlock x:Name="ATextBlock" ></TextBlock></ScrollViewer>
<ScrollViewer Grid.Row="0" Grid.Column="1" >
<TextBlock x:Name="BtTextBlock" ></TextBlock></ScrollViewer>
the problem was; the Height definition on the TextBlock. Just remove it and that is.
regards.,
To show vertical scroll bar on a TextBox when needed you can use this XAML
<TextBox .... VerticalScrollBarVisibility="Auto" />
ScrollBar will apear when text does not fit the original space given to controll.

Prevent buttons from blinking in WPF

I've created a WPF application. This has to have a red colored theme. So I set every color to a type of red, but the problem is all the buttons within the window start blinking when the window opens. The funny thing is they start all simultaneously but after a while they begin to diverge. When the form loses focus they all stop blinking. When a button is clicked, only that one keeps blinking. But when a "not button" control gains focus they all start blinking again.
I found that it could have to do something with the Focusable property, but changing it doesn't change anything. I also found a way to overwrite the default style but that doesn't solve the problem ether. Source
This is my XAML code:
<Grid x:Name="gServerSettings">
<Label x:Name="lTitle" Content="Server Settings" HorizontalAlignment="Center" Margin="182,0,0,166" VerticalAlignment="Center" Width="118" Foreground="#FFFF9999" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" FontSize="16" FontWeight="Bold" Height="34"/>
<TextBox x:Name="tServer" Margin="72,39,10,0" TextWrapping="Wrap" Background="{x:Null}" Foreground="#FFFF9999" BorderBrush="#FFFF9999" SelectionBrush="#FFFF9999" BorderThickness="1" VerticalContentAlignment="Center" Height="24" VerticalAlignment="Top" TabIndex="0"/>
<Label x:Name="lServer" Content="Server" HorizontalAlignment="Left" Margin="10,39,0,0" VerticalAlignment="Top" Width="62" Foreground="#FFFF9999" Height="24" VerticalContentAlignment="Center"/>
<TextBox x:Name="tDatabase" Margin="72,68,10,0" TextWrapping="Wrap" Background="{x:Null}" Foreground="#FFFF9999" BorderBrush="#FFFF9999" SelectionBrush="#FFFF9999" BorderThickness="1" VerticalContentAlignment="Center" Height="24" VerticalAlignment="Top" TabIndex="1"/>
<Label x:Name="lDatabase" Content="Database" HorizontalAlignment="Left" Margin="10,68,0,0" VerticalAlignment="Top" Width="62" Foreground="#FFFF9999" VerticalContentAlignment="Center" Height="24"/>
<TextBox x:Name="tUsername" Margin="72,97,10,0" TextWrapping="Wrap" Background="{x:Null}" Foreground="#FFFF9999" BorderBrush="#FFFF9999" SelectionBrush="#FFFF9999" BorderThickness="1" VerticalContentAlignment="Center" Height="24" VerticalAlignment="Top" TabIndex="2"/>
<Label x:Name="lUsername" Content="Username" HorizontalAlignment="Left" Margin="10,97,0,0" VerticalAlignment="Top" Width="62" Foreground="#FFFF9999" VerticalContentAlignment="Center" Height="24"/>
<Label x:Name="lPassword" Content="Password" HorizontalAlignment="Left" Margin="10,126,0,0" VerticalAlignment="Top" Width="62" Foreground="#FFFF9999" VerticalContentAlignment="Center" Height="24"/>
<PasswordBox x:Name="tPassword" Margin="72,126,10,0" Background="{x:Null}" Foreground="#FFFF9999" BorderBrush="#FFFF9999" SelectionBrush="#FFFF9999" BorderThickness="1" VerticalContentAlignment="Center" Height="24" VerticalAlignment="Top" TabIndex="3"/>
<Button x:Name="bOK" Content="OK" HorizontalAlignment="Left" Margin="215,168,0,0" VerticalAlignment="Top" Width="75" Background="{x:Null}" BorderBrush="{x:Null}" Foreground="#FFFF9999" BorderThickness="1" IsDefault="True" TabIndex="6"/>
<Button x:Name="bCancel" Content="Cancel" HorizontalAlignment="Left" Margin="135,168,0,0" VerticalAlignment="Top" Width="75" Background="{x:Null}" BorderBrush="{x:Null}" Foreground="#FFFF9999" BorderThickness="1" IsDefault="True" TabIndex="5"/>
<Button x:Name="bTestConnection" Content="Test Connection" HorizontalAlignment="Left" Margin="10,168,0,0" VerticalAlignment="Top" Width="120" Background="{x:Null}" BorderBrush="{x:Null}" Foreground="#FFFF9999" BorderThickness="1" IsDefault="True" TabIndex="4" IsHitTestVisible="False"/>
</Grid>
I don't do anything programmatically yet, so my .CS file is empty.
Does anybody know how to solve this problem?
You'd have to basically reimplement the button style and remove that storyboard. You can dump out the default button style with Expression Blend and modify it to your liking. There isn't really any other easy way to disable that storyboard.

Windows Phone SDK - XAML - automatic margin for the top margin

I have the following XAML in my Windows Phone app:
<StackPanel Orientation="Horizontal">
<Grid x:Name="LayoutRoot">
<Image Source="{Binding ImageUrl}" Height="80" HorizontalAlignment="Left" Margin="10,10,0,0" Stretch="Fill" VerticalAlignment="Top" Width="93" />
<TextBlock name="NameBlock" Text="{Binding Name}" FontSize="30" Margin="150,20,0,0" TextWrapping="Wrap" HorizontalAlignment="Left" VerticalAlignment="Top" Width="300" />
<TextBlock name="DescriptionBlock" Text="{Binding Description}" FontSize="25" Margin="150,150,0,0" TextWrapping="Wrap" HorizontalAlignment="Left" VerticalAlignment="Top" Width="300" />
</Grid>
</StackPanel>
Currently, I have the margin of the second TextBlock (DescriptionBlock) set to a static value. Now because I have the work wrapping of the first TextBlock (NameBlock) set to "Wrap", the height of the TextBlock is variable.
Does anyone know how to make the top-margin of DescriptionBlock equal to the automatic height of NameBlock? This would ensure that the second DescriptionBlock appears directly below the NameBlock, regardless of the length of the text of NameBlock.
Many thanks!
Brett
This is what panels are for. Wrap the two text blocks in stack panel and it will stack the text blocks one above the other.
<Grid x:Name="LayoutRoot">
<Image Source="{Binding ImageUrl}" Height="80" HorizontalAlignment="Left" Margin="10,10,0,0" Stretch="Fill" VerticalAlignment="Top" Width="93" />
<StackPanel Margin="150,20,0,0" Width="300">
<TextBlock name="NameBlock" Text="{Binding Name}" FontSize="30" TextWrapping="Wrap" HorizontalAlignment="Left" />
<TextBlock name="DescriptionBlock" Text="{Binding Description}" FontSize="25" TextWrapping="Wrap" HorizontalAlignment="Left" />
</StackPanel>
</Grid>
A panel that holds a single child is usually useless, so I removed the stack panel around the grid.
If you'd like to continue using Grid you can define rows for it to size automatically.

Vertical scroll in Pivot Page

It's a very stupid question :)
Which property sets vertical scroll?
Developing Windows Phone 7 app, I switched off this property, and I don't understand, how I did it :)
I use ComboBox, and when I create project, I can scroll text in ComboBox, but now I can't
You need to include all the items inside the Scrollviewer, as in pivot page, we can't make the content scroller without scroll viewer.
Here is the sample content.
<ScrollViewer HorizontalAlignment="Left" VerticalAlignment="Top" Height="647" Margin="0" Grid.Row="1">
<Grid x:Name="ContentPanel" Margin="0,0,0,24" Width="480" Height="1470" Grid.Row="1">
<Image x:Name="ImgProcess" Source="/GoogTaxi;component/images/loading2.jpg" Visibility="Collapsed" Stretch="None" Opacity="0.60" VerticalAlignment="Top" />
<TextBlock x:Name="tbkCompanyName" TextWrapping="Wrap" Text="Company Name" Margin="20,20,0,0" VerticalAlignment="Top"/>
<TextBox x:Name="txtCompanyName" TextWrapping="Wrap" VerticalAlignment="Top" Margin="8,47,8,0"/>
<TextBlock x:Name="tbkAddress" TextWrapping="Wrap" Text="Address" Margin="20,120,0,0" VerticalAlignment="Top"/>
<TextBox x:Name="txtAddress" AcceptsReturn="True" TextWrapping="Wrap" VerticalAlignment="Top" Margin="8,147,8,336" VerticalScrollBarVisibility="Auto" Height="131"/>
<TextBlock x:Name="tbkEmailId" TextWrapping="Wrap" Text="Email Id" Margin="20,279,0,0" VerticalAlignment="Top"/>
<TextBox x:Name="txtEmailId" IsEnabled="False" TextWrapping="Wrap" VerticalAlignment="Top" Margin="8,306,8,0" d:LayoutOverrides="VerticalAlignment"/>
<TextBlock x:Name="tbkWebsite" TextWrapping="Wrap" Margin="20,379,0,0" VerticalAlignment="Top"><Run Text="Website"/><LineBreak/><Run/></TextBlock>
<TextBox x:Name="txtWebsite" TextWrapping="Wrap" VerticalAlignment="Top" Margin="8,406,8,0" d:LayoutOverrides="VerticalAlignment"/>
<TextBlock x:Name="tbkPhone" TextWrapping="Wrap" Text="Phone" Margin="20,479,0,0" VerticalAlignment="Top" d:LayoutOverrides="VerticalAlignment"/>
<TextBox x:Name="txtPhone" TextWrapping="Wrap" VerticalAlignment="Top" Margin="8,506,8,0"/>
<TextBlock x:Name="tbkCity" TextWrapping="Wrap" Margin="20,579,0,0" VerticalAlignment="Top" Text="City"/>
<TextBox x:Name="txtCity" TextWrapping="Wrap" VerticalAlignment="Top" Margin="8,606,8,0"/>
<TextBlock x:Name="tbkState" TextWrapping="Wrap" Text="State" Margin="20,676,0,0" VerticalAlignment="Top"/>
<TextBox x:Name="txtState" TextWrapping="Wrap" VerticalAlignment="Top" Margin="8,704,8,0"/>
<TextBlock x:Name="tblCountry" TextWrapping="Wrap" Text="Country" Margin="20,780,0,0" VerticalAlignment="Top"/>
<TextBox x:Name="txtCountry" TextWrapping="Wrap" VerticalAlignment="Top" Margin="8,806,8,0"/>
<TextBlock x:Name="tbkCompany_logo" Visibility="Collapsed" TextWrapping="Wrap" Text="Contact Person" Margin="20,0,0,42.602" VerticalAlignment="Top" d:IsHidden="True"/>
<TextBox x:Name="txtCompany_logo" Visibility="Collapsed" TextWrapping="Wrap" Margin="8,0,8,-29.305" VerticalAlignment="Top" d:IsHidden="True"/>
<TextBlock x:Name="tbkContactPerson" TextWrapping="Wrap" Text="Contact Person" Margin="20,879,0,0" VerticalAlignment="Top"/>
<TextBox x:Name="txtContactPerson" TextWrapping="Wrap" Margin="8,908,8,0" VerticalAlignment="Top"/>
<TextBlock x:Name="tbkContactPhone" TextWrapping="Wrap" Text="Contact Person Phone" Margin="20,982,0,0" VerticalAlignment="Top"/>
<TextBox x:Name="txtContactPhone" TextWrapping="Wrap" VerticalAlignment="Top" Margin="8,1005,8,0"/>
<TextBlock x:Name="tbkContactEmail" TextWrapping="Wrap" Text="Contact person Email ID" Margin="20,1079,0,0" VerticalAlignment="Top"/>
<TextBox x:Name="txtContactEmail" TextWrapping="Wrap" VerticalAlignment="Top" Margin="8,1106,8,0"/>
<TextBlock x:Name="tbkMerchantId" TextWrapping="Wrap" Text="Google Merchant Id" Margin="20,1180,0,0" VerticalAlignment="Top"/>
<TextBox x:Name="txtMerchantId" TextWrapping="Wrap" VerticalAlignment="Top" Margin="8,1209,8,0" IsEnabled="False" />
<TextBlock x:Name="tbkMerchantKey" TextWrapping="Wrap" Text="Google Merchant Key" Margin="20,1282,0,0" VerticalAlignment="Top"/>
<TextBox x:Name="txtMerchantKey" TextWrapping="Wrap" VerticalAlignment="Top" Margin="8,1310,8,0" IsEnabled="False" />
<Button x:Name="btnsave" Content="Save" Margin="33,1390,0,0" VerticalAlignment="Top" HorizontalAlignment="Left" Click="btnsave_Click" />
<Button x:Name="btnCancel" Content="Cancel" Margin="0,1390,33,0" VerticalAlignment="Top" HorizontalAlignment="Right" d:LayoutOverrides="HorizontalAlignment" Click="btnCancel_Click" />
</Grid>
</ScrollViewer>
There is no scroll functionality inside PivotItem. You should use ScrollViewer control to get it by your own.
In a pivot control, if the content is overflowing the vertical page then there should be default "vertical" scrolling available to you.
I had a similar control with "list box" bounded to property. Having the list box should automatically allow you to scroll.
Don't add a scrollviewer over the stack panel as it would make the scrolling enabled for each list item which you don't want.
<controls:PivotItem Header="all authors" Foreground="#FF0C388A">
<Grid>
<ListBox Margin="0,0,-12,0" ItemsSource="{Binding AllAuthorsList}" Foreground="#FF0C388A">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Margin="0,0,0,17" Width="432" Height="Auto">
<TextBlock Tap="TextBlockAuthor_Tap" Text="{Binding}" TextWrapping="Wrap" Style="{StaticResource PhoneTextExtraLargeStyle}" Foreground="#FF0C388A"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
</controls:PivotItem>

Categories

Resources