Answered by:
Link a Grid with a text block or a text box

Question
-
Hi,
I am a beginner and i have no idea how to link a grid to a text box or a text block ( as in when i click on the text block the specified grid should appear visible) how to make this happen? if there a easy way with less coding i would be greatful since i am a beginner
regards
Sumedha
Thursday, December 19, 2013 6:11 AM
Answers
-
Hi,
Try below code.
<Window x:Class="GridVisible_Learning.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="350" Width="525"> <Grid> <Grid> <StackPanel> <TextBlock> <Hyperlink Click="Hyperlink_Click">Visible Grid</Hyperlink> </TextBlock> <Grid Name="dgr" Visibility="Collapsed"> <Button>test</Button> </Grid> </StackPanel> </Grid> </Grid> </Window>
public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); } private void Hyperlink_Click(object sender, RoutedEventArgs e) { dgr.Visibility = Visibility.Visible; } }
- Proposed as answer by AyyappanSubramanian Thursday, December 19, 2013 8:46 AM
- Marked as answer by Summa666 Thursday, December 19, 2013 9:46 AM
Thursday, December 19, 2013 7:32 AM
All replies
-
Hi Sumedha,
Please refer the below code.
<Window x:Class="GridVisible_Learning.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="350" Width="525"> <Grid> <StackPanel> <TextBlock> <Hyperlink Click="Hyperlink_Click">Visible Grid</Hyperlink> </TextBlock> <DataGrid Name="dgr" Visibility="Collapsed"></DataGrid> </StackPanel> </Grid> </Window>
In the code behind.
private void Hyperlink_Click(object sender, RoutedEventArgs e) { dgr.Visibility = Visibility.Visible; }
Hope it helpsThursday, December 19, 2013 6:46 AM -
Hi Sumedha,
Please refer the below code.
<Window x:Class="GridVisible_Learning.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="350" Width="525"> <Grid> <StackPanel> <TextBlock> <Hyperlink Click="Hyperlink_Click">Visible Grid</Hyperlink> </TextBlock> <DataGrid Name="dgr" Visibility="Collapsed"></DataGrid> </StackPanel> </Grid> </Window>
In the code behind.
private void Hyperlink_Click(object sender, RoutedEventArgs e) { dgr.Visibility = Visibility.Visible; }
Hope it helps
Hi
thanks for the help
but if i am going to add the objects into the appearing grid where should i start coding? ( i have tried your code and i have added a button inside the data grid function(as shown below) but after when i click on the hyperlink the button doesn't appear
<DataGrid x:Name="dgr" Visibility="Visible" Height="304.04"> <Grid> <Button x:Name="button" Content="Hi" Width="50" Height="50"/> </Grid> </DataGrid>
Regards
Sumedha
Thursday, December 19, 2013 7:14 AM -
Hi,
Try below code.
<Window x:Class="GridVisible_Learning.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="350" Width="525"> <Grid> <Grid> <StackPanel> <TextBlock> <Hyperlink Click="Hyperlink_Click">Visible Grid</Hyperlink> </TextBlock> <Grid Name="dgr" Visibility="Collapsed"> <Button>test</Button> </Grid> </StackPanel> </Grid> </Grid> </Window>
public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); } private void Hyperlink_Click(object sender, RoutedEventArgs e) { dgr.Visibility = Visibility.Visible; } }
- Proposed as answer by AyyappanSubramanian Thursday, December 19, 2013 8:46 AM
- Marked as answer by Summa666 Thursday, December 19, 2013 9:46 AM
Thursday, December 19, 2013 7:32 AM -
Hi
Thanks and i appriciate if you can help me in my other matter regarding the tabs
http://social.msdn.microsoft.com/Forums/windowsazure/en-US/9ac5cfc7-ac11-4130-b1e0-6062647db173/help-with-the-tab-item?forum=wpf
thanks again
Sumedha
Thursday, December 19, 2013 7:48 AM -
Hi,
Try below code.
<Window x:Class="GridVisible_Learning.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="350" Width="525"> <Grid> <Grid> <StackPanel> <TextBlock> <Hyperlink Click="Hyperlink_Click">Visible Grid</Hyperlink> </TextBlock> <Grid Name="dgr" Visibility="Collapsed"> <Button>test</Button> </Grid> </StackPanel> </Grid> </Grid> </Window>
public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); } private void Hyperlink_Click(object sender, RoutedEventArgs e) { dgr.Visibility = Visibility.Visible; } }
Monday, December 23, 2013 9:28 AM -
Please help meMonday, December 23, 2013 9:28 AM
-
Hi,
In another hyperlink event. Add the belwo code
dgr.Visibility = Visibility.Collapsed;
Monday, December 23, 2013 10:04 AM -
what can i do with another hyperlink click event?Monday, December 23, 2013 10:26 AM
-
Hi,
I am trying to imderstand your issue. Please explain the complete scenario.
In 1st textblock click you want to make the grid visible and then 2nd Textblock click do you want to hide it again. Is my understanding correct?
Monday, December 23, 2013 10:33 AM -
well yea.. mainly this is the idea i have like three text blocks and i have coded as you have helped and i have hyperlinked three grids to the three text blocks accordingly and when i click on the 1st TB the respective grid appears and when i click on the 2nd TB the attached grid is appearing but the first grid and the data set is still there, where the 2nd TB comes on top of the 1st.. when i click on the 3rd TB it also comes on top now all are on top of eachother.
What can i do in such a position?
Monday, December 23, 2013 10:48 AM