I have created a text box which when focused brings up a popup box with other text box's as options.. and when pressed closes the popup box.. but I'd like that to then take the value from whichever text box I have selected and add into the original text box. Is this possible? I'm new to wpf so forgive me!
Here is my code so far.
<Grid>
<StackPanel Margin="0,51,0,-51">
<TextBox x:Name="text" GotKeyboardFocus="text_GotKeyboardFocus" Margin="158,0,169,0" Height="24" Text="Select Your Time..." />
<Popup x:Name="popup" Width="282" Height="300" PlacementTarget="{Binding ElementName=text}">
<Grid>
<StackPanel>
<TextBox x:Name="text2" Background="White" Margin="10" GotKeyboardFocus="text_GotKeyboardFocus2" Cursor="Arrow" Height="24" Text="1 second" />
<TextBox x:Name="text3" Background="White" Margin="10" GotKeyboardFocus="text_GotKeyboardFocus2" Cursor="Arrow" Height="24" Text="2 second" />
<TextBox x:Name="text4" Background="White" Margin="10" GotKeyboardFocus="text_GotKeyboardFocus2" Cursor="Arrow" Height="24" Text="3 second" />
<TextBox x:Name="text5" Background="White" Margin="10" GotKeyboardFocus="text_GotKeyboardFocus2" Cursor="Arrow" Height="24" Text="4 second" />
<TextBox x:Name="text6" Background="White" Margin="10" GotKeyboardFocus="text_GotKeyboardFocus2" Cursor="Arrow" Height="24" Text="5 second" />
</StackPanel>
</Grid>
</Popup>
</StackPanel>
</Grid>
private void text_GotKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e)
{
popup.IsOpen = true;
}
private void text_GotKeyboardFocus2(object sender, RoutedEventArgs e)
{
popup.IsOpen = false;
}
Get value from one textbox to another in xaml:
<TextBox Name="txtBox1"/>
<TextBox Name="txtBox2" Text="{Binding ElementName=txtBox1, Path=Text,UpdateSourceTrigger=PropertyChanged}" />
I hope I got your point.
Just add text.Text = (sender as TextBox).Text; to your second event handler as follows :
private void text_GotKeyboardFocus2(object sender, RoutedEventArgs e)
{
popup.IsOpen = false;
text.Text = (sender as TextBox).Text;
}
Good luck.
Get value from one textbox to another XAML
<TextBox Name="txtBox1"/>
<TextBox Name="txtBox2" Text="{Binding ElementName=txtBox1, Path=Text,UpdateSourceTrigger=PropertyChanged}" />
Related
i want to send Data from one Textbox on window One to a label on window Two.
starting with window two:
<StackPanel>
<StackPanel x:Name="ButtonStackPanel" Height="Auto" Width="Auto">
<StackPanel Orientation="Horizontal">
<StackPanel Orientation="Vertical">
<Button Style="{DynamicResource ButtonStyle}" Content="To The Dark Side" Click="OnClickToDarkSide"/>
<Button Style="{DynamicResource ButtonStyle}" Content="To The Gray" Click="OnClickToGraySide"/>
<Button Style="{DynamicResource ButtonStyle}" Content="To The Light Side" Click="OnClickToLightSide"/>
</StackPanel>
<Border HorizontalAlignment="Center" VerticalAlignment="Stretch" Background="Red" Height="Auto" Width="2"/>
<Label Style="{DynamicResource LabelStyle}" x:Name="theTextBlock" Content="{Binding Source=CodeText}"/>
<Border HorizontalAlignment="Center" VerticalAlignment="Stretch" Background="Red" Height="Auto" Width="2"/>
<ToggleButton Style="{DynamicResource ToggleButtonStyle}" Content="Open Style Window" Name="StyleWindowButton" Click="OnClickOpenStyleWindow"/>
<ToggleButton Style="{DynamicResource ToggleButtonStyle}" Content="Open Text Window" Name="TextWindowButton" Click="OnClickOpenTextWindow"/>
</StackPanel>
<Border Height="2" Width="Auto" Background="Red" HorizontalAlignment="Stretch" VerticalAlignment="Center"/>
</StackPanel>
<Border Height="2" Width="Auto" Background="Red" HorizontalAlignment="Stretch" VerticalAlignment="Center"/>
</StackPanel>
Codebehind of Window Two:
public MainWindow()
{
(App.Current as App).CodeText = _jediCode;
InitializeComponent();
}
private void OnClickToDarkSide(object sender, RoutedEventArgs e)
{
(App.Current as App).ChangeSkin(Skin.Dark);
(App.Current as App).CodeText = _sithCode;
theTextBlock.Content = (App.Current as App).CodeText;
}
private void OnClickToLightSide(object sender, RoutedEventArgs e)
{
(App.Current as App).ChangeSkin(Skin.Light);
(App.Current as App).CodeText = _jediCode;
theTextBlock.Content = (App.Current as App).CodeText;
}
private void OnClickToGraySide(object sender, RoutedEventArgs e)
{
(App.Current as App).ChangeSkin(Skin.Gray);
(App.Current as App).CodeText = _grayCode;
theTextBlock.Content = (App.Current as App).CodeText;
}
private void OnClickOpenStyleWindow(object sender, RoutedEventArgs e)
{
if (StyleWindowButton.IsChecked == true)
{
styleWindow = new StyleWindow();
styleWindow.Show();
}
else
{
styleWindow.Close();
styleWindow = null;
}
}
private void OnClickOpenTextWindow(object sender, RoutedEventArgs e)
{
if (TextWindowButton.IsChecked == true)
{
textWindow = new InputWindow();
textWindow.Show();
}
else
{
textWindow.Close();
textWindow = null;
}
}
}
window one:
<Grid>
<TextBox HorizontalAlignment="Left" VerticalAlignment="Top" Height="200" Width="200" TextWrapping="Wrap"
AcceptsReturn="True" AcceptsTab="True" Text="{Binding Path=CodeText, Source={x:Static Application.Current}, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" Margin="10,10,0,0">
<!-- TODO: trigger change from this textbox to the textblock in mainwindow -->
</TextBox>
</Grid>
code behind of one is empty.
app.xaml.cs:
public string CodeText
{
get => _codeText;
set { _codeText = value; OnPropertyChanged(nameof(CodeText)); }
}
Ok, the current behavior is clicking on one of the buttons (Dark Side, Gray, Light Side) leads to changes in the CodeText Property, which leads to a change of the content of the label of Window Two and the text of TextBox of Window One. Changing the text of the TextBox, changes also the CodeText Property, but does not lead to a change in the label and thats confusing, why does it work the one way, but not the other.
hope you have a hint for me. :) Maybe i missed a trigger or a kind of refresh for the label
bindings in window One and Two are set differently. (window Two does it wrong, Content="{Binding Source=CodeText}" is not valid binding)
in fact, window Two removes the binding by assigning CodeText directly as local value:
theTextBlock.Content = (App.Current as App).CodeText;
you should remove that line, and use the same binding as in window One:
<Label Style="{DynamicResource LabelStyle}" x:Name="theTextBlock"
Content="{Binding Path=CodeText, Source={x:Static Application.Current}}"/>
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.
I have 4 radiobuttons and I want to check if any are checked.
This is my WPF code:
<StackPanel Background="#FF3A3A49" Grid.Column="1" Grid.Row="4">
<RadioButton x:Name="rtnRight" GroupName="answer" HorizontalAlignment="Center" VerticalAlignment="Top" Foreground="White" Content="value0" BorderBrush="White"/>
<RadioButton Content="value1" GroupName="answer" HorizontalAlignment="Center" VerticalAlignment="Center" Foreground="White" />
<RadioButton Content="value2" GroupName="answer" HorizontalAlignment="Center" VerticalAlignment="Bottom" Foreground="White" />
<RadioButton Content="value3" GroupName="answer" HorizontalAlignment="Center" VerticalAlignment="Bottom" Foreground="White" />
</StackPanel>
<Button x:Name="btnNext" Grid.Column="1" Grid.Row="5" Content="Dalej" VerticalAlignment="Center" HorizontalAlignment="Center" Width="100" Height="50" Margin="0 0 0 0 " Foreground="#FFAC0303" BorderBrush="#FFC1C1C1" Background="#66FFFFFF" Click="btnNext_Click"></Button>
After I click btnNext and no radiobuttons have been checked, I want to show a message dialog. How can I code this? This is my btnNext_Click function so far.
private async void btnNext_Click(object sender, RoutedEventArgs e)
{
if ("any radiobutton checked?")
{
await new Windows.UI.Popups.MessageDialog("Choose at least one answer").ShowAsync();
}
}
You can specify a name for your StackPanel and then check like:
if (!(radioButtonStackPanel.Children.OfType<RadioButton>().Any(rb => rb.IsChecked == true)))
Just remember to specify a name for StackPanel like:
<StackPanel Background="#FF3A3A49" Grid.Column="1" Grid.Row="4" x:Name="radioButtonStackPanel">
I want to make border and textblock disappear when i click the button and the border and textblock appear when i click the button again.
This is my xaml:
<Border x:Name="descbox" Background="#A6CFC9A8" Height="80" VerticalAlignment="Bottom" Visibility="Visible" Margin="0,-100,0,0">
<ScrollViewer VerticalScrollMode="Auto" Height="auto" Margin="0,0,0.333,0" HorizontalScrollBarVisibility="Visible">
<StackPanel Width="548">
<TextBlock x:Name="desc" Text="{Binding Description}" FontFamily="verdana" FontSize="19" Foreground="#CC000000" TextWrapping="Wrap" Padding="0,10" TextAlignment="Justify" Margin="0,0,10.333,0"/>
</StackPanel>
</ScrollViewer>
</Border>
<Button Content="Button"/>
How to make it in windows phone 8.1?
XAML :
<Button Content="Button" Click="Button_Click"/>
Code :
private void Button_Click(object sender, RoutedEventArgs e)
{
if (descbox.Visibility == Visibility.Visible)
descbox.Visibility = Visibility.Collapsed;
else
descbox.Visibility = Visibility.Visible;
}
I have a form in my windows phone 7 app which contains a few textboxes and a radiobutton. I want to reset the value of the textboxes and radio button on clicking the reset button. I am able to clear the textboxes but donot Know how to clear the value of the radio button. Please help:
My form is:
<TextBox GotFocus="OnGotFocus" Canvas.Left="6" Canvas.Top="6" Height="74" Name="name" Text="*Name" Width="453" BorderThickness="0"/>
<TextBox GotFocus="OnGotFocus1" Canvas.Left="6" Canvas.Top="66" Height="74" Name="age" Text="*Age" Width="453" BorderThickness="0" />
<TextBlock Canvas.Left="20" Canvas.Top="157" Height="44" Name="gen" Text="Gender" Foreground="Black" FontFamily="Verdana" FontSize="24" Width="134" />
<RadioButton Canvas.Left="139" Canvas.Top="157" FontStyle="Italic" Foreground="Black" Content="Male" Height="71" Name="male" Width="154" />
<RadioButton Canvas.Left="139" Canvas.Top="207" FontStyle="Italic" Foreground="Black" Content="Female" Height="71" Name="fem" Width="140" />
<TextBox GotFocus="OnGotFocus2" Canvas.Left="6" Canvas.Top="267" Height="74" Name="sadd" Text="*Street Address" Width="453" BorderThickness="0"/>
<TextBox GotFocus="OnGotFocus3" Canvas.Left="6" Canvas.Top="327" Height="74" Name="cadd" Text="*City Address" Width="453" BorderThickness="0"/>
<TextBox GotFocus="OnGotFocus4" Canvas.Left="6" Canvas.Top="387" Height="74" Name="eadd" Text="*Email Address" Width="453" BorderThickness="0"/>
<TextBox GotFocus="OnGotFocus5" Canvas.Left="6" Canvas.Top="447" Height="74" Name="phn" Text="*Phone" Width="453" BorderThickness="0"/>
<TextBox GotFocus="OnGotFocus6" Canvas.Left="6" Canvas.Top="507" Height="74" Name="zip" Text="*Zip Code" Width="453" BorderThickness="0"/>
My code for resetting on clicking the reset button is:
private void reset_Click(object sender, RoutedEventArgs e)
{
name.Text = "";
age.Text = "";
sadd.Text = "";
cadd.Text = "";
eadd.Text = "";
phn.Text = "";
zip.Text = "";
}
Please add the code that i should add here to reset the radio button
Now on clicking submit button if i want to check that whether male or female has been selected or not, how can i do that. For text box i am doing the following code:
private void submit_Click(object sender, RoutedEventArgs e)
{
if (name.Text == "")
{
MessageBox.Show("Please Enter the name");
name.Focus();
}
}
There is a property named content which is equivalent to a textbox text property
And this is how you are gonna set it
male.IsChecked=false;
male.Content=String.Empty;
And regarding the edits.
assign a common groupname property to both the radiobuttons. ie
<RadioButton Canvas.Left="139" Canvas.Top="157" FontStyle="Italic" GroupName="Gender" Foreground="Black" Content="Male" Height="71" Name="male" Width="154" />
<RadioButton Canvas.Left="139" Canvas.Top="207" FontStyle="Italic" GroupName="Gender" Foreground="Black" Content="Female" Height="71" Name="fem" Width="140" />
This makes either of the two selected everytime in xaml.
Now getting the value of a radiobutton in code should be like.
if(male.IsChecked==true)
{
string gender=male.Content.ToString();
}
else if(female.isChecked==true)
{
string gender=female.Content.ToString();
}
else //none of them is selected.
{
MessageBox.Show("Text");
}