How to show particular textblock on button click in WPF? - c#

i am working on an application using C# WPF and MVVM.The problem i want to show summary on button click event in textblocks and textblocks are inside ListBox as follows:
<ListBox>
<TextBlock
TextWrapping="Wrap"
Height="350"
Text="{Binding ShowVlan}"
</TextBlock>
<TextBlock
TextWrapping="Wrap"
Height="350"
Text="{Binding ShowRouting}">
</TextBlock>
</ListBox>
I have two buttons and i want that if i click 1st button then 1st textblock should be display and on second button click i want to display second textblock .It is working now but the actual problem is that i want to display to on same positions but these are displaying one after another .I am also attaching screenshot for better understanding.

You could simply put both TextBlock at the same Grid Cell and set their Visibility to true/False based on the selected Button :
<TextBlock x:Name="ShowVlanTb" Visibility="Hidden"
TextWrapping="Wrap"
Height="350"
Text="{Binding ShowVlan}" Grid.Row=1 Grid.Colomn=2
/>
<TextBlock x:Name="ShowRoutingTb" Visibility="Hidden"
TextWrapping="Wrap"
Height="350"
Text="{Binding ShowRouting}" Grid.Row=1 Grid.Colomn=2>
/>
and on the button Click event handler set the Visiblity to Visible:
ShowVlanTb.Visibility=Visibility.Visible
ShowRoutingTb.Visibility=Visibility.Hidden

Related

UWP: UserControl override GridView item click

I have a UserControl inside of each GridView item. It's like below.
<GridView Name="SymbolItemsGridView"
Grid.Column="0"
Background="#333333"
SelectionMode="None"
IsItemClickEnabled="True"
ItemsSource="{x:Bind Items}"
HorizontalAlignment="Stretch"
Margin="15,5,10,15"
ItemClick="SymbolGridView_ItemClick">
<GridView.ItemTemplate>
<DataTemplate x:DataType="data:SymbolItem">
<local:SymbolControl Margin="10"/>
</DataTemplate>
</GridView.ItemTemplate>
</GridView>
The SymbolControl above is a UserControl, I changed its ContentPresenter style to round
<ContentPresenter CornerRadius="40"
Height="40"
Width="40"
Background="Cyan"
x:Name="ContentPresenter"
Content="{TemplateBinding Content}"
Padding="0" />
So the only one button inside this UserControl is of round shape.
<Button Name="SymbolButton"
Content="{x:Bind PhoneticSymbolItem.Text}"
Style="{StaticResource VowelSymbolButton}" />
My question is that the ItemClick="SymbolGridView_ItemClick" event handler only works when I click the corner of the GridView Item (the black part above). If I click the round button, it doesn't work.
I know it's probably because the button is on top of the GridView item and clicking the button only triggers the button click event. But the media resource I want to set is in ItemsSource="{x:Bind Items}" of the GridView. I don't know how to pass it to my UserControl and used by the button click event.
Or if there's a way to pop up the button click event to GridView item, it should work as well. I hope my question is clear, any ideas?
Try IsHitTestVisible="False" to your round SymbolControl .

How to open Popup by clicking on grid view item in windows store app?

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

How can get the value of Radio Button Inside Listbox Click on Button in Windows Phone Using C#

I have Radio Group of Three Radio Button and a submit button also
inside of ListBox. I want to get the selected Radio Button Value from
the Radio Group on Button Click. Below my listbox item view. please
help me.
<ListBox x:Name="OptionListView" SelectionChanged="OptionListView_SelectionChanged" Height="720" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="0,0,0,0">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Background="#99000000" Width="480" Margin="0,10,0,0">
<StackPanel Margin="10">
<TextBlock Text="{Binding FeaturedQuestion}" TextWrapping="Wrap" />
<RadioButton Content="Yes" GroupName="OpinionPoll" Foreground="White"/>
<RadioButton Content="No" GroupName="OpinionPoll" Foreground="White"/>
<RadioButton Content="Not Decide" GroupName="OpinionPoll" Foreground="White"/>
<Button x:Name="btnSubmit" Click="btnSubmit_Click" Background="#d44740" Content="Submit" Style="{StaticResource TileButtonTemplate}" Height="65" VerticalAlignment="Top" HorizontalAlignment="Left" Width="200" Foreground="White"/>
</StackPanel>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
When you work with a listbox you need to have a List of something like a object.
This object represent your 3 radio button. For exemple you can work with an enum for get the checked value or create a custom radio button with 3 states.
Steps:
- understand how to use and bind control inside listbox
understand how to get the checked value (Exemple => IsChecked="{Binding IsSelected, Mode=TwoWay}"/>)
You could simply access the properties, by binding the ListBox's selected item.
Reference: how do I access a radiobutton inside a ListBoxItem in windows phone 7

DataGrid Cell with text and button

In a cell of a DataGrid there is a "add" button and then a textblock show quantity. When the user clicks on the "add" button it adds one to the quantity. I am having a hard time figuring out how to create the textblock. Here is my cell;
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Button Content="+" Click="addQTYButton_Click"/>
<TextBlock Text="{Binding qty}"/>
</StackPanel>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
The best solution would be not to use the Click event and the code-behind.
Use a command instead and in your ViewModel change the string the TextBlock is bound to when the command is invoked...
If you insist using the event and the code-behind, just name the TextBlock and it will be available to you in the event handler to manipulate it any way you like...

Listpicker with button in full mode in WP7

I put one button in listpicker full mode template. I want when this button is pressed. It Just invoke my defined event. Not act as normal tap on listpicker And closes the full mode of listpicker.
Please see screenshot below.
To include the button in the listPicker full mode, you have to define the data template as such. Go through the listPicker given here
<DataTemplate x:Name="PickerFullModeItemTemplate">
<StackPanel Orientation="Horizontal" Margin="16 21 0 20">
<Button Click="event">
<Button.Content>
<StackPanel>
<Image Source="myImg.png"/>
<TextBlock Text="test"/>
</StackPanel>
</Button.Content>
</Button>
</StackPanel>
</DataTemplate>
For the behavior you require. Try and test by handling event function on click event in the button. I guess it should work. If not then you have to use popUp instead of listPicker. Or you would have to define your own UserControl in the worst case.

Categories