Create Button in datagrid row silverlight - c#

I have the silverlight Datagrid like ,
I need to add one button in Every Row and If I click that button it will redirect to another page with particular row's Name Value.Because I need to show the Name value in the redirected Page.
Am new to Silverlight Application.Need your Guidance.

Chris is right there are lots of tutorials online however for anyone who gets to this site here is an example.
Your datagrid would look something like this
<sdk:DataGrid AutoGenerateColumns="False" Padding="15" Height="129" x:Name="dgSOF" Width="1021" ItemsSource="{Binding Path=TestListBinding}" RowHeight="30" BorderBrush="#FFE4E4E4">
<sdk:DataGrid.Columns>
<sdk:DataGridTextColumn Binding="{Binding Path=Something}" Header="Something"/>
<sdk:DataGridTemplateColumn>
<sdk:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Button Margin="5" Click="Button_Click" Width="100" Content="Click Me!"/>
</DataTemplate>
</sdk:DataGridTemplateColumn.CellTemplate>
</sdk:DataGridTemplateColumn>
</sdk:DataGrid.Columns>
</sdk:DataGrid>
And then the code behind would look something like this
private void Button_Click(object sender, RoutedEventArgs e)
{
string ClickedSomething = ((TestSL.TT)(((System.Windows.Controls.ContentPresenter)(VisualTreeHelper.GetParent(sender as Button))).DataContext)).Something;
SilverlightMessageBoxLibrary.CustomMessage cm = new SilverlightMessageBoxLibrary.CustomMessage("You clicked on " + ClickedSomething, SilverlightMessageBoxLibrary.CustomMessage.MessageType.Error);
cm.Show();
}
This should point you in the right direction

Related

UWPToolkit AdaptiveGridView unresponsive when clicked

Im trying to use the AdaptiveGridView as a main menu to navigate to other pages so I thought I'd test a click event on it, from my understanding of the sample repo that can be found below you can use a clicked event when click is enabled to do something depending on the item clicked:
https://github.com/Microsoft/UWPCommunityToolkit/tree/master/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/AdaptiveGridView
Seems straight forward but when I try trigger the click event in my own code nothing happens when a popup should appear.
C# Click Event:
private async void AGVC_ItemClick(object sender, Windows.UI.Xaml.Controls.ItemClickEventArgs e)
{
await new MessageDialog($"You clicked {(e.ClickedItem as AdaptItem).Title}", "Item Clicked").ShowAsync();
}
The grid in my XAML page:
<Controls:AdaptiveGridView Name="AGVC"
OneRowModeEnabled="False"
ItemHeight="200"
DesiredWidth="200"
SelectionMode="Single"
IsItemClickEnabled="True"
VerticalAlignment="Top"
ItemTemplate="{StaticResource MenuTemplate}" HorizontalAlignment="Left"/>
<StackPanel VerticalAlignment="Bottom" Margin="0,24,0,0" Grid.Row="1" Background="{ThemeResource SystemControlBackgroundAccentBrush}">
Item clicked was missing from the AdaptiveGridView
<Controls:AdaptiveGridView Name="AGVC"
OneRowModeEnabled="False"
ItemHeight="200"
DesiredWidth="200"
SelectionMode="Single"
IsItemClickEnabled="True"
VerticalAlignment="Top"
ItemClick="AGVC_ItemClick"
ItemTemplate="{StaticResource MenuTemplate}" HorizontalAlignment="Left" />

longlistselector header/footer click

I'm very new in WindowsPhone development and at this moment I'm facing a problem that I couldn't find a way to fix. I'm using a LongListSelector to show some information on the device screen and also a Header and a Footer with some static information. Everything looks right, but I can't handle the Click/Tap on the Header and on the Footer (the other items are working properly).
Someone know how to do it? Is there any event that tells my .cs that someone clicked on the footer or on the header view?
Thanks!
Implement ListFooter and ListHeader in your xaml.
Example :
<phone:LongListSelector x:Name="myLongListSelector"
Background="Transparent"
IsGroupingEnabled="True"
HideEmptyGroups="True">
<phone:LongListSelector.ListFooter>
<Grid Height="70" Tap="Grid_Tap">
<TextBlock Text="Texxt" Foreground="White"
VerticalAlignment="Center"
FontWeight="Bold"
FontSize="20"/>
</Grid>
</phone:LongListSelector.ListFooter>
</phone:LongListSelector>
Now in your cs file, you have :
private void Grid_Tap(object sender, System.Windows.Input.GestureEventArgs e)
{
}

Back button not working in XAML / W8

I have the following button on my page:
<AppBarButton Grid.Column="0" x:Name="backButton" Icon="Back" Margin="10,26,0,-1"
Command="{Binding NavigationHelper.GoBackCommand, ElementName=pageRoot}"
IsEnabled="True"
Visibility="Visible"
Foreground="Green"
AutomationProperties.Name="Back"
AutomationProperties.AutomationId="BackButton"
AutomationProperties.ItemType="Navigation Button" Grid.Row="1" Grid.RowSpan="2" VerticalAlignment="Stretch"
/>
The button appears but clicking it does nothing. This was placed on the second of two pages in the application. I followed the instructions in NavigatonHelper.cs to get it wired up to my second page, but haven't done anything special in the first. What am I missing?
I even tried tying the Click property to a custom function:
public void ClickGoBack(object sender, RoutedEventArgs routedEventArgs) {
this.Frame.Navigate(typeof(HubPage));
}
But this never even got hit when I clicked the button.
Have you checked the Click existed in AppBarButton defined?
like: <AppBarButton ... Click="ClickGoBack"></AppBarButton>
and you should use
if (this.Frame.CanGoBack)
{
this.Frame.GoBack();
}
instead of
this.Frame.Navigate(typeof(HubPage));
You could do this instead much more easier for me.
<AppBar><Button Style="{StaticResource BackButtonStyle}" Click="Click1"></Button>
</AppBar>
and for your code behind...
private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
{
Frame.GoBack();
}
Something was put after the top grid in the XAML that overlapped the button - I didn't understand the concept of "natural order" until now. Thanks for the help everyone!

Get previous page name

something that I thought would be simple is turning out not to be, or I'm just not thinking hard enough :)
I have a page which I navigate to, in the OnNavigateTo event I set the SelectedIndex of a ListPicker and that works fine.
If I then touch the ListPicker and select a new value the OnNavigateTo event is fired again and the new value is overridden by the original value.
My initial thought was to simply check the parent page name and if it was the ListPicker then skip the initial setting but I can't seem to find where to get the parent page name from.
Any clues? or a better way I should be handling this?
Here's the XAML:
<toolkit:ListPicker x:Name="Status" Margin="10,549,163,-97" Header="Status" FullModeHeader="Status" ExpansionMode="FullScreenOnly" BorderBrush="Black" Foreground="Black" Grid.ColumnSpan="2" Visibility="Visible">
<toolkit:ListPicker.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding}" />
</DataTemplate>
</toolkit:ListPicker.ItemTemplate>
<toolkit:ListPicker.FullModeItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding}"
FontSize="43"
FontFamily="{StaticResource PhoneFontFamilyLight}"/>
</DataTemplate>
</toolkit:ListPicker.FullModeItemTemplate>
</toolkit:ListPicker>
And here's the Loaded event:
private void AddNote_Loaded(object sender, RoutedEventArgs e)
{
this.TicketStatus.ItemsSource = ticketStatus();
string st;
if (NavigationContext.QueryString.TryGetValue("status", out st))
{
tStatus = st;
TicketStatus.SelectedIndex = GetStatus(tStatus);
}
}
Ok, worked around it but creating my own page list and manually adding and removing the pages I want to check for. Bit of a hack but it works :)

Double clicking on WPF datagrid WITH RowDetailsTemplate

I have searched and searched and found no answer.
I have a datagrid which utilizes the RowDetailsTemplate to display some higher-level information about that particular row. However, when the user double clicks on a row, I would like to display a separate form which displays much more detailed information.
How can I accomplish this?
I forgot to mention: On double click, I want to open the detail WITHOUT seeing the row details template! – Menashe 1 hour ago
Thanks!
Menashe
Just put this together and it seemed to work... I added a MouseDown handler to the grid in the RowDetailsTemplate:
<Grid>
<DataGrid x:Name="DataGrid1">
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding}" />
</DataGrid.Columns>
<DataGrid.RowDetailsTemplate>
<DataTemplate>
<Grid MouseDown="Grid_MouseDown" >
<TextBlock >This</TextBlock>
</Grid>
</DataTemplate>
</DataGrid.RowDetailsTemplate>
</DataGrid>
</Grid>
And the code behind:
private void Grid_MouseDown(object sender, MouseButtonEventArgs e)
{
if (e.ChangedButton == MouseButton.Left && e.ClickCount == 2)
{
//Open the window here
}
}

Categories

Resources