I am using Windows Phone 8.1 and I am wondering how do I pass Binded values across pages? I have already binded the data to my ListView as shown below. And also, how do I retrieve the values from the page.
E.g. when I click the "Name" I would go to the EnterAmount and pass all the 5 Binded Data to it.
Is my method of doing correct? Or is there a simpler way of accomplishing this.
And also, may know how do I concatinate first_name and last_name into a single row?
I want it displayed like
First Name + Last Name
Item Name
Much appreciated
SelectItem.xaml
<ListView Name="ItemList"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Margin="40,300,0,0"
Height="200"
Width="320"
IsItemClickEnabled="True"
ItemClick="ItemList_ItemClick">
<ListView.ItemTemplate>
<DataTemplate>
<StackPanel Grid.Column="1">
<TextBlock Width="200"
FontSize="20"
Foreground="#FFFF7B2C"
Text="{Binding item_id}"
Visibility="Collapsed"/>
<TextBlock Width="200"
FontSize="20"
Foreground="#FFFF7B2C"
Text="{Binding first_name}" />
<TextBlock Width="200"
FontSize="20"
Foreground="#FFFF7B2C"
Text="{Binding last_name}" />
<TextBlock Width="200"
FontSize="20"
Foreground="#FFFF7B2C"
Text="{Binding item_name}" />
<TextBlock Width="200"
FontSize="20"
Foreground="#FFFF7B2C"
Text="{Binding progress}"
Visibility="Collapsed"/>
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
SelectItem.xaml.cs
private void ItemList_ItemClick(object sender, ItemClickEventArgs e)
{
//this.Frame.Navigate(typeof(EnterAmount), e.ClickedItem);
}
Related
I have a datagrid which on click will show a textbox for user input. I am able to display the details on the textbox. Now I have a Update button inside the datatemplate. Once i click on the update button I want the user input taken and do processing.
This is my xaml code:
<DataGrid.RowDetailsTemplate>
<DataTemplate>
<Border BorderThickness="0" Background="BlanchedAlmond" Padding="10">
<StackPanel Orientation="Vertical">
<StackPanel Orientation="Horizontal">
<TextBlock FontSize="12" Text="First Name: " VerticalAlignment="Center" />
<TextBox x:Name="txtFirstName" FontSize="16" Foreground="MidnightBlue" Text="{Binding UserFirstName}" VerticalAlignment="Center" />
</StackPanel>
<StackPanel Orientation="Horizontal">
<TextBlock FontSize="12" Text="Last Name: " VerticalAlignment="Center" />
<TextBox x:Name="txtLastName" FontSize="16" Foreground="MidnightBlue" Text="{Binding UserLastName}" VerticalAlignment="Center" />
</StackPanel>
<StackPanel>
<Button x:Name="btnUpdate" Content="Update" VerticalAlignment="Center" HorizontalAlignment="Right" Click="btnUpdate_Click"/>
</StackPanel>
</StackPanel>
</Border>
</DataTemplate>
</DataGrid.RowDetailsTemplate>
This is my .cs code:
void btnUpdate_Click(object sender, RoutedEventArgs e)
{
string firstName;
firstName = txtFirstName.Text;
}
The txtFirstName.Text is showing Does Not Exist In The Current Context
Because it's inside the datatemplate you may have to do something like https://code.msdn.microsoft.com/windowsapps/How-to-access-a-control-6039571a
Or use the binding that you already have, just make the mode TwoWay.
{Binding UserFirstName, Mode=TwoWay}
I have a single Grid that contains a ListView. The ListView is populated with 2 records of employees. How can I detect if focus is lost. E.g the empty space below records or another part of the window is clicked. The record should then be deselected.
<Grid HorizontalAlignment="Left" Height="128" Margin="10,39,0,0" VerticalAlignment="Top" Width="267" LostFocus="Grid_LostFocus">
<ListView Margin="0" Name="listviewEmps" MouseDoubleClick="listviewEmps_MouseDoubleClick" SelectionChanged="listviewEmps_SelectionChanged">
<ListView.ItemTemplate>
<DataTemplate>
<WrapPanel>
<TextBlock Text="Name: " />
<TextBlock Text="{Binding Name}" FontWeight="Bold" />
<TextBlock Text=", " />
<TextBlock Text="dob: " />
<TextBlock Text="{Binding DOB , StringFormat={}{0:d}}" />
</WrapPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</Grid>
I'm working on a project in which I'm setting content using JSON Binding in Grid view but now I want to get Text of item when it is selected. XAML CODE:
<GridView ItemsSource="{Binding}" HorizontalAlignment="Center" Margin="0,10,0,0" x:Name="dataList" VerticalAlignment="Center" SelectionMode="None" SelectionChanged="dataList_Selection">
<GridView.ItemTemplate>
<DataTemplate>
<StackPanel Width="450" Height="300">
<Image Source="{Binding Top}" Margin="0,0,0,0" Stretch="None" />
<TextBlock x:Name="title" Text="{Binding Title}" Foreground="Black" HorizontalAlignment="Center" FontFamily="Assets/Font/MixBrush.ttf#MixBrush" FontWeight="Bold" FontSize="50" Margin="0,10,0,0" />
<Image Source="{Binding Bottom}" Margin="0,0,0,0" Stretch="None" />
<TextBlock Text="{Binding first}" Foreground="Black" HorizontalAlignment="Center" FontFamily="Assets/Font/Comfortaa_Regular.ttf#Comfortaa" FontSize="20" Margin="0,50,0,0" />
<TextBlock Text="{Binding second}" Foreground="Black" HorizontalAlignment="Center" FontFamily="Assets/Font/Comfortaa_Regular.ttf#Comfortaa" FontSize="20" Margin="0,0,0,0" />
<TextBlock Text="{Binding third}" Foreground="Black" HorizontalAlignment="Center" FontFamily="Assets/Font/Comfortaa_Regular.ttf#Comfortaa" FontSize="20" Margin="0,0,0,0" />
</StackPanel>
</DataTemplate>
</GridView.ItemTemplate>
</GridView>
Here I want to get Text of "title" programmatically. Please share your knowledge with me. :-)
********************** Thank You ************************
On your back code use:
title.Text;
After long hard struggle I found my answer.
var selection = (myClass) dataList.SelectedItem;
await new MessageDialog(selection.Title).ShowAsync();
And I got perfect result.
Thank You.
I have this XAML code:
<ListView Name="ListBoxWithNews" ItemsSource="{Binding News}" Grid.Row="1" Grid.Column="1" Grid.RowSpan="2" Grid.ColumnSpan="2">
<ListView.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Image Source="{Binding imageURL}" Width="75" Height="75" />
<StackPanel>
<TextBox Text="{Binding Title}" Width="200" />
<TextBox Text="{Binding Body}" Width="200" />
</StackPanel>
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
The controls are binded using the MVVM pattern. The user can change the content of the two text boxes. Is there a possible way to get the updated text from these text boxes at some point when I need them?
Your ViewModel should implement INotifyPropertyChanged and Use TwoWay Binding as below
<ListView Name="ListBoxWithNews" ItemsSource="{Binding News,Mode=TwoWay}" Grid.Row="1" Grid.Column="1" Grid.RowSpan="2" Grid.ColumnSpan="2">
<ListView.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Image Source="{Binding imageURL,Mode=TwoWay}" Width="75" Height="75" />
<StackPanel>
<TextBox Text="{Binding Title,Mode=TwoWay}" Width="200" />
<TextBox Text="{Binding Body,Mode=TwoWay}" Width="200" />
</StackPanel>
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
I'm trying to figure out how to use UpdateSourceTrigger=Explicit.
I've got following form:
<StackPanel x:Name="LayoutRoot" Margin="10" DataContext="{Binding ElementName=Window, Mode=OneWay}">
<DockPanel>
<TextBlock Text="Proxy address:" VerticalAlignment="Center"/>
<TextBox Text="{Binding User.PageAddress, Mode=TwoWay, UpdateSourceTrigger=Explicit}" Margin="28,0,0,0"/>
</DockPanel>
<DockPanel Margin="0,5,0,0">
<TextBlock Text="User name:" VerticalAlignment="Center"/>
<TextBox Text="{Binding User.UserName, Mode=TwoWay, UpdateSourceTrigger=Explicit}" Margin="46,0,0,0"/>
</DockPanel>
<DockPanel Margin="0,5,0,0">
<TextBlock Text="User password:" VerticalAlignment="Center"/>
<TextBox Text="{Binding User.Password, Mode=TwoWay, UpdateSourceTrigger=Explicit}" Margin="26,0,0,0"/>
</DockPanel>
<StackPanel Orientation="Horizontal" VerticalAlignment="Center" HorizontalAlignment="Right" Margin="0,5,0,0">
<Button Content="Ok" IsDefault="True" Width="70" Margin="0,0,15,0" Click="Ok_Click"/>
<Button Content="Cancel" IsCancel="True" Width="70"/>
</StackPanel>
</StackPanel>
what method should I call to update User property?
I don't want to address the elements by x:Name to invoke the binding. If I have to address the elements by x:Name, I as well can go without binding altogether, as far as I'm concerned.
You need to call BindingExpression.UpdateSource in the code behind to manually update the binding. Explicit binding isn't really compatible with MVVM since you need to directly reference the view objects to perform the manually update.
// itemNameTextBox is an instance of a TextBox
BindingExpression be = itemNameTextBox.GetBindingExpression(TextBox.TextProperty);
be.UpdateSource();