Windows Phone App Crashes on ListPicker Selected Item - c#

My (first) Windows Phone app keeps crashing when the code takes the selection from a ListPicker, and a webbrowser navigates to that selection. It builds without errors, but crashed when I run it and press the button. I am a beginner when it comes to coding, so please dumb-down your answers :)
Heres my code:
XAML:
<phone:PhoneApplicationPage
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"
x:Class="SecurityCamera.Page1"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait" Orientation="Portrait"
mc:Ignorable="d"
shell:SystemTray.IsVisible="True">
<phone:PhoneApplicationPage.Resources>
<DataTemplate x:Name="ListPickerItemTemplate">
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Name}" Margin="10 0 0 0"/>
</StackPanel>
</DataTemplate>
<DataTemplate x:Name="ListPickerFullModeItemTemplate">
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Name}" Margin="10 0 0 0"/>
</StackPanel>
</DataTemplate>
</phone:PhoneApplicationPage.Resources>
<!--LayoutRoot is the root grid where all page content is placed-->
<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 Grid.Row="0" Margin="12,17,0,28">
<TextBlock Text="Security Camera Access" Style="{StaticResource PhoneTextNormalStyle}"/>
<TextBlock Text="Specify IP" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
</StackPanel>
<!--ContentPanel - place additional content here-->
<Grid x:Name="ContentPanel" Margin="12,138,12,0" Grid.RowSpan="2" Opacity="0.99">
<TextBox x:Name="box1" HorizontalAlignment="Left" Height="70" Margin="31,172,0,0" TextWrapping="Wrap" Text="Http://" VerticalAlignment="Top" Width="400"/>
<TextBox x:Name="box2" HorizontalAlignment="Left" Height="70" Margin="31,242,0,0" TextWrapping="Wrap" Text="Http://" VerticalAlignment="Top" Width="400"/>
<TextBox x:Name="box3" HorizontalAlignment="Left" Height="70" Margin="31,312,0,0" TextWrapping="Wrap" Text="Http://" VerticalAlignment="Top" Width="400"/>
<TextBox x:Name="box4" HorizontalAlignment="Left" Height="70" Margin="31,382,0,0" TextWrapping="Wrap" Text="Http://" VerticalAlignment="Top" Width="400"/>
<Button Content="Connect" HorizontalAlignment="Left" Height="80" Margin="84,527,0,0" VerticalAlignment="Top" Width="305" Click="Button_Click_1"/>
<Button Content="Save" HorizontalAlignment="Left" Height="80" Margin="84,457,0,0" VerticalAlignment="Top" Width="305" Click="Button_Click_2"/>
<TextBlock HorizontalAlignment="Left" Margin="10,119,0,0" TextWrapping="Wrap" Text="Write IP's below to save - Include http:// before all addresses!" VerticalAlignment="Top"/>
</Grid>
<toolkit:ListPicker x:Name="defaultPicker" SelectionChanged="OnListPickerChanged" ExpansionMode="FullScreenOnly" Header="Saved IP's:" Margin="72,0,72,489" Grid.Row="1"/>
<phone:WebBrowser x:Name="webBrowser" HorizontalAlignment="Left" Margin="12,143,0,0" VerticalAlignment="Top" Width="456" Grid.RowSpan="2" Height="615" Opacity="100" Visibility="Visible"/>
</Grid>
</phone:PhoneApplicationPage>
XAML.CS:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using System.Xml;
using System.IO.IsolatedStorage;
using System.IO;
namespace SecurityCamera
{
public partial class Page1 : PhoneApplicationPage
{
public Page1()
{
InitializeComponent();
defaultPicker.ItemsSource = new List<string>() { { box1.Text }, { box2.Text }, { box3.Text }, { box4.Text } };
webBrowser.Visibility = System.Windows.Visibility.Collapsed;
// DEBUG MESSAGE - DELETE
MessageBox.Show("Visibility set to Collapsed (startup)");
}
private void Button_Click_1(object sender, RoutedEventArgs e)
{
------------------------THIS IS WHERE IT CRASHES --------------------------
//DEBUG MESSAGE - DELETE
MessageBox.Show("Button Pressed!");
string selectedItem;
selectedItem = (sender as ListPicker).SelectedItem.ToString();
// Do what you want with selectedItem
webBrowser.Navigate(new Uri(selectedItem));
//DEBUG MESSAGE - DELETE
MessageBox.Show("webBrowser.Navigate Executed...Making Visible");
webBrowser.Visibility = System.Windows.Visibility.Visible;
// DEBUG MESSAGE - DELETE
MessageBox.Show("webBrowser navigation sent - webBrowser Visibility set to Visible - Button Press");
}
private void OnListPickerChanged(object sender, SelectionChangedEventArgs e)
{
string selectedItem;
selectedItem = (sender as ListPicker).SelectedItem.ToString();
// Do what you want with selectedItem
// webBrowser.Navigate(new Uri(selectedItem));
}
private void Button_Click_2(object sender, RoutedEventArgs e)
{
defaultPicker.ItemsSource = new List<string>() { { box1.Text }, { box2.Text }, { box3.Text }, { box4.Text } };
// Write Text's into param
IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication();
//create new file
using (StreamWriter writeFile = new StreamWriter(new IsolatedStorageFileStream("ip1.txt", FileMode.Create, FileAccess.Write, myIsolatedStorage)))
{
string someTextData = "{ box1.Text }";
writeFile.WriteLine(someTextData);
writeFile.Close();
}
}
}
}

I believe this cast is failing:
selectedItem = (sender as ListPicker).SelectedItem.ToString();
instead try:
selectedItem = defaultPicker.SelectedItem.ToString();

Related

Where do File Parsers belong in MVVM Design Pattern?

I have tried to find a good consistent folder structure in Visual Studio to capture all the possibilities. This so far has been what I've came up with for my project.
My Application looks like:
The xaml is pretty straight forward:
<Window x:Class="Check.Views.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:viewModels="clr-namespace:SA_BOM_Check.ViewModels"
mc:Ignorable="d"
d:DataContext="{d:DesignInstance Type=viewModels:MainWindowViewModel, IsDesignTimeCreatable=True}"
Height="600" Width="800"
DataContext="{StaticResource ResourceKey=MainWindowViewModel}">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="150" />
<ColumnDefinition></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="20"></RowDefinition>
<RowDefinition Height="40"></RowDefinition>
<RowDefinition Height="40"></RowDefinition>
<RowDefinition Height="10"></RowDefinition>
<RowDefinition Height="30"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="30"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<TextBlock Grid.Row="1" Grid.Column="0" VerticalAlignment="Center" HorizontalAlignment="Right" Text="XA File: " Height="30" FontSize="20" FontWeight="Bold"/>
<TextBox x:Name="TxtXAFile" Grid.Row="1" Grid.Column="1" Text="{Binding Path=XAFile, Mode=TwoWay}" VerticalAlignment="Center" FontSize="15"></TextBox>
<Button x:Name="BtnXaBrowse" Grid.Row="1" Grid.Column="2" VerticalAlignment="Center" Margin="10,5,80,1" FontSize="20" FontWeight="DemiBold" Click="BtnXaBrowse_OnClick">Browse...</Button>
<TextBlock Grid.Row="2" Grid.Column="0" VerticalAlignment="Center" HorizontalAlignment="Right" Text="Inventor File: " Height="30" FontSize="20" FontWeight="Bold"/>
<TextBox Grid.Row="2" Grid.Column="1" x:Name="TxtInventorFile" Text="{Binding Path=InventorFile, Mode=TwoWay}" VerticalAlignment="Center" FontSize="15"/>
<Button x:Name="BtnInventorBrowse" Grid.Row="2" Grid.Column="2" VerticalAlignment="Center" Margin="10,0,80,0" FontSize="20" FontWeight="DemiBold" Click="BtnInventorBrowse_OnClick">Browse...</Button>
<Button x:Name="BtnDiff" Grid.Row="2" Grid.Column="3" VerticalAlignment="Center" Margin="10,5,80,1" FontSize="20" FontWeight="DemiBold" Command="{Binding GetDifferences}">Differences</Button>
<Line Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="4" X1="0" Y1="0" X2="1" Y2="0" Stroke="Black" StrokeThickness="2" Stretch="Uniform"></Line>
<Label Grid.Row="4" Grid.Column="0" Grid.ColumnSpan="4" Content="Missing in Inventor (Inventor - XA)" FontSize="15" FontStyle="Normal" HorizontalAlignment="Center" FontWeight="Bold" Foreground="Black"/>
<DataGrid AutoGenerateColumns="True" Grid.Row="5" Grid.Column="0" Grid.ColumnSpan="4" IsReadOnly="True"
FontSize="18" ItemsSource="{Binding Path=XADiffDataTable}"
ColumnWidth="*">
<DataGrid.ColumnHeaderStyle>
<Style TargetType="{x:Type DataGridColumnHeader}">
<Setter Property="FontWeight" Value="Bold"></Setter>
</Style>
</DataGrid.ColumnHeaderStyle>
</DataGrid>
<Label Grid.Row="6" Grid.Column="0" Grid.ColumnSpan="4"
Content="Missing In XA (XA - Inventor)" FontSize="15" FontStyle="Normal"
HorizontalAlignment="Center" FontWeight="Bold" Foreground="Black"/>
<DataGrid Grid.Row="7" Grid.Column="0" Grid.ColumnSpan="4"
AutoGenerateColumns="True" IsReadOnly="True"
FontSize="18" ItemsSource="{Binding Path=InventorDiffDataTable}"
ColumnWidth="*">
<DataGrid.ColumnHeaderStyle>
<Style TargetType="{x:Type DataGridColumnHeader}">
<Setter Property="FontWeight" Value="Bold"></Setter>
</Style>
</DataGrid.ColumnHeaderStyle>
</DataGrid>
</Grid>
</Window>
Code Behind:
using System.Windows;
using System.Windows.Controls;
using Microsoft.Win32;
using SA_BOM_Check.ViewModels;
namespace SA_BOM_Check.Views
{
public partial class MainWindow : Window
{
//private readonly MainWindowViewModel _vm;
public MainWindow()
{
InitializeComponent();
//_vm = (MainWindowViewModel) this.DataContext;
}
private void BtnXaBrowse_OnClick(object sender, RoutedEventArgs e)
{
TxtXAFile.Text = OpenFileDialog();
TxtXAFile.GetBindingExpression(TextBox.TextProperty)?.UpdateSource();
//_vm.XAFile = OpenFileDialog();
}
private void BtnInventorBrowse_OnClick(object sender, RoutedEventArgs e)
{
TxtInventorFile.Text = OpenFileDialog();
TxtInventorFile.GetBindingExpression((TextBox.TextProperty))?.UpdateSource();
}
private string OpenFileDialog()
{
OpenFileDialog openFileDialog = new();
return openFileDialog.ShowDialog() == true ? openFileDialog.FileName : "";
}
}
}
Keeping the ShowDialog inside the code behind was inspired by BionicCode https://stackoverflow.com/users/3141792/bioniccode
Where he answered the question about OpenFileDialogs Open File Dialog MVVM Actual Answer (which should have been the answer to the question) is at https://stackoverflow.com/a/64861760/4162851
The InventorAndXACompare class in summary is
private static readonly Dictionary<string, Part> INVENTOR_PARTS
= new Dictionary<string, Part>();
private static readonly Dictionary<string, Part> XA_PARTS = new Dictionary<string, Part>();
private static readonly Dictionary<string, Part> XA_PARTS_OMIT = new Dictionary<string, Part>();
private static readonly DataTable MISSING_IN_INVENTOR = new DataTable("XACompared");
private static readonly DataTable MISSING_IN_XA = new DataTable("InventorCompared");
public static DataTable[] CompareFiles(string xaFile, string inventorFile)
private static void ParseInventor(string inventorFile)
private static void ParseXA(string xaFile)
private static void CompareXAToInventor()
private static void CompareInventorToXA()
The compare files takes two files. It then parses those files into two dictionaries that are compared in both directions where there are differences it adds those rows to a datatable inside the MainWindowViewModel those are then binded to the View by
private DataTable _xaDiffDataTable;
public DataTable XADiffDataTable
{
get { return _xaDiffDataTable;}
set
{
_xaDiffDataTable = value;
OnPropertyChanged("XADiffDataTable");
}
}
private DataTable _inventorDiffDataTable;
public DataTable InventorDiffDataTable
{
get { return _inventorDiffDataTable;}
set
{
_inventorDiffDataTable = value;
OnPropertyChanged("InventorDiffDataTable");
}
}
I would like to know if there is a better way of structuring this and if InventorAndXACompare would be better placed in the Models folder?
In an MVVM architecture you would usually find parsers in the Model component. The View Model generally does not process data. Usually it may convert data to meet the constraints of the Model's interface or to prepare data for presentation in the View.
Also from an MVVM point of view the data source and sink is always part of the Model. It does not matter whether data comes from a database or from a file picked by the user.

how to properly use item click in gridview

I have a gridview, which presents all of the users I have in my database, and their details, I want to be able, on the click of a user(on the gridview), that it's details will appear separately on the side of the grid view, and there I could change them accordingly. However, I'm not sure how to do so. I have the ItemClick event in my gridview, and It does recognize if I click on an item, but I don't know how to get that specific clicked user's details, for me to present them on the side. I also have another problem- for some reason It doesn't recognize nor let me click on any of the top row items on the grid view-only the ones below it, does anyone know why?
this is my XAML :
<Page
x:Class="My_Little_Animal.ShowUsers"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:My_Little_Animal"
xmlns:data="using:My_Little_Animal"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid>
<Grid.Background>
<ImageBrush ImageSource="/Assets/changeUserDetailesBackground.jpg"></ImageBrush>
</Grid.Background>
<Grid.RowDefinitions>
<RowDefinition Height="8*" />
<RowDefinition Height="147*"/>
<RowDefinition Height="100" />
</Grid.RowDefinitions>
<GridView Name="grid1" ItemClick="grid1_ItemClick" IsItemClickEnabled="True" Margin="-70,151,692,50" Grid.RowSpan="2" Grid.Row="1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<GridView.ItemTemplate>
<DataTemplate x:DataType="data:User">
<StackPanel Orientation="Horizontal" HorizontalAlignment="Left">
<StackPanel Margin="100,20,0,0">
<TextBlock Name="t1" FontSize="20" GotFocus="t1_GotFocus" Text="{x:Bind UserId}"/>
<TextBlock Name="t2" FontSize="20" GotFocus="t2_GotFocus" Text="{x:Bind Password}"/>
<TextBlock Name="t3" FontSize="20" GotFocus="t3_GotFocus" Text="{x:Bind UserName}"/>
<TextBlock Name="t4" FontSize="20" GotFocus="t4_GotFocus" Text="{x:Bind Email}"/>
</StackPanel>
</StackPanel>
</DataTemplate>
</GridView.ItemTemplate>
</GridView>
<Canvas>
<Image Name="loginTitle" Source="/Assets/ShowUsersTitle.png" RenderTransformOrigin="0.5,0.5" Grid.RowSpan="2" Canvas.Left="-325" Canvas.Top="-120" Height="462" Width="1875"/>
<TextBlock Grid.Row="2" Name="ResultTextBlock" FontSize="24" Foreground="Red" FontWeight="Bold" Height="169" Margin="0,0,0,-69"/>
<Image Name="editTheUserName" Width="100" Height="35" Visibility="Visible" Source="/Assets/editIcon.png" RenderTransformOrigin="0.5,0.5" Grid.Row="1" Canvas.Left="852" Canvas.Top="226" />
<Image Name="CancelTheUserNamE" Width="100" Height="35" Visibility="Visible" Source="/Assets/xIcon.png" RenderTransformOrigin="0.485,0.529" Grid.Row="1" Canvas.Left="848" Canvas.Top="224" />
<TextBlock Visibility="Visible" Name="theUserItself" FontFamily="Comic Sans MS" FontWeight="ExtraBold" FontStyle="Italic" FontSize="25" Text="your user name " RenderTransformOrigin="0.496,1.165" Foreground="#FF283D6C" Grid.Row="1" Canvas.Left="1103" Canvas.Top="219" HorizontalAlignment="Stretch" Margin="0,0,0,0" VerticalAlignment="Stretch"/>
<TextBlock Name="userName" FontFamily="Comic Sans MS" FontWeight="ExtraBold" FontStyle="Italic" FontSize="25" Text="User Name : " RenderTransformOrigin="0.496,1.165" TextDecorations="Underline" Grid.Row="1" Canvas.Left="922" Canvas.Top="224"/>
<TextBox Visibility="Visible" Width="200" Name="UserNameText" MaxLength="50" FontFamily="Comic Sans MS" FontStyle="Italic" FontSize="15" BorderThickness="3" BorderBrush="#FF23677D" Grid.Row="1" Canvas.Left="1099" Canvas.Top="223" HorizontalAlignment="Stretch" Margin="0,0,0,0" VerticalAlignment="Stretch"/>
<Button Visibility="Visible" Name="changeuserName" Height="49" Width="140" FontSize="20" Content="change" FontWeight="ExtraBold" BorderBrush="White" Foreground="White" BorderThickness="2" Background="#FF191A5C" HorizontalAlignment="Center" VerticalAlignment="Top" RenderTransformOrigin="0.45,0.536" Grid.Row="1" Canvas.Left="1305" Canvas.Top="210" Margin="0,0,0,0"/>
<Image Name="editTheEmail" Canvas.Top="286" Canvas.Left="850" Width="100" Height="35" Visibility="Visible" Source="/Assets/editIcon.png" RenderTransformOrigin="0.49,0.557" Grid.Row="1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" />
<Image Name="CancelTheEmail" Width="100" Height="35" Visibility="Visible" Source="/Assets/xIcon.png" RenderTransformOrigin="0.485,0.529" Grid.Row="1" Canvas.Left="847" Canvas.Top="284" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" />
<TextBlock Visibility="Visible" Name="theEmailItself" FontFamily="Comic Sans MS" FontWeight="ExtraBold" FontStyle="Italic" FontSize="25" Text="your email " RenderTransformOrigin="0.496,1.165" Foreground="#FF283D6C" Grid.Row="1" Canvas.Left="1105" Canvas.Top="276"/>
<TextBlock Name="Email" FontFamily="Comic Sans MS" FontWeight="ExtraBold" FontStyle="Italic" FontSize="25" Text="Email : " RenderTransformOrigin="0.496,1.165" TextDecorations="Underline" Grid.Row="1" Canvas.Left="921" Canvas.Top="283" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/>
<TextBox Visibility="Visible" Width="200" Name="EmailText" MaxLength="50" FontFamily="Comic Sans MS" FontStyle="Italic" FontSize="15" BorderThickness="3" BorderBrush="#FF23677D" Grid.Row="1" Canvas.Left="1093" Canvas.Top="284" HorizontalAlignment="Stretch" Margin="0,0,0,0" VerticalAlignment="Stretch"/>
<Button Visibility="Visible" Name="changeEmail" Height="49" Width="140" FontSize="20" Content="change" FontWeight="ExtraBold" BorderBrush="White" Foreground="White" BorderThickness="2" Background="#FF191A5C" HorizontalAlignment="Center" VerticalAlignment="Top" RenderTransformOrigin="0.45,0.536" Grid.Row="1" Canvas.Left="1302" Canvas.Top="274" Margin="0,0,0,0"/>
<Image Name="theReturn" Height="100" Width="100" Tapped="theReturn_Tapped_1" Source="/Assets/theReturnIcon.png" RenderTransformOrigin="0.493,0.496" Grid.RowSpan="2" Canvas.Left="65" Canvas.Top="27" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" />
</Canvas>
</Grid>
The c# code :
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using System.Xml;
using System.Data;
using Windows.UI.Popups;
// The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=234238
namespace My_Little_Animal
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class ShowUsers : Page
{
regitration.regitrationSoapClient cal;
public ShowUsers()
{
this.InitializeComponent();
cal = new regitration.regitrationSoapClient();
getData();
}
public async void getData()
{
regitration.getUserTableResponseGetUserTableResult r = await cal.getUserTableAsync();
List<User> theUserList = new List<User>();
User u = null;
XmlReader xr = r.Any1.CreateReader();
XmlDocument document = new XmlDocument();
document.Load(xr);
XmlNodeList theXmlList = document.GetElementsByTagName("Table");
foreach (XmlElement item in theXmlList)
{
u = new User();
foreach (XmlNode node in item.ChildNodes)
{
switch (node.Name)
{
case "userId": u.UserId = int.Parse(node.InnerText); break;
case "password": u.Password = node.InnerText; break;
case "userName": u.UserName = node.InnerText; break;
case "email": u.Email = node.InnerText; break;
}
}
theUserList.Add(u);
}
grid1.ItemsSource = theUserList;
}
private async void grid1_ItemClick(object sender, ItemClickEventArgs e)
{
var dialog = new MessageDialog("The item that was clicked is : ");
await dialog.ShowAsync();
}
private void t1_GotFocus(object sender, RoutedEventArgs e)
{
}
private void t2_GotFocus(object sender, RoutedEventArgs e)
{
}
private void t3_GotFocus(object sender, RoutedEventArgs e)
{
}
private void t4_GotFocus(object sender, RoutedEventArgs e)
{
}
private void theReturn_Tapped_1(object sender, TappedRoutedEventArgs e)
{
this.Frame.Navigate(typeof(Administrator));
}
}
}
I will be so thankful for any help, it's really important for me!
but I don't know how to get that specific clicked user's details, for me to present them on the side.
There are many ways to get the item in item click event. if you have used MVVM pattern, the recommend way is binding command. For more you could refer this case.
In general, you could subscribe ItemClick event and get ClickedItem from event ItemClickEventArgs
Example
private void VideoGridView_ItemClick(object sender, ItemClickEventArgs e)
{
var vedio = e.ClickedItem as VideoItem;
var item = new MediaPlaybackItem(MediaSource.CreateFromUri(new Uri(vedio.videoUri)));
mediaPlayerElement.Source = item;
}
I also have another problem- for some reason It doesn't recognize nor let me click on any of the top row items on the grid view-only the ones below it, does anyone know why?
I could not reproduce this issue, please check if there is some element cover the top row up cause the grid view could not be clicked.

c# UWP ListView with Columns Binding Sqlite

I am trying a ListView with multiple columns, with my code I get that, but i got some problem with the binding code, because I am geting the same values in both columns.
How I can get this?
MainPage.xaml
<Page
x:Class="SQlite_Test_01.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:SQlite_Test_01"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Button x:Name="btnCreateDB" Content="Crear DataBase" HorizontalAlignment="Left" Margin="23,10,0,0" VerticalAlignment="Top" Height="83" Width="255" Click="btnCreateDB_Click"/>
<Button x:Name="btnFillList" Content="Llenar Lista 1" HorizontalAlignment="Left" Margin="295,10,0,0" VerticalAlignment="Top" Height="83" Width="299" Click="btnFillList_Click"/>
<ListView x:Name="ctlList" Margin="23,113,0,241" BorderBrush="Black" BorderThickness="1" Background="White" HorizontalAlignment="Left" Width="944" >
<ListView.ItemTemplate>
<DataTemplate>
<Grid Width="{Binding ElementName=ctlList , Path=ActualWidth }" Padding="0" Margin="0" >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="150" />
<ColumnDefinition Width="300" />
<ColumnDefinition Width="000" />
</Grid.ColumnDefinitions>
<TextBox x:Name="Col1" Text="{Binding}" Grid.Column="0" TextWrapping="Wrap" />
<TextBox x:Name="Col2" Text="{Binding}" Grid.Column="1" TextWrapping="Wrap" />
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
<ListBox x:Name="ctlList_2" Margin="1047,113,0,241" BorderBrush="Black" BorderThickness="1" Background="White" HorizontalAlignment="Left" Width="155" ScrollViewer.IsVerticalScrollChainingEnabled="True" >
<ListBox.ItemTemplate>
<DataTemplate>
<Grid Width="{Binding ActualWidth, ElementName=ctlList_2}" Padding="0" Margin="0" >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="200" />
<ColumnDefinition Width="0" />
<ColumnDefinition Width="0" />
</Grid.ColumnDefinitions>
<TextBox Text="{Binding}" Grid.Column="0" TextWrapping="Wrap" />
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
</Page>
MainPage.xaml.cs
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using Windows.Storage;
using SQLitePCL;
// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409
namespace SQlite_Test_01
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
}
public SQLitePCL.SQLiteConnection dbConnection = new SQLiteConnection("folders.db");
private void btnCreateDB_Click(object sender, RoutedEventArgs e)
{
SQLiteConnection dbConnection = new SQLiteConnection("folders.db");
string sSQL = #"CREATE TABLE IF NOT EXISTS Folders
(IDFolder Integer Primary Key Autoincrement NOT NULL
, Foldername VARCHAR ( 200 )
, Path VARCHAR ( 255 ));";
ISQLiteStatement cnStatement = dbConnection.Prepare(sSQL);
cnStatement.Step();
}
private void btnFillList_Click(object sender, RoutedEventArgs e)
{
var items1 = new List<String>();
var items2 = new List<String>();
string sSQL = #"SELECT [Foldername],[Path] FROM Folders";
ISQLiteStatement dbState = dbConnection.Prepare(sSQL);
while (dbState.Step() == SQLiteResult.ROW)
{
string sFoldername = dbState["Foldername"] as string;
string sPath = dbState["Path"] as string;
items1.Add(sFoldername);
items2.Add(sPath);
;
}
ctlList.ItemsSource = items1;
ctlList_2.ItemsSource = items2;
}
}
}
PD: ctlList_2 will be erased when I resolve my trouble.
I am trying a ListView with multiple columns, with my code I get that, but i got some problem with the binding code, because I am geting the same values in both columns. How I can get this?
First, create a new class called Folders:
public class Folders
{
public string Foldername { get; set; }
public string Path { get; set; }
}
Then, set the ItemsSource for ctlList with List<Folders> instead of List<string>:
private void btnFillList_Click(object sender, RoutedEventArgs e)
{
// set the ItemsSource for ctlList with List<Folders> instead of List<string>:
var items1 = new List<Folders>();
string sSQL = #"SELECT [Foldername],[Path] FROM Folders";
ISQLiteStatement dbState = dbConnection.Prepare(sSQL);
while (dbState.Step() == SQLiteResult.ROW)
{
string sFoldername = dbState["Foldername"] as string;
string sPath = dbState["Path"] as string;
Folders folder = new Folders() { Foldername = sFoldername, Path = sPath };
items1.Add(folder);
;
}
ctlList.ItemsSource = items1;
}
Last, bind Foldername and Path to different columns:
<DataTemplate>
<Grid Width="{Binding ElementName=ctlList , Path=ActualWidth }" Padding="0" Margin="0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="150" />
<ColumnDefinition Width="300" />
<ColumnDefinition Width="000" />
</Grid.ColumnDefinitions>
<TextBox x:Name="Col1" Text="{Binding Path=Foldername}" Grid.Column="0" TextWrapping="Wrap" />
<TextBox x:Name="Col2" Text="{Binding Path=Path}" Grid.Column="1" TextWrapping="Wrap" />
</Grid>
</DataTemplate>
Here is Entire Sample for your reference.

Errors when editting existing WP8 project

So I am just starting out with this stuff and have run into some strife. There was a pivot soundboard application that I needed to change into a series of panorama pages but have the same functionality.
I have finished all the xaml and c# appropriately but I think because I had to create a new MainPage and delete the older one I have created several errors. I suspect they all have a similar cause so I will just provide three.
Error 1 The type 'SoundBoard.MainPage' already contains a definition
for 'LayoutRoot' \SoundBoard\obj\Debug\Cartoons.g.cs
Error 30 The name 'AudioPlayer' does not exist in the current
context \SoundBoard\Cartoons.xaml.cs
Error 7 Type 'SoundBoard.MainPage' already defines a member called
'InitializeComponent' with the same parameter types
\SoundBoard\obj\Debug\Cartoons.g.cs
I'll link my current MainPage and Cartoons and hopefully you guys can help me out.
MainPage.xaml:
<phone:PhoneApplicationPage
x:Class="SoundBoard.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DataContext="{d:DesignData SampleData/SampleData.xaml}"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait" Orientation="Portrait"
shell:SystemTray.IsVisible="True">
<!--LayoutRoot is the root grid where all page content is placed-->
<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 Grid.Row="0" Margin="12,17,0,28">
<TextBlock Text="SoundBoard" Style="{StaticResource PhoneTextNormalStyle}"/>
<TextBlock Text="Categories" 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">
<Button Content="Warnings" HorizontalAlignment="Left" Margin="244,304,0,0" VerticalAlignment="Top" Height="160" Width="182" Background="Red" Click="Button_Click_3"/>
<Button Content="Taunts" HorizontalAlignment="Left" Margin="27,304,0,0" VerticalAlignment="Top" Height="160" Width="182" Background="Red" Click="Button_Click_2"/>
<Button Content="Cartoons" HorizontalAlignment="Left" Margin="244,123,0,0" VerticalAlignment="Top" Height="160" Width="182" Background="Red" Click="Button_Click_1"/>
<Button Content="Animals" HorizontalAlignment="Left" Margin="27,123,0,0" VerticalAlignment="Top" Height="160" Width="182" Background="Red" Click="Button_Click"/>
</Grid>
</Grid>
</phone:PhoneApplicationPage>
MainPage.xaml.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
namespace SoundBoard
{
public partial class FirstPage : PhoneApplicationPage
{
public FirstPage()
{
InitializeComponent();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
NavigationService.Navigate(new Uri("/Animals.xaml", UriKind.Relative));
}
private void Button_Click_1(object sender, RoutedEventArgs e)
{
NavigationService.Navigate(new Uri("/Cartoons.xaml", UriKind.Relative));
}
private void Button_Click_2(object sender, RoutedEventArgs e)
{
NavigationService.Navigate(new Uri("/Taunts.xaml", UriKind.Relative));
}
private void Button_Click_3(object sender, RoutedEventArgs e)
{
NavigationService.Navigate(new Uri("/Warnings.xaml", UriKind.Relative));
}
}
}
Cartoons.xaml:
<phone:PhoneApplicationPage
x:Class="SoundBoard.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DataContext="{d:DesignData SampleData/SampleData.xaml}"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait" Orientation="Portrait"
shell:SystemTray.IsVisible="True">
<!--LayoutRoot contains the root grid where all other page content is placed-->
<Grid x:Name="LayoutRoot">
<phone:Panorama Title="{Binding Path=LocalizedResources.ApplicationTitle,
Source={StaticResource LocalizedStrings}}">
<!--Panorama item one-->
<phone:PanoramaItem Header="Cartoons">
<Grid>
<Image HorizontalAlignment="Center" Height="431" Margin="10,10,0,0" VerticalAlignment="Top" Width="400" Source="/Assets/cartoon.jpg"/>
</Grid>
</phone:PanoramaItem>
<!--Panorama item two-->
<phone:PanoramaItem Header="Sounds">
<phone:LongListSelector
Margin="0,0,-12,0"
ItemsSource="{Binding Cartoons.Items}"
LayoutMode="Grid"
GridCellSize="150,150"
>
<phone:LongListSelector.ItemTemplate>
<DataTemplate>
<Grid Background="{StaticResource PhoneAccentBrush}">
<Grid VerticalAlignment="Top" HorizontalAlignment="Right"
Width="40" Height="40" Margin="0,6,6,0">
<Ellipse Stroke="{StaticResource PhoneForegroundBrush}"
StrokeThickness="3" />
<Image Source="Assets/AppBar/Play.png" />
</Grid>
<StackPanel VerticalAlignment="Bottom">
<TextBlock Text="{Binding Title}"
Margin="6,0,0,6"/>
</StackPanel>
</Grid>
</DataTemplate>
</phone:LongListSelector.ItemTemplate>
</phone:LongListSelector>
</phone:PanoramaItem>
<!--Panorama item three-->
<phone:PanoramaItem Header="Record">
<Grid>
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<MediaElement x:Name="AudioPlayer" AutoPlay="False" />
<StackPanel>
<ToggleButton Content="Record"
Checked="RecordAudioChecked"
Unchecked="RecordAudioUnchecked"/>
<Grid Width="200"
Height="200"
Name="ReelGrid"
RenderTransformOrigin=".5,.5">
<Grid.RenderTransform>
<CompositeTransform />
</Grid.RenderTransform>
<Ellipse Fill="{StaticResource PhoneAccentBrush}" />
<Ellipse Height="20"
Width="20"
Fill="{StaticResource PhoneForegroundBrush}" />
<Rectangle Height="20"
Width="20"
Margin="0,20,0,20"
VerticalAlignment="Top"
Fill="{StaticResource PhoneForegroundBrush}" />
<Rectangle Height="20"
Width="20"
Margin="0,20,0,20"
VerticalAlignment="Bottom"
Fill="{StaticResource PhoneForegroundBrush}" />
<Rectangle Height="20"
Width="20"
Margin="0,0,20,0"
HorizontalAlignment="Right"
Fill="{StaticResource PhoneForegroundBrush}" />
<Rectangle Height="20"
Width="20"
Margin="20,0,0,0"
HorizontalAlignment="Left"
Fill="{StaticResource PhoneForegroundBrush}" />
</Grid>
<Button Name="PlayAudio" Content="Play" Click="PlayAudioClick" />
</StackPanel>
</Grid>
</Grid>
</phone:PanoramaItem>
</phone:Panorama>
</Grid>
</phone:PhoneApplicationPage>
Cartoons.xaml.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using SoundBoard.Resources;
using Coding4Fun.Toolkit.Audio;
using Coding4Fun.Toolkit.Audio.Helpers;
using System.IO;
using System.IO.IsolatedStorage;
using Coding4Fun.Toolkit.Controls;
using SoundBoard.ViewModels;
using Newtonsoft.Json;
namespace SoundBoard
{
public partial class Cartoons : PhoneApplicationPage
{
private MicrophoneRecorder _recorder = new MicrophoneRecorder();
private IsolatedStorageFileStream _audioStream;
private string _tempFileName = "tempWav.wav";
public Cartoons()
{
InitializeComponent();
DataContext = App.ViewModel;
BuildLocalizedApplicationBar();
}
// Load data for the ViewModel Items
protected override void OnNavigatedTo(NavigationEventArgs e)
{
if (!App.ViewModel.IsDataLoaded)
{
App.ViewModel.LoadData();
}
}
private void LongListSelector_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
LongListSelector selector = sender as LongListSelector;
// verifying our sender is actually a LongListSelector
if (selector == null)
return;
SoundData data = selector.SelectedItem as SoundData;
// verifying our sender is actually SoundData
if (data == null)
return;
if (File.Exists(data.FilePath))
{
AudioPlayer.Source = new Uri(data.FilePath, UriKind.RelativeOrAbsolute);
}
else
{
using (var storageFolder = IsolatedStorageFile.GetUserStoreForApplication())
{
using (var stream = new IsolatedStorageFileStream(data.FilePath, FileMode.Open, storageFolder))
{
AudioPlayer.SetSource(stream);
}
}
}
selector.SelectedItem = null;
}
private void BuildLocalizedApplicationBar()
{
ApplicationBar = new ApplicationBar();
ApplicationBarIconButton recordAudioAppBar =
new ApplicationBarIconButton();
recordAudioAppBar.IconUri = new Uri("/Assets/AppBar/Save.png", UriKind.Relative);
recordAudioAppBar.Text = AppResources.AppBarSave;
recordAudioAppBar.Click += recordAudioAppBar_Click;
ApplicationBar.Buttons.Add(recordAudioAppBar);
ApplicationBar.IsVisible = false;
}
void recordAudioAppBar_Click(object sender, EventArgs e)
{
InputPrompt fileName = new InputPrompt();
fileName.Message = "What should we call the sound?";
fileName.Completed += FileNameCompleted;
fileName.Show();
}
private void FileNameCompleted(object sender, PopUpEventArgs<string, PopUpResult> e)
{
if (e.PopUpResult == PopUpResult.Ok)
{
// Create a sound data object
SoundData soundData = new SoundData();
soundData.FilePath = string.Format("/customAudio/{0}.wav", DateTime.Now.ToFileTime());
soundData.Title = e.Result;
// Save the wav file into the DIR /customAudio/
using (IsolatedStorageFile isoStore = IsolatedStorageFile.GetUserStoreForApplication()) {
if (!isoStore.DirectoryExists("/customAudio/"))
isoStore.CreateDirectory("/customAudio/");
isoStore.MoveFile(_tempFileName, soundData.FilePath);
}
// Add the SoundData to App.ViewModel.CustomSounds
App.ViewModel.CustomSounds.Items.Add(soundData);
// Save the list of CustomSounds to isolatedStorage.ApplicationSettings
var data = JsonConvert.SerializeObject(App.ViewModel.CustomSounds);
IsolatedStorageSettings.ApplicationSettings[SoundModel.CustomSoundKey] = data;
IsolatedStorageSettings.ApplicationSettings.Save();
// We'll need to modify sound model to retrieve CustomSounds
//from isolatedStorage.ApplicationSettings
NavigationService.Navigate(new Uri("", UriKind.RelativeOrAbsolute));
}
}
private void RecordAudioChecked(object sender, RoutedEventArgs e)
{
PlayAudio.IsEnabled = false;
ApplicationBar.IsVisible = false;
RotateCirlce.Begin();
_recorder.Start();
}
private void RecordAudioUnchecked(object sender, RoutedEventArgs e)
{
_recorder.Stop();
SaveTempAudio(_recorder.Buffer);
PlayAudio.IsEnabled = true;
ApplicationBar.IsVisible = true;
RotateCircle.Stop();
}
private void SaveTempAudio(MemoryStream buffer)
{
//defensive...
if (buffer == null)
throw new ArgumentNullException("Attempting a save on empty sound buffer.");
//Clean out hold on audioStream
if (_audioStream != null)
{
AudioPlayer.Stop();
AudioPlayer.Source = null;
_audioStream.Dispose();
}
var bytes = buffer.GetWavAsByteArray(_recorder.SampleRate);
using (IsolatedStorageFile isoStore = IsolatedStorageFile.GetUserStoreForApplication()) {
if (isoStore.FileExists(_tempFileName))
isoStore.DeleteFile(_tempFileName);
_tempFileName = string.Format("{0}.wav", DateTime.Now.ToFileTime());
_audioStream = isoStore.CreateFile(_tempFileName);
_audioStream.Write(bytes, 0, bytes.Length);
//Play ... SetSource of a mediaElement
AudioPlayer.SetSource(_audioStream);
}
}
private void PlayAudioClick(object sender, RoutedEventArgs e)
{
AudioPlayer.Play();
}
}
}
As I said it is probably something dumb but I am really stuck so would really appreciate any advice.
Thanks in advance.
It seems that all the problems reside in auto-generated files Cartoons.g.cs. The only error that points to non fully auto-generated file is this :
The name 'AudioPlayer' does not exist in the current context \SoundBoard\Cartoons.xaml.cs
Which complaining about AudioPlayer doesn't exists when it does exist, declared in Cartoons.xaml. So that's all weird errors.
First thing I will do is clean up (from visual studio, or manually delete bin and debug folders) and rebuild the project, and or even restart Visual Studio. Those steps can fix weird errors most of the time.
The problem is that both Cartoons.xaml and MainPage.xaml have the same line x:Class="SoundBoard.MainPage". I'm not sure but think that Cartoons.xaml should have different value for x:Class attribute

Problem with refreshing Data c#

My problem is first I'm downladin xml file from server like this:
private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
{
//pobieranie danych z pliku xml znajdujacego sie na serwerze
WebClient client = new WebClient();
client.DownloadStringCompleted += HttpsCompleted;
client.DownloadStringAsync(new Uri("Myurl/baza.xml"));
}
private void HttpsCompleted(object sender, DownloadStringCompletedEventArgs e)
{
if (e.Error == null)
{
XDocument xdoc3 = XDocument.Parse(e.Result, LoadOptions.None);
var data = from query in xdoc3.Descendants("Item")
select new Item
{
name = (string)query.Element("name"),
prise = (int)query.Element("prise"),
howmany = (int)query.Element("howmany")
};
items_listBox.ItemsSource = data;
status_textBlock.Text = "Data ok";
}
else {
status_textBlock.Text = "Fail";
kup_button.Visibility = 0;
}
Then i'v made a refresh button, and add function to it, basicly the same code:
private void button1_Click(object sendera, RoutedEventArgs a)
{
WebClient client2 = new WebClient();
client2.DownloadStringCompleted += HttpsCompleteda;
client2.DownloadStringAsync(new Uri(Myurl/baza.xml"));
}
private void HttpsCompleteda(object sendera, DownloadStringCompletedEventArgs a)
{
#region server_ok
if (a.Error == null
{
#region refresh
XDocument xdoca = XDocument.Parse(a.Result, LoadOptions.None);
var new_data = from query in xdoca.Descendants("Item")
select new Item
{
name = (string)query.Element("name"),
prise = (int)query.Element("prise"),
howmany = (int)query.Element("howmany")
};
items_listBox.ItemsSource = new_data;
}
After laod first xml, it (xml file) is chenged(i can see via my web browser) but when i refresh it looks steel the same in
items_listBox.ItemsSource
any ideas? thanks for help
xaml code
x:Class="Sklep.Page1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait" Orientation="Portrait"
mc:Ignorable="d" d:DesignHeight="768" d:DesignWidth="480"
shell:SystemTray.IsVisible="True" Loaded="PhoneApplicationPage_Loaded">
<!--LayoutRoot is the root grid where all page content is placed-->
<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="Sklep" Style="{StaticResource PhoneTextNormalStyle}"/>
<TextBlock x:Name="PageTitle" Text="Sklep" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}" Height="49" Width="456" FontSize="30" />
</StackPanel>
<!--ContentPanel - place additional content here-->
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<Button Content="zamow" Height="70" HorizontalAlignment="Left" Margin="-12,474,0,0" Name="kup_button" VerticalAlignment="Top" Width="480" Click="kup_button_Click" />
<TextBlock HorizontalAlignment="Left" Margin="230,550,0,74" Name="textBlock1" Text="Ilość sztuk" Width="190" />
<TextBox Height="57" HorizontalAlignment="Left" Margin="0,536,0,0" Name="order_textBox" Text="1" VerticalAlignment="Top" Width="224" TextAlignment="Right" FontSize="18" />
<CheckBox Content="zapłacone" Height="86" HorizontalAlignment="Left" Margin="171,568,0,0" Name="pay_box" VerticalAlignment="Top" Width="261" />
<ListBox x:Name="items_listBox" MinHeight="200" MinWidth="300" Margin="6,62,6,174" MaxHeight="500">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Margin="10" >
<TextBlock Text="{Binding name}"/>
<TextBlock Text="{Binding prise}"/>
<TextBlock Text="{Binding howmany}"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<TextBlock Height="53" HorizontalAlignment="Left" Margin="1,3,0,0" Name="status_textBlock" Text="" VerticalAlignment="Top" Width="449" TextAlignment="Center" />
<Button Content="Odswież" Height="103" HorizontalAlignment="Left" Margin="339,545,0,0" Name="button1" VerticalAlignment="Top" Width="114" FontSize="15" Click="button1_Click" />
</Grid>
</Grid>
The request will be cached by the WebClient.
The easiest solution is to make the request look like a different one by adding something unique to the query string.
client.DownloadStringAsync(new Uri("Myurl/baza.xml?rand=" + Guid.NewGuid()));
Your problem seems more to be a data binding problem than about a web service call. You should give your XAML code.
I've solved it using
static public WebClient public_webclient

Categories

Resources