I'm trying to create a simple popup in windows 10 universal application. I've made a GridView
<GridView x:Name="PopUp" HorizontalAlignment="Left" Height="453" Margin="10,99,0,0" VerticalAlignment="Top" Width="340" Visibility="Collapsed">
<TextBox x:Name="Teacher" Height="29" TextWrapping="Wrap" Text="Teacher's name" Width="330"/>
<TextBox x:Name="Room" Height="29" TextWrapping="Wrap" Text="Room" Width="330"/>
<TextBox x:Name="Time" Height="29" TextWrapping="Wrap" Text="Time" Width="330"/>
<TextBox x:Name="Subject" Height="29" TextWrapping="Wrap" Text="Subject" Width="330"/>
<ComboBox x:Name="Day" HorizontalAlignment="Left" VerticalAlignment="Top" Width="330" />
<AppBarButton Icon="Cancel" Label="" Height="51" Margin="80,0,0,0"/>
<AppBarButton Icon="Accept" Label="" Height="48" Margin="-40,-70,0,0" BorderThickness="0"/>
</GridView>
I've got button "Add". I want my GridView become visible when User presses the add button, than he feels fields in GridView, presses "Ok" and GridView becomes invisible again. I used the buttonclick event, but it doesn't work:
private void AppBarButton_Click(object sender, RoutedEventArgs e)
{
Popup pop = new Popup();
pop.Visibility = Visibility.Visible;
}
Maybe there is another way to create a popup(or I don't know how it's called) menu, because I don't want to create separate page for adding data.
private void AppBarButton_Click(object sender, RoutedEventArgs e)
{
PopUp.Visibility = Visibility.Visible;
}
I hope This Help you let me know if its ok ;)
Related
Windows store app WInRT XAML C# - How to get navigated page textbox value.here is my all code...................................................
1.MainPage.xaml
<Button Content="Navigate" Name="nav" HorizontalAlignment="Left" Margin="826,198,0,0" VerticalAlignment="Top" Click="nav_Click"/>
<TextBlock HorizontalAlignment="Left" Margin="402,201,0,0" TextWrapping="Wrap" Text="TextBlock" VerticalAlignment="Top" Height="27" Width="155"/>
<Frame Name="framee" VerticalAlignment="Top" Height="440" HorizontalAlignment="Left" Width="600" Margin="402,238,0,0"/>
<Button Content="Get" Name="get" HorizontalAlignment="Left" Margin="1062,193,0,0" VerticalAlignment="Top" Click="get_Click"/>
2.InfoPage.xaml
<TextBox HorizontalAlignment="Left" TextWrapping="Wrap" Name="Name" VerticalAlignment="Top" Margin="0,6,0,0" Width="348"/>
<TextBox HorizontalAlignment="Left" TextWrapping="Wrap" Name="Address" VerticalAlignment="Top" Margin="0,43,0,0" Width="348"/>
<TextBox HorizontalAlignment="Left" TextWrapping="Wrap" Name="Phone" VerticalAlignment="Top" Margin="0,80,0,0" Width="348"/>
MainPage.cs
private void nav_Click(object sender, RoutedEventArgs e)
{
framee.Navigate(typeof(InfoPage));
}
private void get_Click(object sender, RoutedEventArgs e)
{
here textbox name are not showing
}
Simple enough question. Try this:
MainPage.xaml
<TextBox x:Name="MyTextBox" Text="Hello" />
<Button Click="Button_Click" />
MainPage.xaml.cs
void Button_Click(object sender, RoutedEventArgs e)
{
Frame.Navigate(typeof(InfoPage), MyTextBox.Text);
}
InfoPage.xaml
<TextBlock x:Name="MyTextBlock" />
InfoPage.xaml.cs
protected override void OnNavigatedTo(NavigationEventArgs e)
{
MyTextBlock.Text = e.Parameter?.ToString();
}
That will do it.
There are several ways to achieve what you're asking for. If you are using an MVVM pattern (which I personally highly recommend) then you simply need to bind the TextBox.Text to a field in the ViewModel and do the same to the same ViewModel in the MainPage... (and this could be discussed deeper so let me know if this is what you're doing.) If you're not using the MVVM pattern then you probably have no idea what I'm talking about so let's look at other options.
Another possible solution is to Interface the new pages requiring them all to have the same interface that in turns exposes the TextBox.Text property or a TextBox with the same name or however you decide. This is a big deeper as it may rely on other internal features such as Dependency Injection and or Controllers depending on how you're setup.
If you still have no idea what I'm talking about then I'm going to assume you're semi new at all of this and suggest you simply look for the TextBox via different approaches. It would be much easier to answer the question directly if you provided the full code and XAML for both pages at least.
I have a silverlight app with two textboxes. When I focus on one of them, I want my popup with my "virtual" keyboard to show up (works). But, the problem is when I want to close the popup. I want to be able to close it with my "X" button (red color on the screen). How can I do it? I tried everything - delegates, INotifyProperyChanged. Nothing seems to work. In my XAML code you can see that I'm not able to access any of the buttons from MainPage - only from the code of the Custom Control. Here's the problem.
<Grid x:Name="LayoutRoot" Background="#DB1E1E1E" Margin="0,0,-89,-114">
<TextBox x:Name="txt1"
HorizontalAlignment="Left" Height="23"
Margin="10,10,0,0" TextWrapping="Wrap"
Text="TextBox" VerticalAlignment="Top"
Width="398" GotFocus="txt1_GotFocus"/>
<TextBox
HorizontalAlignment="Left"
Height="23"
Margin="10,82,0,0"
TextWrapping="Wrap"
Text="TextBox"
VerticalAlignment="Top"
Width="398"/>
<Popup x:Name="popup" IsOpen="True" AllowDrop="True">
<Grid x:Name="theBack" Background="Black" Margin="80,196,114,24">
<Keyboard:KeyboardControl x:Name="keyboard" Margin="0,-10,0,10"/>
</Grid>
</Popup>
<Button x:Name="btn"
Content="Button"
HorizontalAlignment="Left"
Margin="508,114,0,0"
VerticalAlignment="Top"
Width="75"
Click="btn_Click"/>
</Grid>
Without Bindings:
In KeyboardControl.xaml.cs define a custom handler for your control and a method for the click on the close button:
public event RoutedEventHandler CloseClick;
private void ButtonX_Click(object sender, RoutedEventArgs e)
{
if (CloseClick != null)
CloseClick(sender, e);
}
Then in KeyboardControl.xaml assign the "Click" event of the "X" button with the method previously created
<Button Content="X" Click="ButtonX_Click"/>
Then in your MainPage change the layout of KeyboardControl for this:
Finally in MainPage.xaml.cs:
private void keyboard_CloseClick(object sender, RoutedEventArgs e)
{
popup.IsOpen = false;
}
I want to hide all Stackpanels when a button is clicked programatically, how can I accomplish this?
<Window>
<Grid>
<Button x:Name="btn1" Click="toggle_stackpanels" />
<StackPanel HorizontalAlignment="Left" Height="505" Margin="705,0,0,0" VerticalAlignment="Top" Width="55" Background="#FFD82727"/>
<StackPanel HorizontalAlignment="Left" Height="505" Margin="655,0,0,0" VerticalAlignment="Top" Width="50" Background="#FF6DEA49"/>
<StackPanel HorizontalAlignment="Left" Height="505" Margin="600,0,0,0" VerticalAlignment="Top" Width="55" Background="#FF1F92BD"/>
</Grid>
</Window>
public void toggle_stackpanels(object sender, RoutedEventArgs e)
{
//Hide All Stackpanels
}
I want to open popup by clicking on button in gridView element, inside popup I have three options by clicking on that option I want to navigate to another page with the id of the element
i want to open popup on click on button inside the gridView element my code looks like :-
<GridView x:Name="Test" Grid.Row="1" Margin="20,20,20,20" >
<GridView.ItemTemplate>
<DataTemplate>
<Grid HorizontalAlignment="Left" Width="250" Height="250">
<Button Background="Red" HorizontalAlignment="Left" VerticalAlignment="Top" Height="100" Content="OpenPopup" Click="Button_PointerPressed"></Button>
<Popup x:Name="Mypopup">
<TextBlock Text="hi"/>
</Popup>
<StackPanel VerticalAlignment="Bottom" Background="{ThemeResource ListViewItemOverlayBackgroundThemeBrush}">
<TextBlock Text="{Binding Title}" Foreground="{ThemeResource ListViewItemOverlayForegroundThemeBrush}" Style="{StaticResource TitleTextBlockStyle}" Height="60" Margin="15,0,15,0"/>
<TextBlock Text="{Binding Subtitle}" Foreground="{ThemeResource ListViewItemOverlaySecondaryForegroundThemeBrush}" Style="{StaticResource CaptionTextBlockStyle}" TextWrapping="NoWrap" Margin="15,0,15,10"/>
</StackPanel>
</Grid>
</DataTemplate>
</GridView.ItemTemplate>
</GridView>
on click event
private void Button_PointerPressed(object sender, RoutedEventArgs e)
{
Mypopup.isopen = true;
}
Error:-The name 'Mypopup' does not exist in the current context
I am a newbie.. so help me
All you have to do is on the Onclick event of your gridview's button do the following code :
popup.isopen = true
Then in your popup if you want to navigate to another page all you have to do is use Navigate on the proper event
Frame.Navigate(typeof(YourPage),YourID);
EDIT : If the buttons in your gridview are added through code and you want to do the event on those then make sure that they have different names such as : GrdButton1/GrdButton2 and then give them an event dynamicly
If they are added in the XAML then simply add it an event there
<Button x:Name="ButtonTest"
Click="ButtonTest_Click"/>
If none of this answers your question please add more details to it
I have four RadioButtons in a grid panel, but when I do this:
<GroupBox x:Name="radioButtons">
<RadioButton Content="1" Height="16" HorizontalAlignment="Left" Margin="10,45,0,0" Name="status1" VerticalAlignment="Top" />
<RadioButton Content="2" Height="16" HorizontalAlignment="Left" Margin="10,67,0,0" Name="status2" VerticalAlignment="Top" />
<RadioButton Content="3" Height="16" HorizontalAlignment="Left" Margin="10,89,0,0" Name="status3" VerticalAlignment="Top" />
<RadioButton Content="4" Height="16" HorizontalAlignment="Left" Margin="10,111,0,0" Name="status4" VerticalAlignment="Top" />
</GroupBox>
It says that:
Error 1 The object 'GroupBox' already has a child and cannot add 'RadioButton'. 'GroupBox' can accept only one child.
And the last three RadioButtons say:
The property 'Content' is set more than once.
What's wrong with my GroupBox? Furthermore, in my code I want to access the RadioButton that is checked (preferably as an int). How do I do this? I tried to look in Google and I found a lot of results, but I couldn't understand any of them.
GroupBox can only hold 1 item, hence the error about trying to set the Content property of the GroupBox multiple times.
So, make that a Layout item and then put the RadioButtons inside it. Now, you set the Content once, which is the StackPanel, and that Layout item can hold many children -> RadioButtons.
<GroupBox x:Name="radioButtons">
<StackPanel>
<RadioButton Name="status1"
Height="16"
Margin="10,45,0,0"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Content="1" />
<RadioButton Name="status2"
Height="16"
Margin="10,67,0,0"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Content="2" />
<RadioButton Name="status3"
Height="16"
Margin="10,89,0,0"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Content="3" />
<RadioButton Name="status4"
Height="16"
Margin="10,111,0,0"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Content="4" />
</StackPanel>
</GroupBox>
As for your second question, Christian Mosers WPF Tutorial.net has a decent sample. If you don't understand it, you maybe should look at the topics Binding and Converter, first.
A very crude way to be notified of RadioButton checked in a non MVVM way:
private void RadioButtonChecked(object sender, RoutedEventArgs e) {
var radioButton = sender as RadioButton;
if (radioButton == null)
return;
int intIndex = Convert.ToInt32(radioButton.Content.ToString());
MessageBox.Show(intIndex.ToString(CultureInfo.InvariantCulture));
}
Then, in each of your RadioButtons in xaml, add Checked="RadioButtonChecked".
If you want many elements or controls then you have to put them in layout containers.
Grid
StackPanel
DockPanel
WrapPanel
Etc.....