i'm getting the documentlibrary folders. but i don't know how to display the geeting folders in a MainPage.Xaml (design page).
here is my code:
var folders = await KnownFolders.DocumentsLibrary.GetFoldersAsync();
if anyone guide me. Thanks in advance.
Let's assume you've a ListView to show all the folders. And on click of a button, you want to show list of folders in DocumentsLibrary. For this, use following XAML:
<Button Content="Button" HorizontalAlignment="Left" Margin="216,172,0,0" VerticalAlignment="Top" Click="Button_Click_1"/>
<ListView x:Name="FolderList" HorizontalAlignment="Left" Height="100" Margin="216,328,0,0" VerticalAlignment="Top" Width="830">
<ListView.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding DisplayName}"></TextBlock>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
Now, in code behind write following code:
private async void Button_Click_1(object sender, RoutedEventArgs e)
{
var folders = await Windows.Storage.KnownFolders.DocumentsLibrary.GetFoldersAsync();
var data = folders.ToList<Windows.Storage.StorageFolder>();
FolderList.ItemsSource = data;
}
This will show you all the folders within the DocumentsLibrary in ListView.
Hope, it helps.
You need to use a ListView or GridView or ListBox in XAML (depending on what you want to do with it) and bind it to the folders list. Then you need an ItemTemplate to specify what you want displayed e.g. folder name, path, size etc
Related
I have the following XAML markup:
<ListView x:Name="wordsListView">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<ViewCell.View>
<StackLayout>
<Label Text="{Binding Keyword}" />
<Button Text="Click Me" x:Name="randomButton"></Button>
</StackLayout>
</ViewCell.View>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
And in my .xaml.cs file I have the button clicked event for the random button defined as below:
randomButton.Clicked += (object sender, EventArgs e) =>
{
a = rand.Next(words.Count);
word = words[a];
};
But somehow when I build my project I kept getting an error: The name randomButton does not exists in the current context. Can anyone tell me what I'm doing wrong and how it should be done?
You can't access any control by name or even give it a name as long as it is on template view , naming it is not appropriate as long as this control on template will be repeated on run time!
but you can access the whole control from the Sender of the click event ... and this depends on your development approach
Hope it will help others.
There is nothing wrong with your code.You can try these 2 ways:
First, save xaml file and use this.randomButton. Try if it works.
Else Clean the solution and try again. If that didn't work, restart the Visual Studio.
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)
{
}
The following code is not working:
private void fileNameLinkButton_Click(object sender, RoutedEventArgs e)
{
HyperlinkButton clickedLink = (HyperlinkButton)sender;
string uri = String.Format(
"/IsolatedStorageListing;component/SecondPage.xaml?id={0}",
clickedLink.Content);
NavigationService.Navigate(new Uri(uri, UriKind.Relative));
}
<ListBox Height="183"
Width="460"
HorizontalAlignment="Right"
VerticalAlignment="Top"
Name="fileListBox">
<ListBox.ItemTemplate>
<DataTemplate>
<HyperlinkButton Name="fileNameLinkButton"
Content="{Binding}"
Click="fileNameLinkButton_Click" />
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
When I click the HyperlinkButton, my app closes/exit. Please help!
I doubt that you need to add /IsolatedStorageListing;component in the navigation Uri. Try to remove it and simply leave /SecondPage.xaml?id={0}
By the way, it is really strange and moreover wrong to use Content for navigation parameter. I would suggest you to use Tag property for such purposes.
I have a list box and i have to display a tick mark on the item selected.I tried this code
List Box
<ListBox Height="691" HorizontalAlignment="Left" Name="listBox1" Margin="-12,71,0,0" VerticalAlignment="Top" Width="480" SelectionChanged="listBox1_SelectionChanged">
<ListBox.ItemTemplate>
<DataTemplate>
<Border BorderThickness="0,1,0,0" BorderBrush="#FFC1BCBC" Width="490">
<Grid Height="70">
<TextBlock
Name="clients"
Margin="10,12,0,0"
Text="{Binding Name}" FontSize="24" FontWeight="SemiBold" Foreground="Black"></TextBlock>
<Image Height="30" Width="30"
HorizontalAlignment="Left"
Name="imageTick"
Stretch="Fill"
VerticalAlignment="Center"
Source="{Binding strAccountSelectedTickPath}"
Margin="380,0,0,0" Visibility="Collapsed"/>
</Grid>
</Border>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
xaml.cs
private void listBox1_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
string clientId="";
if (listBox_1.SelectedIndex >= 0)
{
(Application.Current as App).obj_subnodes = newlist[listBox1.SelectedIndex];
if ((Application.Current as App).obj_subnodes.strAccountSelectedTickPath==""||(Application.Current as App).obj_subnodes.strAccountSelectedTickPath==null)
{
if ( (Application.Current as App).obj_subnodes.strAccountSelectedTickPath = "")
{
(Application.Current as App).obj_subnodes.strAccountSelectedTickPath = "/sprinklr;component/Images/IsSelected.png";}
else{ (Application.Current as App).obj_subnodes.strAccountSelectedTickPath = ""; }
initializeListBox();
}
NavigationService.Navigate(new Uri("/Home.xaml, UriKind.Relative));
}
}
private void initializeListBox()
{
listBox1.ItemsSource = "";
listBox1.ItemsSource = newlist;
}
but the problem is suppose ifi have two items in list box say item1 and item2 and at first time i selected item1 and the tick mark displayed on item1 and after that i selected item 2 and the tick marlk displayed on item2 .but the tick mark on item1 doesnot gone.I have to display one tick mark to indicate the selected item,that is i want the tick image to display on the item i clicked.Is there any solution for this.and is there any option to get controll access for the tick image inside the list box.if there is an option i can use imagetick.visibility=visibility.collapsed.but i dont find such an option.is there any solution for this please help me
The best way to achieve this is to change the style / template of the ListBoxItem so that when it is in the 'selected' state, a tick image is displayed.
You need to create a Style that sets the Template for ListBoxItem, adding your tick image within each item. For details of how to do this, see the following blog post. You can apply this style to your ListBox by setting the ItemContainerStyle.
To turn the tick mark on / off based on selection, you will need to add a VisualState to your ListBoxItem Template, which is described in this blog post.
Download the latest Silverlight Toolkit for Windows Phone (or install it via NuGet) and use the MultiselectList instead of a regular ListBox. The MultiselectList supports checkboxes designed to match the functionality of the mail client.
I am having an issue with my button event not occuring
Basically I have cart items that are listed in the listbox. When the delete button is clicked then the item is deleted from the list box.
I tried debugging, but it seems to not even call the method for when the button is clicked.
In my ticketscreen.xaml file I specify my button in the template:
<DataTemplate x:Key="TicketTemplate">
<StackPanel Orientation="Horizontal" HorizontalAlignment="Left" Height="50">
...
<Button Name="Remove" Width="35" Height="35"
FontFamily="Resources/#charlemagnestd-regular.otf" FontSize="24"
Click="removeCartItem" Grid.Column="5"
MouseMove="Remove_MouseMove">X</Button>
...
</StackPanel>
</DataTemplate>
My List box is the following:
<ListBox Name="TicketItems" ItemsSource="{Binding}"
ItemTemplate="{StaticResource TicketTemplate}"
Grid.Row="3" Grid.ColumnSpan="6" Background="Transparent"
BorderBrush="Transparent" IsHitTestVisible="False">
</ListBox>
My method removeCartItem is in the ticketscreen.xaml.cs:
private void removeCartItem(object sender, RoutedEventArgs e)
{
Console.WriteLine("TestingCartRemove");
}
Am I missing something obvious?
Thx in adv! :)
Edit:
There seems to be something infront of it... maybe the listbox? How do I make it so that I am not clicking the ListBox, but I can click on things within the Stackpanel, which are contents of the list box.
IsHitTestVisible="False" for the ListBox is disabling the click event for the Button. It makes all content within the ListBox invisible to hit-test as well.
Are you sure is not firing? Maybe you haven't seen the output in Visual Studio Output Window. Try to call a MessageBox.Show("Test"); instead.
You have a listbox control, which leads me to believe that this is not a console application. Therefore, Console.WriteLine() will not show you anything. Try MessageBox.Show() instead.