I am currently using multiple textblocks on a pivot control page, but I am unable to change the value of my textblocks. The reason is being "The name 'XXX' does not exist in the current context" even though I have named my textblocks for the value to be written in.
I am able to change the values when using a normal application page but pivot does not allow me to. Is there any way I can get past this?
<ScrollViewer>
<Grid x:Name="LayoutRoot" Background="Transparent" Height="768" Width="480">
<!--Pivot Control-->
<phone:Pivot Title="MY APPLICATION" Loaded="Pivot_Loaded">
<!--Pivot item one-->
<phone:PivotItem Header="Stats">
<Border
BorderBrush="{StaticResource PhoneBackgroundBrush}"
BorderThickness="{StaticResource PhoneBorderThickness}" Background="Black">
<Grid Margin="-3,75,-17,-75">
<TextBlock
TextWrapping="Wrap"
Style="{StaticResource PhoneTextExtraLargeStyle}" Margin="10,121,253,422" FontSize="30" Text="Highest Temp : " />
<TextBlock
TextWrapping="Wrap"
Style="{StaticResource PhoneTextExtraLargeStyle}" Margin="10,0,253,551" Text="Current Temp :" FontSize="30" />
<TextBlock
TextWrapping="Wrap"
Style="{StaticResource PhoneTextExtraLargeStyle}" Margin="10,240,253,311" Text="Lowest Temp : " FontSize="30" />
<TextBlock
TextWrapping="Wrap"
Style="{StaticResource PhoneTextExtraLargeStyle}" Margin="10,360,253,191" Text="Average Temp : " FontSize="30" />
<TextBlock x:Name="TempAverage"
TextWrapping="Wrap"
Style="{StaticResource PhoneTextExtraLargeStyle}" Margin="222,360,41,191" Text="-" FontSize="30" />
<TextBlock x:Name="TempLowest"
TextWrapping="Wrap"
Style="{StaticResource PhoneTextExtraLargeStyle}" Margin="222,240,41,311" Text="-" FontSize="30" />
<TextBlock x:Name="TempHighest"
TextWrapping="Wrap"
Style="{StaticResource PhoneTextExtraLargeStyle}" Margin="222,121,41,430" Text="-" FontSize="30" />
<TextBlock x:Name="TempCurrent"
TextWrapping="Wrap"
Style="{StaticResource PhoneTextExtraLargeStyle}" Margin="222,0,41,551" Text="-" FontSize="30" />
</Grid>
</Border>
Here is my cs code
if(TempRandom2 > Max)
{
Max = TempRandom2; //Highest Temp = Current Temp
TempHighest.Text = Max.ToString("0.0");
}
if(TempRandom2 < Min)
{
Min = TempRandom2;
TempLowest.Text = Min.ToString("0.0"); //Lowest Temp = Current Temp
}
AvgTemp[a++ % 100] = TempRandom2;
if (a > 100)
TempAverage.Text = AvgTemp.Average().ToString("0.0");
else
TempAverage.Text = (AvgTemp.Sum() / a).ToString("0.0");
}
}
}
Related
I have a ListBox including an ItemTemplate with a StackPanel. I want to access that stackpanel and change its visibility.
(Change it's visibility to collapsed when I click mouseleftbutton "closeAll")
I can do that with FindDescendantByName Method but it works for only listbox items on screen (Only first 10 items) but when I am scrolling down, I see that this is not working for other listbox items.
I think that errors occurs because of VisualTreeHelper. What can I use instead of VisualTreeHelper?
Thanks..
XAML CODE
<ListBox x:Name="listBoxEditPast" SelectionMode="Single" Margin="0" Background="#272B34" ScrollViewer.VerticalScrollBarVisibility="Visible">
<ListBox.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<Border Grid.Row="0" BorderThickness="4,0,0,0" Margin="2,0,0,0" Height="29" Background="#2E323B" Width="1050" BorderBrush="#1373A9" MouseLeftButtonDown="Border_MouseLeftButtonDown">
<DockPanel Name="dockPanelPast" Margin="0,4,0,0">
<Image Name="imgArrow" Source="images/down-arrow.png" HorizontalAlignment="Left" Width="20" Height="18"/>
<TextBlock Text="{Binding CreateDate}" Name="txtTarih" Foreground="White" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="16"/>
<TextBlock Text="{Binding SarjNo}" Name="txtSarjNo" Foreground="#FF9CA518" HorizontalAlignment="Stretch" VerticalAlignment="Center" FontSize="16" Margin="50,0,0,0" Width="90"/>
<TextBlock Text="{Binding Adi}" Name="txtReceteAdi" Foreground="#FF26A053" VerticalAlignment="Center" FontSize="16" Margin="40,0,0,0" HorizontalAlignment="Stretch"/>
<Button Content="Detaylar" Style="{StaticResource BlueButton}" HorizontalAlignment="Right" VerticalAlignment="Center" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" DockPanel.Dock="Right"/>
</DockPanel>
</Border>
<StackPanel Grid.Row="1" Name="stackPanelDetay" Tag="{Binding ID}">
<DockPanel>
<TextBlock Text="Sipariş No" Foreground="#D9480F" VerticalAlignment="Center" />
<TextBlock Text="Parça" Foreground="#AF0FD9" VerticalAlignment="Center" Margin="50,0,0,0" Width="200" />
<TextBlock Text="Malzeme" Foreground="White" VerticalAlignment="Center" Margin="150,0,0,0" Width="90"/>
<TextBlock Text="Müşteri" Foreground="#AF0FD9" VerticalAlignment="Center" Margin="70,0,0,0" />
</DockPanel>
<DockPanel>
<TextBlock Text="{Binding ID}" Foreground="White" VerticalAlignment="Center" Width="100"/>
<TextBlock Text="{Binding ParcaKoduAdi}" Foreground="White" VerticalAlignment="Center" Margin="5,0,0,0" Width="200" />
<TextBlock Text="{Binding Malzeme}" Foreground="White" VerticalAlignment="Center" Margin="152,0,0,0" Width="90" />
<TextBlock Text="{Binding MusteriKoduAdi}" Foreground="White" VerticalAlignment="Center" Margin="70,0,0,0" />
</DockPanel>
</StackPanel>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
C# CODE
public static class FrameworkElementExtensions
{
public static FrameworkElement FindDescendantByName(this FrameworkElement element, string name)
{
if (element == null || string.IsNullOrWhiteSpace(name)) { return null; }
if (name.Equals(element.Name, StringComparison.OrdinalIgnoreCase))
{
return element;
}
var childCount = VisualTreeHelper.GetChildrenCount(element);
for (int i = 0; i < childCount; i++)
{
var result = (VisualTreeHelper.GetChild(element, i) as FrameworkElement).FindDescendantByName(name);
if (result != null) { return result; }
}
return null;
}
}
private void closeAll_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
// StackPanel panel = LayoutHelper.FindElement(listBoxEditPast, n => n.GetType() == typeof(StackPanel)) as StackPanel;
for (int i = 0; i < listBoxEditPast.Items.Count; i++)
{
var element = listBoxEditPast.ItemContainerGenerator.ContainerFromIndex(i) as FrameworkElement;
if (element != null)
{
var sp = element.FindDescendantByName("stackPanelDetay") as StackPanel;
if (sp != null)
{
sp.Visibility = Visibility.Collapsed;
}
}
}
}
noting to do with the visualtreehelper, this is because the list is virtualized, so only the first ten items are created and then replaced by the ten next....and you loose your modifications
you must not work with the element in the data template by code
iterate through your data to set a boolean to true/false for all and then change the stack and bind the visibility to this boolean
<StackPanel Grid.Row="1" Name="stackPanelDetay" Visibility="{Binding myBoolean, Converter=BoolToVisibility}">
On my Resources.xaml(Resource Dictionary) I have a DataTemplate :
<DataTemplate x:Key="ProductDetailsContentTemplate">
<StackPanel Orientation="Vertical" >
<Viewbox Margin="27,0,28,0" Height="200" >
<Image UWPUtil:ImageExtensions.CachedUriSource="{Binding ImageUri}" />
</Viewbox>
<TextBlock Text="Description" Style="{StaticResource CaptionTextBlockStyle}" FontWeight="Bold" FontSize="24"/>
<TextBlock Text="{Binding ProductDescription}" Style="{StaticResource SubtitleTextBlockStyle}" FontSize="30"/>
<TextBlock Text="Barcode" Style="{StaticResource CaptionTextBlockStyle}" FontWeight="Bold" FontSize="24"/>
<TextBlock Text="{Binding Barcode}" Style="{StaticResource SubtitleTextBlockStyle}" FontSize="30"/>
<TextBlock Text="Weight" Style="{StaticResource CaptionTextBlockStyle}" FontWeight="Bold" FontSize="24"/>
<TextBlock Text="{Binding Weight}" Style="{StaticResource SubtitleTextBlockStyle}" FontSize="30"/>
<TextBlock Text="Quantity" Style="{StaticResource CaptionTextBlockStyle}" FontWeight="Bold" FontSize="24"/>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="25*"/>
<ColumnDefinition Width="50*"/>
<ColumnDefinition Width="25*"/>
</Grid.ColumnDefinitions>
<Button x:Name="SubtractQytyButton" Grid.Column="0" Content="-" FontSize="24" HorizontalAlignment="Stretch"
Margin="5,0" Style="{StaticResource TestButtonStyle}" FontWeight="ExtraBold"
Click="SubQytyButton_Click"/>
<TextBox x:Name="QuantityTextBox" Grid.Column="1" HorizontalAlignment="Stretch" FontSize="24" Margin="5,0"
KeyDown="Quantity_Keydown" TextChanging="Quantity_TextChanging"
Text="{Binding Quantity, Mode=TwoWay, Converter={StaticResource DecmialConverter}}" MaxLength="5" TextAlignment="Center"/>
<Button x:Name="AddQytyButton" Grid.Column="2" Content="+" FontSize="24" HorizontalAlignment="Stretch"
Margin="5,0" Style="{StaticResource TestButtonStyle}" FontWeight="ExtraBold"
Click="AddQytyButton_Click"/>
</Grid>
</StackPanel>
</DataTemplate><br>
I file nested it using the File Nesting from Mads Kristensen , here is the thread: https://marketplace.visualstudio.com/items?itemName=MadsKristensen.FileNesting
so I have a Resources.xaml.cs on my ResourceDictionary
my problem is I want to set my QuantityTextBox Value on AddQytyButton and SubQytyButton click command, here is my click command event:
private void AddQytyButton_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e)
{
//does not exist in the current context
QuantityTextBox.Text = "test";
}
OR
private void AddQytyButton_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e)
{
Button btn = sender as Button;
// this is not working as null reference
var textbox = (btn.Parent as StackPanel).Children[1] as TextBox;
}
Thanks,
NicoTing
You should cast btn.Parent to a Grid instead of a StackPanel since you are using the former in your XAML.
var textbox = (btn.Parent as Grid).Children[1] as TextBox;
I have code to download data from WordPress
Here it is:
private async void Down_at_Start() {
RestAPI rest = new RestAPI("http://simplegames.com.ua/wp-json/wc/v1/", "ck_9d64c027d2c5f81b8bed3342eeccc6d337be813d", "cs_60697b1e6cbdeb8d62d19e0765e339f8e3334754");
WCObject wc = new WCObject(rest);
//Get all products
var orders = await wc.GetOrders();
string date = orders[0].date_created + "+0:00";
DateTime dt = DateTime.Parse(date);
string convertedDate = dt.ToString("dd/MM/yyyy HH:mm:ss");
try
{
date1.Text = convertedDate;
adress1.Text = orders[0].shipping.address_1.ToString() + " " + orders[0].shipping.address_2;
name1.Text = orders[0].billing.first_name.ToString();
}
catch (Exception e)
{
Debug.WriteLine(e.Message);
Debug.WriteLine(e.StackTrace);
}
string date_2 = orders[1].date_created + "+0:00";
DateTime dt2 = DateTime.Parse(date_2);
string convertedDate2 = dt2.ToString("dd/MM/yyyy HH:mm:ss");
try
{
date2.Text = convertedDate2;
adress2.Text = orders[1].shipping.address_1.ToString() + " " + orders[1].shipping.address_2;
name2.Text = orders[1].billing.first_name.ToString();
}
catch (Exception e)
{
Debug.WriteLine(e.Message);
Debug.WriteLine(e.StackTrace);
}
string date_3 = orders[2].date_created + "+0:00";
DateTime dt3 = DateTime.Parse(date_3);
string convertedDate3 = dt3.ToString("dd/MM/yyyy HH:mm:ss");
try
{
date3.Text = convertedDate3;
adress3.Text = orders[2].shipping.address_1.ToString() + " " + orders[2].shipping.address_2;
name3.Text = orders[2].billing.first_name.ToString();
}
catch (Exception e)
{
Debug.WriteLine(e.Message);
Debug.WriteLine(e.StackTrace);
}
string date_4 = orders[3].date_created + "+0:00";
DateTime dt4 = DateTime.Parse(date_4);
string convertedDate4 = dt4.ToString("dd/MM/yyyy HH:mm:ss");
try
{
date4.Text = convertedDate4;
adress4.Text = orders[3].shipping.address_1.ToString() + " " + orders[3].shipping.address_2;
name4.Text = orders[3].billing.first_name.ToString();
}
catch (Exception e)
{
Debug.WriteLine(e.Message);
Debug.WriteLine(e.StackTrace);
}
string date_5 = orders[4].date_created + "+0:00";
DateTime dt5 = DateTime.Parse(date_5);
string convertedDate5 = dt5.ToString("dd/MM/yyyy HH:mm:ss");
try
{
date5.Text = convertedDate5;
adress5.Text = orders[4].shipping.address_1.ToString() + " " + orders[4].shipping.address_2;
name5.Text = orders[4].billing.first_name.ToString();
}
catch (Exception e)
{
Debug.WriteLine(e.Message);
Debug.WriteLine(e.StackTrace);
}
}
As you see I have static number of fields.
My XAML:
<Page
x:Class="Milano.InWork"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Milano"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid BorderBrush="White" BorderThickness="1">
<Grid.Background>
<ImageBrush Stretch="Fill" ImageSource="Images/Background.png"/>
</Grid.Background>
<Grid HorizontalAlignment="Left" Height="720" VerticalAlignment="Top" Width="60" BorderBrush="#FFF5F1F1" BorderThickness="0,0,1,0">
<Button x:Name="MenuButton" Content="" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" Height="38" Width="38">
<Button.Background>
<ImageBrush Stretch="Uniform" ImageSource="Images/Menu-100.png"/>
</Button.Background>
</Button>
<Button x:Name="logoutbutton" Content="" HorizontalAlignment="Left" Margin="10,650,0,0" VerticalAlignment="Top" Height="43" Width="38">
<Button.Background>
<ImageBrush Stretch="Uniform" ImageSource="Images/Logout_Button.png"/>
</Button.Background>
</Button>
</Grid>
<Grid HorizontalAlignment="Left" Height="47" Margin="63,2,-121,0" VerticalAlignment="Top" Width="1338" BorderBrush="#FFFDFDFD" Padding="0,0,0,1" BorderThickness="0,0,0,1">
<TextBlock x:Name="textBlock" HorizontalAlignment="Left" TextWrapping="Wrap" Text="В Работе" VerticalAlignment="Top" Height="37" Width="1218" FontSize="32" FontFamily="SF UI Display" Padding="550,0,0,0" Foreground="White"/>
</Grid>
<ScrollViewer HorizontalAlignment="Left" Height="668" Margin="63,52,0,0" VerticalAlignment="Top" Width="350">
<StackPanel Height="1020" Width="350" BorderBrush="#FFFDFCFC" BorderThickness="0,0,1,0">
<Grid Height="204" BorderBrush="#FFFBF8F8" BorderThickness="0,0,0,1">
<TextBlock x:Name="date1" HorizontalAlignment="Left" TextAlignment="Center" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="350" Height="50" FontFamily="SF UI Display" FontSize="30" FontWeight="Light" Foreground="White" />
<TextBlock x:Name="adress1" TextAlignment="Center" HorizontalAlignment="Left" Margin="0,146,-1,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Height="58" Width="350" FontFamily="SF UI Display" FontSize="20" FontWeight="Light" Foreground="White" />
<TextBlock x:Name="name1" HorizontalAlignment="Left" TextAlignment="Center" Margin="0,86,-1,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Height="60" Width="350" FontFamily="SF UI Display" FontSize="30" FontWeight="Light" Foreground="White" Padding="0,0,0,0"/>
</Grid>
<Grid Height="204" BorderBrush="#FFFBF8F8" BorderThickness="0,0,0,1">
<TextBlock x:Name="date2" TextAlignment="Center" HorizontalAlignment="Left" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="350" Height="50" Foreground="White" FontFamily="SF UI Display" FontSize="30" FontWeight="Light" />
<TextBlock x:Name="adress2" TextAlignment="Center" HorizontalAlignment="Left" Margin="0,145,-1,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Height="59" Width="350" FontFamily="SF UI Display" FontSize="20" FontWeight="Light" Foreground="White" />
<TextBlock x:Name="name2" HorizontalAlignment="Left" Margin="0,87,-1,0" TextAlignment="Center" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Height="64" Width="350" FontFamily="SF UI Display" FontSize="30" FontWeight="Light" Foreground="White" Padding="0,0,0,50"/>
</Grid>
<Grid Height="204" BorderBrush="#FFFBF8F8" BorderThickness="0,0,0,1">
<TextBlock x:Name="date3" HorizontalAlignment="Left" TextAlignment="Center" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="350" Height="50" Foreground="White" FontFamily="SF UI Display" FontSize="30" FontWeight="Light" />
<TextBlock x:Name="adress3" HorizontalAlignment="Left" TextAlignment="Center" Margin="0,143,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="350" Height="61" FontFamily="SF UI Display" FontSize="20" FontWeight="Light" Foreground="White" />
<TextBlock x:Name="name3" HorizontalAlignment="Left" TextAlignment="Center" Margin="0,86,-1,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Height="60" Width="350" FontFamily="SF UI Display" FontSize="30" FontWeight="Light" Foreground="White" Padding="0,0,0,50"/>
</Grid>
<Grid Height="204" BorderBrush="#FFFBF8F8" BorderThickness="0,0,0,1">
<TextBlock x:Name="date4" HorizontalAlignment="Left" TextWrapping="Wrap" TextAlignment="Center" Text="" VerticalAlignment="Top" Width="350" Height="50" Foreground="White" FontFamily="SF UI Display" FontSize="30" FontWeight="Light" />
<TextBlock x:Name="adress4" HorizontalAlignment="Left" Margin="0,153,0,0" TextWrapping="Wrap" TextAlignment="Center" Text="TextBlock" VerticalAlignment="Top" Height="61" Width="342" FontFamily="SF UI Display" FontSize="20" FontWeight="Light" Foreground="White" />
<TextBlock x:Name="name4" HorizontalAlignment="Left" TextAlignment="Center" Margin="0,86,-1,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Height="60" Width="350" FontFamily="SF UI Display" FontSize="30" FontWeight="Light" Foreground="White" Padding="0,0,0,50"/>
</Grid>
<Grid Height="204" BorderBrush="#FFFBF8F8" BorderThickness="0,0,0,1">
<TextBlock x:Name="date5" HorizontalAlignment="Left" TextWrapping="Wrap" Text="" VerticalAlignment="Top" TextAlignment="Center" Width="350" Height="50" Foreground="White" FontFamily="SF UI Display" FontSize="30" FontWeight="Light" />
<TextBlock x:Name="adress5" TextAlignment="Center" HorizontalAlignment="Left" Margin="0,155,0,0" TextWrapping="Wrap" Text="TextBlock" VerticalAlignment="Top" Height="49" Width="349" FontFamily="SF UI Display" FontSize="20" FontWeight="Light" Foreground="White" />
<TextBlock x:Name="name5" HorizontalAlignment="Left" TextAlignment="Center" Margin="0,86,-1,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Height="60" Width="350" FontFamily="SF UI Display" FontSize="30" FontWeight="Light" Foreground="White" Padding="0,0,0,50"/>
</Grid>
</StackPanel>
</ScrollViewer>
</Grid>
How I can count how many orders in answer from website and generate grids?
Thank's for help so much! :)
There is a ContestListView with elements:
public MainPage()
{
this.InitializeComponent();
List<int> list = new List<int>();
list.Add(2);
list.Add(3);
list.Add(5);
list.Add(7);
ContestListView.ItemsSource = list;
}
I want to navigate to another Frame when SelectionChange is.
private void ContestSelectionChange(object sender, SelectionChangedEventArgs e)
{
this.Frame.Navigate(typeof(BlankPage1));
}
But I have a problem - sometimes, when I choose element at list, the BlankPage1 starts load, but I got an unhandled exception
{"Unspecified error\r\n\r\nUnspecified error\r\n"}
at this place
#if DEBUG && !DISABLE_XAML_GENERATED_BREAK_ON_UNHANDLED_EXCEPTION
UnhandledException += (sender, e) =>
{
if (global::System.Diagnostics.Debugger.IsAttached) global::System.Diagnostics.Debugger.Break();
};
#endif
This exception can be after first SelectionChandeg, but it can be too after second, third etc.
There is BlankPage1 XAML:
<Page
x:Class="Contests.BlankPage1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Contests"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Page.TopAppBar>
<CommandBar Foreground="White">
<CommandBar.Background>
<ImageBrush Stretch="Fill" ImageSource="Assets/app02_0013_panel_main.png"/>
</CommandBar.Background>
<CommandBar.SecondaryCommands>
<AppBarButton Label="LogOut" Click="onClick"/>
</CommandBar.SecondaryCommands>
</CommandBar>
</Page.TopAppBar>
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<ScrollViewer>
<RelativePanel>
<TextBlock x:Name="txtContestName"
Text="TestTest "
Foreground="DarkOliveGreen"
RelativePanel.AlignLeftWithPanel="True"
RelativePanel.Below=""
TextWrapping="Wrap"
FontSize="20"
Margin="5,10,0,10"/>
<TextBlock x:Name="CategoryExpiration" FontSize="12"
RelativePanel.AlignLeftWithPanel="True"
RelativePanel.Below="txtContestName"
Margin="5,0,0,10">
<Run x:Name="txtCategory" Text="Test "/>
<Run x:Name="txtExpiration" Text="2016-05-23" Foreground="Green"/>
</TextBlock>
<RelativePanel x:Name="QuestionPanel" RelativePanel.Below="CategoryExpiration"
RelativePanel.AlignLeftWithPanel="True"
RelativePanel.AlignRightWithPanel="True"
Background="Green"
Margin="5,0,5,5">
<TextBlock x:Name="textblock1" Text="Question:" Foreground="White"
RelativePanel.AlignLeftWithPanel="True"
Margin="5,5,5,0"/>
<TextBlock x:Name="txtQuestion" Foreground="White"
Text="Test?"
RelativePanel.AlignHorizontalCenterWithPanel="True"
RelativePanel.Below="textblock1"
TextWrapping="Wrap"
Margin="10, 5" TextAlignment="Center"/>
<TextBox x:Name="AnswerText" PlaceholderText="Test"
RelativePanel.Below="txtQuestion"
RelativePanel.AlignRightWithPanel="True"
RelativePanel.AlignLeftWithPanel="True"
Margin="5,5"/>
<Button x:Name="bSendAnswer" Content="Test"
RelativePanel.Below="AnswerText"
RelativePanel.AlignHorizontalCenterWithPanel="True"
Foreground="White"
Margin="5,5" Width="335"/>
</RelativePanel>
<RelativePanel x:Name="OrgPanel" RelativePanel.Below="QuestionPanel"
RelativePanel.AlignLeftWithPanel="True"
RelativePanel.AlignRightWithPanel="True"
Margin="5,0,5,5" BorderBrush="Gray">
<TextBlock x:Name="textblock2" Text="Organizator" Foreground="Green"
RelativePanel.AlignLeftWithPanel="True"
Margin="5,5,5,0"/>
<TextBlock x:Name="Org" Text="Test"
RelativePanel.Below="textblock2"
Foreground="DarkGreen"
FontSize="12"
RelativePanel.AlignRightWithPanel="True"
RelativePanel.AlignLeftWithPanel="True"
Margin="5,5"/>
</RelativePanel>
<RelativePanel x:Name="DesriptionPanel" RelativePanel.Below="OrgPanel"
RelativePanel.AlignLeftWithPanel="True"
RelativePanel.AlignRightWithPanel="True"
Margin="5,0,5,5" BorderBrush="Gray">
<TextBlock x:Name="textblock3" Text="Opis konkursu" Foreground="Green"
RelativePanel.AlignLeftWithPanel="True"
Margin="5,5,5,0"/>
<TextBlock x:Name="txtDescription" Text="test"
RelativePanel.Below="textblock3"
TextWrapping="Wrap"
Foreground="DarkGreen"
FontSize="12"
RelativePanel.AlignRightWithPanel="True"
RelativePanel.AlignLeftWithPanel="True"
Margin="5,5"/>
</RelativePanel>
<RelativePanel x:Name="PrizePanel" RelativePanel.Below="DesriptionPanel"
RelativePanel.AlignLeftWithPanel="True"
RelativePanel.AlignRightWithPanel="True"
Margin="5,0,5,5" BorderBrush="Gray">
<TextBlock x:Name="textblock4" Text="Test" Foreground="Green"
RelativePanel.AlignLeftWithPanel="True"
Margin="5,5,5,0"/>
<TextBlock x:Name="txtPrize" Text=""
RelativePanel.Below="textblock4"
Foreground="DarkGreen"
TextWrapping="Wrap"
FontSize="12"
RelativePanel.AlignRightWithPanel="True"
RelativePanel.AlignLeftWithPanel="True"
Margin="5,5"/>
</RelativePanel>
</RelativePanel>
</ScrollViewer>
</Grid>
What my problem is?
I'm stuck with not being able to display random generated numbers on a pivot page. Below is my code,
<!--LayoutRoot is the root grid where all page content is placed-->
<ScrollViewer>
<Grid x:Name="LayoutRoot" Background="Transparent" Height="768" Width="480">
<!--Pivot Control-->
<phone:Pivot Title="MY APPLICATION" Loaded="Pivot_Loaded">
<!--Pivot item one-->
<phone:PivotItem Header="Stats">
<Border
BorderBrush="{StaticResource PhoneBackgroundBrush}"
BorderThickness="{StaticResource PhoneBorderThickness}" Background="Black">
<Grid Margin="-3,75,-17,-75">
<TextBlock
TextWrapping="Wrap"
Style="{StaticResource PhoneTextExtraLargeStyle}" Margin="10,121,253,422" FontSize="30" Text="Highest Temp : " />
<TextBlock
TextWrapping="Wrap"
Style="{StaticResource PhoneTextExtraLargeStyle}" Margin="10,0,253,551" Text="Current Temp :" FontSize="30" />
<TextBlock
TextWrapping="Wrap"
Style="{StaticResource PhoneTextExtraLargeStyle}" Margin="10,240,253,311" Text="Lowest Temp : " FontSize="30" />
<TextBlock
TextWrapping="Wrap"
Style="{StaticResource PhoneTextExtraLargeStyle}" Margin="10,360,253,191" Text="Average Temp : " FontSize="30" />
<TextBlock Name="TempAverage"
TextWrapping="Wrap"
Style="{StaticResource PhoneTextExtraLargeStyle}" Margin="222,360,41,191" Text="-" FontSize="30" />
<TextBlock Name="TempLowest"
TextWrapping="Wrap"
Style="{StaticResource PhoneTextExtraLargeStyle}" Margin="222,240,41,311" Text="-" FontSize="30" />
<TextBlock Name="TempHighest"
TextWrapping="Wrap"
Style="{StaticResource PhoneTextExtraLargeStyle}" Margin="222,121,41,430" Text="-" FontSize="30" />
<TextBlock Name="TempCurrent"
TextWrapping="Wrap"
Style="{StaticResource PhoneTextExtraLargeStyle}" Margin="222,0,41,551" Text="-" FontSize="30" />
</Grid>
</Border>
</phone:PivotItem>
It then tells me the error "The name 'TempAverage does not exist in the current context'. Same with TempCurrent, TempHighest and TempLowest. What is the error that I am facing and how should I go about it?
int a = 0;
void time_Tick(object sender, EventArgs e)
{
DispatcherTimer time = new DispatcherTimer();
Random rnd = new Random();
double TempRandom = rnd.Next(100, 500); //generate random number
double TempRandom2 = TempRandom / 10;
***TempCurrent.Text = TempRandom2.ToString("0.0");
if(TempRandom2 > Max)
{
Max = TempRandom2; //Highest Temp = Current Temp
TempHighest.Text = Max.ToString("0.0");
}
if(TempRandom2 < Min)
{
Min = TempRandom2;
TempLowest.Text = Min.ToString("0.0"); //Lowest Temp = Current Temp
}
AvgTemp[a++ % 100] = TempRandom2;
if (a > 100)
TempAverage.Text = AvgTemp.Average().ToString("0.0");
else
TempAverage.Text = (AvgTemp.Sum() / a).ToString("0.0");***
}
You need to add a name to your elements. Eg. `TextBlocks. When you add a name to the elements you can reference them in the code. Like this.
<TextBlock Name="TempCurrent"
TextWrapping="Wrap"
Style="{StaticResource PhoneTextExtraLargeStyle}"
Margin="10,0,253,551"
Text="Current Temp :"
FontSize="30" />