How to make this code scroll'able?
I've tried this solution but it won't work: Need to scroll one WPF Grid
My XAML (Grid named Photos has to scroll):
<Grid Height="533" VerticalAlignment="Bottom">
<TextBox x:Name="siteAdressTextBox" HorizontalAlignment="Left" Height="23" Margin="10,10,0,0" TextWrapping="Wrap" Text="http://www.etrapez.pl/" VerticalAlignment="Top" Width="215"/>
<Button x:Name="sendWebRequestButton" Content="Wyślij zapytanie" HorizontalAlignment="Left" Margin="10,38,0,0" VerticalAlignment="Top" Width="107" Click="webRequest"/>
<Button Content="Pobierz wszystko" HorizontalAlignment="Left" Margin="122,38,0,0" VerticalAlignment="Top" Width="103" Click="downThemAll"/>
<ScrollViewer HorizontalAlignment="Left" Height="460" Margin="10,63,0,0" VerticalAlignment="Top" Width="1000" HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Visible" CanContentScroll="True">
<Grid x:Name="Photos" HorizontalAlignment="Left" Height="460" VerticalAlignment="Top" Width="1000" ShowGridLines="False" ScrollViewer.CanContentScroll="True" ScrollViewer.VerticalScrollBarVisibility="Visible" />
</ScrollViewer>
<TextBox Name="InfoBoxLabel" IsReadOnly="True" VerticalScrollBarVisibility="Auto" HorizontalAlignment="Left" Height="48" Margin="230,10,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="300"/>
</Grid>
try this
<Grid Height="533" VerticalAlignment="Bottom">
<TextBox x:Name="siteAdressTextBox" HorizontalAlignment="Left" Height="23" Margin="10,10,0,0" TextWrapping="Wrap" Text="http://www.etrapez.pl/" VerticalAlignment="Top" Width="215"/>
<Button x:Name="sendWebRequestButton" Content="Wyślij zapytanie" HorizontalAlignment="Left" Margin="10,38,0,0" VerticalAlignment="Top" Width="107"/>
<Button Content="Pobierz wszystko" HorizontalAlignment="Left" Margin="122,38,0,0" VerticalAlignment="Top" Width="103" />
<ScrollViewer HorizontalAlignment="Left" Height="460" Margin="10,63,0,0" VerticalAlignment="Top" Width="1000" HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Visible">
<Grid x:Name="Photos" ShowGridLines="False">
<TextBlock TextWrapping="Wrap" Text="text here"/>
</Grid>
</ScrollViewer>
<TextBox Name="InfoBoxLabel" IsReadOnly="True" VerticalScrollBarVisibility="Auto" HorizontalAlignment="Left" Height="48" Margin="230,10,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="300"/>
</Grid>
Output will be http://prntscr.com/3w0cr9
Related
I need help with my WPF application. In the bottom of my window I have a canvas which is filled dynamically with groupboxes, which contain several userlements like buttons and gridviews.
The inserted content is outside my window and I want to access it with scrollbars but the scrollbars aren't adjusting so I can't access the elements.
How can I reach the content with the scrollbars?
Thanks for your help.
<ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Visible" >
<Grid Height="Auto">
<GroupBox Header="Fleet Import" HorizontalAlignment="Left" Height="115" Margin="23,21,0,0" VerticalAlignment="Top" Width="419">
<StackPanel Margin="0,0,-67,0">
<StackPanel Orientation="Horizontal">
<Button x:Name="btnSelectProject" Content="Select Project" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" Width="88" Height="23" Click="btnSelectProject_Click"/>
<TextBox Name="tbPath" Height="17" Width="283" Margin="10,10,0,0" />
</StackPanel>
<Button x:Name="bntConnectTia" Content="Connect to TIA" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" Width="88" Height="23" Click="bntConnectTia_Click"/>
</StackPanel>
</GroupBox>
<GroupBox Header="Start update" HorizontalAlignment="Left" Height="115" Margin="498,21,0,0" VerticalAlignment="Top" Width="277">
<StackPanel Orientation="Horizontal">
<StackPanel>
<RadioButton Content="Maintanace" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" Width="88" Height="23"/>
<RadioButton Content="Production" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" Width="88" Height="23"/>
</StackPanel>
<StackPanel>
<Button Content="Start Update" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" Width="88" Height="23" Click="Button_Click_2"/>
<Button Content="Cancel" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" Width="88" Height="23"/>
</StackPanel>
</StackPanel>
</GroupBox>
<GroupBox Header="GroupBox" HorizontalAlignment="Left" Height="164" Margin="23,157,0,0" VerticalAlignment="Top" Width="752">
<TextBox HorizontalAlignment="Left" Height="128" TextWrapping="Wrap" Name="tbOutput" VerticalAlignment="Top" Width="742" Margin="0,0,-2,0"/>
</GroupBox>
<Canvas x:Name="canvasDevices" Margin="23,346,25,10" Height="Auto" />
<GroupBox Header="GroupBox" HorizontalAlignment="Left" Height="164" Margin="-393,337,0,-439" VerticalAlignment="Top" Width="752" Visibility="Hidden">
<StackPanel>
<StackPanel Orientation="Horizontal">
<Button Content="Button" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" Width="75"/>
<TextBox HorizontalAlignment="Left" Height="23" Margin="10,10,0,0" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Top" Width="120"/>
<Button Content="Button" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" Width="75"/>
</StackPanel>
<DataGrid Margin="20,10,20,0" RenderTransformOrigin="0.163,0.543" Height="88"/>
</StackPanel>
</GroupBox>
<Button Content="Button" HorizontalAlignment="Left" Margin="89,151,0,0" VerticalAlignment="Top" Width="75" Click="Button_Click_3"/>
</Grid>
</ScrollViewer>
GroupBox groupbox = new GroupBox();
groupbox.Header = deviceName;
groupbox.Name = deviceName;
groupbox.Width = 742;
groupbox.Height = 250;
stackPanelV.Children.Add(stackPanelH);
stackPanelV.Children.Add(dgDevice);
groupbox.Content = stackPanelV;
Canvas.SetTop(groupbox,0);
canvasDevices.Children.Add(groupbox);
Your items get out the canvas bounds, canvas is not resized and ScrollView not applied.
By the way I dont recommend you using canvas for that prupose.
There is plenty of other layouts that will give you a better result such as StackPanel or WrapPanel, and if you give to WrapPanel a width it will nicely rearrange your items.
Im trying to create a progress bar for one of my computer configuration scripts and I'd like to avoid adding a button or some kind of trigger to the GUI,
The script is powershell and for the GUI XAML:
<Window x:Name="BackUp_MAINWINDOW" x:Class="ProgressBarTest.MainWindow"
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:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:ProgressBarTest"
mc:Ignorable="d"
Title="88%" Height="110" Width="510" Icon="C:\Users\rsosa012\Documents\Scripts\Powershell\ICOs\PwC.ico" ResizeMode="CanMinimize" WindowStartupLocation="CenterScreen" Top="0" FontFamily="Georgia" Margin="0,-1,0,0" FontSize="11" SnapsToDevicePixels="True" BorderThickness="0">
<Window.TaskbarItemInfo>
<TaskbarItemInfo Description="Progress" ProgressState="Indeterminate" ProgressValue="50"/>
</Window.TaskbarItemInfo>
<Grid>
<ProgressBar HorizontalAlignment="Left" Height="17" Margin="10,44,0,0" VerticalAlignment="Top" Width="410" Value="50" Opacity="0.6"/>
<Image HorizontalAlignment="Left" Height="50" Margin="435,10,0,0" VerticalAlignment="Top" Width="50" Source="C:\Users\rsosa012\Documents\Scripts\Powershell\ICOs\PwC.ico"/>
<Label Content="Name: " HorizontalAlignment="Left" Height="20" Margin="10,6,0,0" VerticalAlignment="Top" Width="46" FontFamily="Georgia" Background="{x:Null}" Foreground="Black" FontSize="10" FontWeight="Bold"/>
<Label Content="Items remaining: " HorizontalAlignment="Left" Height="21" Margin="10,19,0,0" VerticalAlignment="Top" Width="110" FontFamily="Georgia" Background="{x:Null}" Foreground="Black" FontSize="10" FontWeight="Bold"/>
<TextBlock HorizontalAlignment="Left" Height="15" Margin="392,28,0,0" TextWrapping="Wrap" Text="88%" VerticalAlignment="Top" Width="28" FontSize="12" Opacity="0.6"/>
<TextBlock HorizontalAlignment="Left" Height="11" Margin="51,12,0,0" TextWrapping="Wrap" Text="TextBlock" VerticalAlignment="Top" Width="62" FontSize="9"/>
<TextBlock HorizontalAlignment="Left" Height="11" Margin="106,25,0,0" TextWrapping="Wrap" Text="TextBlock" VerticalAlignment="Top" Width="62" FontSize="9"/>
</Grid>
My question is about the events of these controls, does any of these controls have an event that triggers when the .showdialog() method executes, basically when the window appears?
Thanks in advance.
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.
I made a product page but the scrollviewer does not show everything that is in that grid. I have a feeling that is has something to do with my row definitions I hope someone can help me
XAML:
<Page
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" Height="729.552">
<Page.Resources>
</Page.Resources>
<Grid x:Name="LayoutRoot" d:DataContext="{d:DesignData /SampleData/RootObjectSampleData2.xaml}" HorizontalAlignment="Left" VerticalAlignment="Top">
<Grid.ChildrenTransitions>
<TransitionCollection>
<EntranceThemeTransition/>
</TransitionCollection>
</Grid.ChildrenTransitions>
<!--TODO: Content should be placed within the following grid-->
<Grid x:Name="ContentPanel" HorizontalAlignment="Left" VerticalAlignment="Top">
<Pivot x:Name="ProductHub" HorizontalAlignment="Left" VerticalAlignment="Top">
<PivotItem x:Name="ProductPivot" Header="Item" DataContext="{Binding}" HorizontalAlignment="Left" VerticalAlignment="Top" Height="680">
<ScrollViewer Width="336" Height="670" HorizontalAlignment="Left" VerticalAlignment="Top" >
<Grid x:Name="ContentGrid" Height="auto" Margin="0">
<Grid.RowDefinitions>
<RowDefinition Height="auto" MinHeight="278"/>
<RowDefinition Height="30*"/>
<RowDefinition Height="auto" MinHeight="251"/>
<RowDefinition Height="77*"/>
<RowDefinition Height="34*"/>
</Grid.RowDefinitions>
<TextBlock x:Name="TBlockTitle" HorizontalAlignment="Left" Margin="10,10,0,0" TextWrapping="Wrap" Text="{Binding result.item.title}" VerticalAlignment="Top" Height="20" d:DataContext="{d:DesignData /SampleData/RootObjectSampleData.xaml}"/>
<Image x:Name="ImageProduct" HorizontalAlignment="Left" Height="160" Margin="10,49,0,0" VerticalAlignment="Top" Width="316" Stretch="Fill" Source="{Binding result.item.images.Item330}" Tapped="ImgProduct_Click" />
<TextBlock x:Name="BtnFavorite" HorizontalAlignment="Left" Margin="10,214,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" FontFamily="Segoe MDL2 Assets" FontSize="20" Height="20" Width="20" />
<TextBlock x:Name="TBlockHiddenSEO" HorizontalAlignment="Left" Margin="298,10,-6,0" TextWrapping="Wrap" Text="{Binding result.item.seo_name}" VerticalAlignment="Top" Opacity="0" Height="40" Width="44"/>
<TextBlock x:Name="textBlockCurrency" HorizontalAlignment="Left" Margin="192,218,0,0" TextWrapping="Wrap" Text="{Binding result.item.currency_symbol}" VerticalAlignment="Top" Height="20" Width="8"/>
<TextBlock x:Name="textBlockPrice" HorizontalAlignment="Left" Margin="205,218,0,0" TextWrapping="Wrap" Text="{Binding result.item.price}" VerticalAlignment="Top" Height="20" Width="28"/>
<TextBlock x:Name="textBlockLookAmmount" HorizontalAlignment="Left" Margin="10,258,0,0" TextWrapping="Wrap" Text="{Binding result.item.views}" VerticalAlignment="Top" Height="20" Width="16" d:DataContext="{d:DesignData /SampleData/RootObjectSampleData.xaml}"/>
<TextBlock x:Name="textBlockWatchedText" HorizontalAlignment="Left" Margin="31,258,0,0" TextWrapping="Wrap" Text="x bekeken sinds" VerticalAlignment="Top" Height="20" Width="105"/>
<TextBlock x:Name="textBlockDate" HorizontalAlignment="Left" Margin="141,258,0,0" TextWrapping="Wrap" Text="{Binding result.item.placed}" VerticalAlignment="Top" Height="20" Width="81" d:DataContext="{d:DesignData /SampleData/RootObjectSampleData.xaml}"/>
<StackPanel x:Name="StPanelUser" Grid.Row="1" Margin="0,10,0,20"/>
<TextBlock x:Name="textBlockDescription" HorizontalAlignment="Left" Margin="10,10,0,0" TextWrapping="Wrap" Text="{Binding result.item.description}" VerticalAlignment="Top" Width="316" Grid.Row="1"/>
<TextBlock x:Name="textBlockShipping" HorizontalAlignment="Left" Margin="10,1,0,0" Grid.Row="2" TextWrapping="Wrap" Text="Shipping" VerticalAlignment="Top" Height="20" Width="59"/>
<TextBlock x:Name="textBlockState" HorizontalAlignment="Left" Margin="10,26,0,0" Grid.Row="2" TextWrapping="Wrap" Text="State" VerticalAlignment="Top" Height="20" Width="59"/>
</Grid>
</ScrollViewer>
</PivotItem>
</Pivot>
</Grid>
<ProgressRing HorizontalAlignment="Left" VerticalAlignment="Top" x:Name="ProgressRing"/>
</Grid>
Thank you
I'm pretty sure, that the parent element of your scrollviewer has a smaller height than the scrollviewer itself - the height of the scrollviewer sets the height of the control, not the heigh of the content...
As consequence, if the scrollviewer is 200px greater than the parent control - the last 200px of the scrollviewer are cut off
Remove Height="670" in the ScrollViewer. If you set the height for a ScrollViewer, then it displays the controls that fits in the given height
<ScrollViewer Width="336" HorizontalAlignment="Left" VerticalAlignment="Top" >
....
....
</ScrollViewer>
.
<Window x:Class="minimizeApp.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid >
<ScrollViewer Width="336" HorizontalAlignment="Left" VerticalAlignment="Top" >
<Grid x:Name="ContentGrid" Height="auto" Margin="0">
<Grid.RowDefinitions>
<RowDefinition Height="auto" MinHeight="278"/>
<RowDefinition Height="30*"/>
<RowDefinition Height="auto" MinHeight="251"/>
<RowDefinition Height="77*"/>
<RowDefinition Height="34*"/>
</Grid.RowDefinitions>
<TextBlock x:Name="TBlockTitle" HorizontalAlignment="Left" Margin="10,10,0,0" TextWrapping="Wrap" Text="title" VerticalAlignment="Top" Height="20" />
<Image x:Name="ImageProduct" HorizontalAlignment="Left" Height="160" Margin="10,49,0,0" VerticalAlignment="Top" Width="316" Stretch="Fill" Source="Images/graph1.jpg" />
<TextBlock x:Name="BtnFavorite" HorizontalAlignment="Left" Margin="10,214,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" FontFamily="Segoe MDL2 Assets" FontSize="20" Height="20" Width="20" />
<TextBlock x:Name="TBlockHiddenSEO" HorizontalAlignment="Left" Margin="298,10,-6,0" TextWrapping="Wrap" Text="name" VerticalAlignment="Top" Opacity="0" Height="40" Width="44"/>
<TextBlock x:Name="textBlockCurrency" HorizontalAlignment="Left" Margin="192,218,0,0" TextWrapping="Wrap" Text="currency" VerticalAlignment="Top" Height="20" Width="8"/>
<TextBlock x:Name="textBlockPrice" HorizontalAlignment="Left" Margin="205,218,0,0" TextWrapping="Wrap" Text="price" VerticalAlignment="Top" Height="20" Width="28"/>
<TextBlock x:Name="textBlockLookAmmount" HorizontalAlignment="Left" Margin="10,258,0,0" TextWrapping="Wrap" Text="123" VerticalAlignment="Top" Height="20" Width="16" />
<TextBlock x:Name="textBlockWatchedText" HorizontalAlignment="Left" Margin="31,258,0,0" TextWrapping="Wrap" Text="x bekeken sinds" VerticalAlignment="Top" Height="20" Width="105"/>
<TextBlock x:Name="textBlockDate" HorizontalAlignment="Left" Margin="141,258,0,0" TextWrapping="Wrap" Text="placed" VerticalAlignment="Top" Height="20" Width="81" />
<StackPanel x:Name="StPanelUser" Grid.Row="1" Margin="0,10,0,20"/>
<TextBlock x:Name="textBlockDescription" HorizontalAlignment="Left" Margin="10,10,0,0" TextWrapping="Wrap" Text="description" VerticalAlignment="Top" Width="316" Grid.Row="1"/>
<TextBlock x:Name="textBlockShipping" HorizontalAlignment="Left" Margin="10,1,0,0" Grid.Row="2" TextWrapping="Wrap" Text="Shipping" VerticalAlignment="Top" Height="20" Width="59"/>
<TextBlock x:Name="textBlockState" HorizontalAlignment="Left" Margin="10,26,0,0" Grid.Row="2" TextWrapping="Wrap" Text="State" VerticalAlignment="Top" Height="20" Width="59"/>
<TextBlock x:Name="textBlockpayment" HorizontalAlignment="Left" Margin="10,51,0,0" Grid.Row="2" TextWrapping="Wrap" Text="Payment" VerticalAlignment="Top" Height="20" Width="72"/>
<TextBlock x:Name="textBlockType" HorizontalAlignment="Left" Margin="10,76,0,0" Grid.Row="2" TextWrapping="Wrap" Text="Type" VerticalAlignment="Top" Height="20" Width="59"/>
<TextBlock x:Name="textBlockRole" HorizontalAlignment="Left" Margin="10,101,0,0" Grid.Row="2" TextWrapping="Wrap" Text="Role" VerticalAlignment="Top" Height="20" Width="59"/>
<TextBlock x:Name="textBlockShipping_FillIn" HorizontalAlignment="Left" Margin="141,1,0,0" Grid.Row="2" TextWrapping="Wrap" Text="123" VerticalAlignment="Top" Height="20" Width="0"/>
<TextBlock x:Name="textBlockState_FillIn" HorizontalAlignment="Left" Margin="141,26,0,0" Grid.Row="2" TextWrapping="Wrap" Text="123" VerticalAlignment="Top" Height="20" Width="0"/>
<TextBlock x:Name="textBlockpayment_FillIn" HorizontalAlignment="Left" Margin="141,51,0,0" Grid.Row="2" TextWrapping="Wrap" Text="123" VerticalAlignment="Top" Height="20" Width="0"/>
<TextBlock x:Name="textBlockType_FillIn" HorizontalAlignment="Left" Margin="141,76,0,0" Grid.Row="2" TextWrapping="Wrap" Text="123" VerticalAlignment="Top" Height="20" Width="0"/>
<TextBlock x:Name="textBlockRole_FillIn" HorizontalAlignment="Left" Margin="141,101,0,0" Grid.Row="2" TextWrapping="Wrap" Text="1323" VerticalAlignment="Top" Height="20" Width="0"/>
<TextBlock x:Name="textBlockAdvertiser" HorizontalAlignment="Left" Margin="10,149,0,0" Grid.Row="2" TextWrapping="Wrap" Text="Adverteerder" VerticalAlignment="Top" Height="20" Width="87"/>
<TextBlock x:Name="textBlockLocation" HorizontalAlignment="Left" Margin="10,174,0,0" Grid.Row="2" TextWrapping="Wrap" Text="Locatie" VerticalAlignment="Top" Height="20" Width="87"/>
<TextBlock x:Name="textBlockPhone" HorizontalAlignment="Left" Margin="10,231,0,0" Grid.Row="2" TextWrapping="Wrap" Text="Telefoon" VerticalAlignment="Top" Height="20" Width="87"/>
<TextBlock x:Name="textBlockAdvertiser_FillIn" HorizontalAlignment="Left" Margin="141,149,0,0" Grid.Row="2" TextWrapping="Wrap" Text="name" VerticalAlignment="Top" Height="20" Width="37"/>
<TextBlock x:Name="textBlockLocation_FillIn" HorizontalAlignment="Left" Margin="141,174,0,0" Grid.Row="2" TextWrapping="Wrap" Text="123" VerticalAlignment="Top" Height="20" Width="8"/>
<TextBlock x:Name="textBlockProvince_FillIn" HorizontalAlignment="Left" Margin="141,199,0,0" Grid.Row="2" TextWrapping="Wrap" Text="123" VerticalAlignment="Top" Height="20" Width="0"/>
<TextBlock x:Name="textBlockPhone_FillIn" HorizontalAlignment="Left" Margin="141,231,0,0" Grid.Row="2" TextWrapping="Wrap" Text="phone" VerticalAlignment="Top" Height="20"/>
</Grid>
</ScrollViewer>
</Grid>
</Window>
I´m working on a Windows Phone 8.1 c# app.
I´m trying to acces a textbox that is inside a tab page of a Hub. But whatever i do i can´t acces the textbox in the MainPage.xaml.cs code. Can anyone tell me why?
Here is my XAML code:
<Grid>
<Hub x:Name="Hub" Header="My Buddy!" Background="#FF303030">
<HubSection Tag="0" x:Name="HubSelection" Header="Hoofdscherm">
<DataTemplate>
<Grid>
<Button x:Name="btnAgenda" Content="Agenda" HorizontalAlignment="Left" Margin="20,17,0,0" VerticalAlignment="Top" Height="140" Width="140" RenderTransformOrigin="0.5,0.5" BorderBrush="White" Background="#FFD13535" Foreground="White" Click="btnAgenda_Click"/>
<Button x:Name="btnTaken" Content="Taken" HorizontalAlignment="Right" Margin="0,17,20,0" VerticalAlignment="Top" Height="140" Width="140" RenderTransformOrigin="0.5,0.5" BorderBrush="White" Background="#FFD13535" Foreground="White" Click="btnTaken_Click"/>
<Button x:Name="btnNieuweAfspraak" Content="Nieuwe afspraak" HorizontalAlignment="Left" Margin="20,161,0,0" VerticalAlignment="Top" Height="140" Width="140" RenderTransformOrigin="0.5,0.5" BorderBrush="White" Background="#FFD13535" Foreground="White" Click="btnNieuweAfspraak_Click"/>
<Button x:Name="btnNieuweTaak" Content="Nieuwe taak" HorizontalAlignment="Right" Margin="0,161,20,0" VerticalAlignment="Top" Height="140" Width="140" RenderTransformOrigin="0.5,0.5" BorderBrush="White" Background="#FFD13535" Foreground="White" Click="btnNieuweTaak_Click"/>
</Grid>
</DataTemplate>
</HubSection>
<HubSection Tag="1" Header="Agenda">
<DataTemplate>
<Grid>
<AppBarButton HorizontalAlignment="Left" Icon="Add" Label="Nieuwe afspraak" Margin="6,419,-2,0" VerticalAlignment="Top" Height="81" Width="337" Click="AppBarButton_Click"/>
</Grid>
</DataTemplate>
</HubSection>
<HubSection Tag="2" Header="Taken">
<DataTemplate>
<Grid>
<AppBarButton HorizontalAlignment="Left" Icon="Add" Label="Nieuwe taak" Margin="6,419,-2,0" VerticalAlignment="Top" Height="81" Width="337" Click="AppBarButton_Click_1" FontFamily="Global User Interface"/>
</Grid>
</DataTemplate>
</HubSection>
<HubSection Tag="3" x:Name="NewAfspraak" Header="Nieuwe afspraak">
<DataTemplate>
<Grid>
<TextBox x:Name="AfspraakBox" HorizontalAlignment="Left" Margin="10,10,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="321" Height="47" PlaceholderText="Naam afspraak" TextChanged="AfspraakBox_TextChanged" IsColorFontEnabled="False"/>
<DatePicker x:Name="DatumAfspraak" HorizontalAlignment="Left" Margin="10,52,0,0" VerticalAlignment="Top" Height="55" Width="157"/>
<TimePicker x:Name="BegintijdAfspraak" HorizontalAlignment="Left" Margin="172,52,0,0" VerticalAlignment="Top" Height="53" Width="159"/>
<TextBox x:Name="tbLocatieAfspraak" HorizontalAlignment="Left" Margin="10,106,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="321" PlaceholderText="Locatie" Height="42"/>
<TextBox HorizontalAlignment="Left" Margin="10,165,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Height="255" Width="321" PlaceholderText="Omschrijving"/>
<Button x:Name="btnAfspraakOpslaan1" Content="Opslaan" HorizontalAlignment="Left" Margin="172,436,0,0" VerticalAlignment="Top" RenderTransformOrigin="0.5,0.5" Width="159" Height="63" Click="btnAfspraakOpslaan1_Click"/>
<Button x:Name="btnAfspraakOpslaan" Content="Annuleren" HorizontalAlignment="Left" Margin="10,436,0,0" VerticalAlignment="Top" RenderTransformOrigin="0.5,0.5" Width="157" Height="63" Click="btnAfspraakAnnuleren_Click"/>
</Grid>
</DataTemplate>
</HubSection>
<HubSection Tag="4" Header="Nieuwe taak">
<DataTemplate>
<Grid>
<TextBox x:Name="TbNaamTaak" HorizontalAlignment="Left" Margin="10,10,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="321" Height="47" PlaceholderText="Naam taak"/>
<TextBox x:Name="tbTaakOmschrijving" HorizontalAlignment="Left" Margin="10,168,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="321" Height="254" PlaceholderText="Omschrijving"/>
<TextBlock HorizontalAlignment="Left" Margin="172,62,0,0" TextWrapping="Wrap" Text="Eindtijd:" VerticalAlignment="Top" Height="14" Width="54"/>
<TextBlock HorizontalAlignment="Left" Margin="10,62,0,0" TextWrapping="Wrap" Text="Begintijd:" VerticalAlignment="Top" Height="14" Width="98"/>
<TimePicker x:Name="BegintijdNieuweTaak" HorizontalAlignment="Left" Margin="10,71,0,0" VerticalAlignment="Top" Width="157" Height="55" ToolTipService.ToolTip="Selecteer een begintijd:" FontFamily="Global User Interface"/>
<TimePicker x:Name="EindtijdNieuweTaak" HorizontalAlignment="Left" Margin="172,71,0,0" VerticalAlignment="Top" Width="159" Height="53" ToolTipService.ToolTip="Selecteer een eindtijd:"/>
<Button x:Name="btnTaakOpslaan" Content="Opslaan" HorizontalAlignment="Left" Margin="172,436,0,0" VerticalAlignment="Top" RenderTransformOrigin="0.5,0.5" Width="159" Height="63" FontFamily="Global User Interface" Click="btnTaakOpslaan_Click"/>
<Button Content="Annuleren" HorizontalAlignment="Left" Margin="10,436,0,0" VerticalAlignment="Top" RenderTransformOrigin="0.5,0.5" Width="157" Height="63" Click="btnTaakAnnuleren" FontFamily="Global User Interface"/>
<DatePicker x:Name="DatumNieuweTaak" HorizontalAlignment="Left" Margin="10,114,0,0" VerticalAlignment="Top" Height="81" Width="321" FontFamily="Global User Interface"/>
</Grid>
</DataTemplate>
</HubSection>
</Hub>
</Grid>
And my MainPage.xaml.cs code:
private void btnTaken_Click(object sender, RoutedEventArgs e)
{
String Test = AfspraakBox.text;
Hub.ScrollToSection(Hub.Sections[2]);
}
The error that i'm getting is:
AfspraakBox does not exist in the current context.
I'm pritty sure it has something to do with the Hubs. Because in a new project without a Hub it just works fine. But i just can't figure out why and how to fix it.
You can't access a XAML control inside of a DataTemplate. That's a problem of HubSections. It uses DataTemplate, unlike PivotItem.