List<Items> list = new List<Items>();
list = (from query in doc.Descendants("row")
select new Items
{
Id = Convert.ToInt64(query.Element("Id").Value),
Name = query.Element("Name").Value,
title = query.Element("title").Value
}).ToList();
listPicker1.DataContext = list;
Is it possible to show by default "Select" in windows phone list picker and whenever I select list picker item, the item should be display.
Here is the code I have so far:
<toolkit:ListPicker ItemsSource="{Binding}" x:Name="listPicker1" FullModeHeader="Employee" SelectionChanged="ListPicker1_SelectionChanged" BorderThickness="0" Margin="130,-45,144,160" SelectedItem="{Binding}" SelectionMode="Single" ExpansionMode="FullScreenOnly" Header="" CacheMode="BitmapCache" Height="55" Background="White">
<toolkit:ListPicker.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Name}" TextWrapping="Wrap" FontSize="22" Width="200" Height="50" VerticalAlignment="Center" TextAlignment="Center" HorizontalAlignment="Center" Foreground="Blue"/>
</StackPanel>
</DataTemplate>
</toolkit:ListPicker.ItemTemplate>
<toolkit:ListPicker.FullModeItemTemplate>
<DataTemplate>
<StackPanel Orientation="Vertical">
<TextBlock Text="{Binding Name}" Margin="10" FontSize="24" TextWrapping="Wrap" Foreground="Black" Width="440"/>
<TextBlock Text="{Binding title}" FontSize="20" TextWrapping="Wrap" Foreground="Black" Width="440"/>
</StackPanel>
</DataTemplate>
</toolkit:ListPicker.FullModeItemTemplate>
</toolkit:ListPicker>
To make this add a item named "select" and set it as default.
Related
I am developing a Windows store app. At a high level, the page has a Grid with two rows. Along with other controls, the ComboBox is placed in the first row.
The second row has a GridView and the red tile is one of the items in the GridView. The ComboBox is used to display hierarchical data as shown here.
ComboBox
I am working on replacing the ComboBox with a TreeView from WinRT XAML Toolkit as shown here.
TreeView
What I like about the Combobox is that when its open, the opened list sits on top of the GridView. For the Treeview, when I open the parent node, the opened list stays within the specified height along with the scrollbar.
I would like the TreeView to act like the ComboBox so that when opened, it extends out and the opened list sits on top of the GridView. Any idea how I can accomplish that?
Thanks for your help.
Set something like this on the TreeView (adjust max dimensions for available space)
VerticalAlignment="Top"
HorizontalAlignment="Left"
MaxHeight="500"
MaxWidth="500"
Canvas.ZIndex="1"
This will make the ScrollViewer and the TreeView change the size depending on the size of expanded tree up to a max size where it will start scrolling. The ZIndex will make it render on top of items with lower or default ZIndex value at the same level in the visual tree.
You could also put it in a Popup when your root node expands and back out of the Popup when the Popup closes or when the node collapses.
*EDIT
Based on your code - I can see you have a bit of a mess of a lot of nested panels, but with a simple hack you can make it work even with your layout. There are three things to do:
Make the TreeView top-aligned as I mentioned earlier.
The height of the panel the TreeView is inside of is a bit limited (to 20% of page height) by the size of the Grid row it's in. You can add a bit more space by setting a large enough negative bottom Margin value for the TreeView.
Since the TreeView is in the first row of the grid - the second row naturally overlays it when the TreeView extends into the negative margin. You can fix that by setting Canvas.ZIndex="1" on the StackPanel that is the root of your first row or reordering your row elements to reverse the ZIndex.
Here's the updated code:
<Page
x:Class="TestApp.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:TestApp"
xmlns:custom="using:TestApp.Custom"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:controls="using:WinRTXamlToolkit.Controls"
xmlns:data="using:WinRTXamlToolkit.Controls.Data"
mc:Ignorable="d">
<Page.Resources>
<Style x:Key="HorizontalScrollViewerStyle" TargetType="ScrollViewer">
<Setter Property="HorizontalScrollBarVisibility" Value="Auto"/>
<Setter Property="VerticalScrollBarVisibility" Value="Disabled"/>
<Setter Property="ScrollViewer.HorizontalScrollMode" Value="Enabled" />
<Setter Property="ScrollViewer.VerticalScrollMode" Value="Disabled" />
<Setter Property="ScrollViewer.ZoomMode" Value="Disabled" />
</Style>
</Page.Resources>
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid.RowDefinitions>
<RowDefinition Height="2*"></RowDefinition>
<RowDefinition Height="7*"></RowDefinition>
<RowDefinition Height="1*"></RowDefinition>
</Grid.RowDefinitions>
<StackPanel Grid.Row="0" Margin="0,10,0,0"
Canvas.ZIndex="1">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<StackPanel Grid.Column="0" HorizontalAlignment="Left" Margin="50,0,0,0">
<StackPanel>
<TextBlock Text="Version 1.0.0.0"/>
<!--<ProgressBar IsIndeterminate="True" Visibility="{Binding ShowProgressBar, Converter={StaticResource BooleanToVisibility}}" Height="20"/>-->
</StackPanel>
<StackPanel Orientation="Horizontal">
<Image Source="/Assets/SmallLogo.scale-100.png" Width="130" Height="60" Stretch="Uniform"/>
<TextBlock Text="Testing TreeView" FontSize="20" FontWeight="Light" VerticalAlignment="Center" Margin="10"/>
</StackPanel>
</StackPanel>
<StackPanel Grid.Column="1" HorizontalAlignment="Right" VerticalAlignment="Top" Margin="10">
<Grid>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<Grid Grid.Row="0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="6*"/>
<ColumnDefinition Width="4*"/>
</Grid.ColumnDefinitions>
<StackPanel Grid.Column="0" Orientation="Horizontal">
<TextBlock Text="Test ID: 1234" Margin="0,0,5,0" FontWeight="SemiBold" VerticalAlignment="Center"/>
</StackPanel>
</Grid>
<StackPanel Grid.Row="1" Orientation="Horizontal">
<TextBlock Text ="Test Data 123"/>
<TextBlock Text ="More Test Data 123"/>
</StackPanel>
<!--<ComboBox Grid.Row="2"
ItemsSource="{Binding Locations}"
SelectedItem="{Binding SelectedLocation, Mode=TwoWay}"
Width="400" Margin="0,5,0,0" />-->
<controls:TreeView Grid.Row="2" ItemsSource="{Binding TLocations}"
VerticalAlignment="Top"
Width="400" Margin="0,5,0,-1000" MaxHeight="400">
<controls:TreeView.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Header}"/>
<data:DataTemplateExtensions.Hierarchy>
<data:HierarchicalDataTemplate ItemsSource="{Binding Items}" />
</data:DataTemplateExtensions.Hierarchy>
</DataTemplate>
</controls:TreeView.ItemTemplate>
</controls:TreeView>
</Grid>
</StackPanel>
</Grid>
</StackPanel>
<Grid Grid.Row="1" Margin="0,10,0,0">
<!--<Grid.Background>
<ImageBrush ImageSource="/Assets/Background.png" />
</Grid.Background>-->
<ScrollViewer Style="{StaticResource HorizontalScrollViewerStyle}">
<StackPanel Orientation="Horizontal" >
<StackPanel Margin="50,0,0,0">
<TextBlock Text="Overview" Margin="0,20,0,0" />
<Grid Width="450" Height="450" HorizontalAlignment="Left" VerticalAlignment="Top">
<Grid.RowDefinitions>
<RowDefinition Height="5*" />
<RowDefinition Height="2*" />
<RowDefinition Height="3*" />
</Grid.RowDefinitions>
<Image Grid.Row="0" Source="Assets/StoreLogo.scale-100.png" Stretch="UniformToFill"/>
<StackPanel Grid.Row="1" Background="Azure">
</StackPanel>
<StackPanel Grid.Row="2" Background="Orange">
</StackPanel>
</Grid>
</StackPanel>
<StackPanel Margin="50,20,0,0">
<TextBlock Text="Test Content" Margin="2,0,0,0"/>
<custom:CustomGridView ItemsSource="{Binding Items}" SelectionMode="None">
<GridView.ItemsPanel>
<ItemsPanelTemplate>
<VariableSizedWrapGrid Orientation="Horizontal" ItemHeight="150" ItemWidth="175" MaximumRowsOrColumns="3" />
</ItemsPanelTemplate>
</GridView.ItemsPanel>
<GridView.ItemTemplate>
<DataTemplate>
<Grid Background="{Binding BackgroundColor}">
<Grid.RowDefinitions>
<RowDefinition Height="{Binding TitleHeight}"/>
<RowDefinition Height="{Binding ImageHeight}" />
<RowDefinition Height="{Binding ContentHeight}" />
</Grid.RowDefinitions>
<StackPanel Grid.Row="0" VerticalAlignment="Top">
<TextBlock Text="{Binding Title}" HorizontalAlignment="Left" Padding="5,0,0,0"></TextBlock>
</StackPanel>
<StackPanel Grid.Row="1">
<Image Source="{Binding ImageSource}" Stretch="None" VerticalAlignment="Center" />
</StackPanel>
<StackPanel Grid.Row="2" VerticalAlignment="Bottom" Background="{Binding ContentBackgroundColor}">
<TextBlock Text="{Binding Content}" HorizontalAlignment="Center" VerticalAlignment="Center" Padding="5"></TextBlock>
</StackPanel>
</Grid>
</DataTemplate>
</GridView.ItemTemplate>
</custom:CustomGridView>
</StackPanel>
<!--<userControls:EarnBenefits x:Name="earnBenefits"/>-->
</StackPanel>
</ScrollViewer>
</Grid>
</Grid>
</Page>
Here's a screenshot:
I've also noticed you are targeting Windows 8.1 at least with your test app, but you are using an old Windows 8.0 version (1.6.1.3) of the toolkit. You can get the latest version (1.8.1 as of 2015-02-01) here: http://www.nuget.org/packages/winrtxamltoolkit.windows
I need to change the StackPanel background color for the item selected by user.
Apprecaite your help.
here my XAML:
<DataTemplate x:Key="SpeechTemplate">
<StackPanel x:Name="Sp" Width="400" Height="120" Background="Red">
<TextBlock Text="{Binding Title}"
Grid.Column="0"
Margin="3,3,0,0"
TextWrapping="Wrap"
VerticalAlignment="Top"
FontSize="24"
FontWeight="SemiBold"/>
<TextBlock Text="{Binding SId}"
Grid.Column="1"
Margin="3,3,0,0"
TextWrapping="Wrap"
VerticalAlignment="Top"
FontSize="18"/>
<TextBlock Text="{Binding TopicId}"
Grid.Column="2"
Margin="3,3,0,0"
TextWrapping="Wrap"
VerticalAlignment="Top"
FontSize="18"/>
</StackPanel>
</DataTemplate>
<ListView x:Name="SpeechesGridView" Width="420"
Foreground="White"
SelectionMode="None"
IsSwipeEnabled="True"
IsItemClickEnabled="True"
ItemsSource="{Binding Mode=OneWay, Source={StaticResource SpeechesViewSource}}"
ItemTemplate="{StaticResource SpeechTemplate}"
ItemClick="SpeechesGridView_ItemClick"
SelectionChanged="SpeechesGridView_SelectionChanged"/>
Override/add <SolidColorBrush x:Key="ListViewItemSelectedBackgroundThemeBrush" Color="#YourColor" /> to your Application.Resources. You'll find all default colours in the generic.xaml file here: C:\Program Files (x86)\Windows Kits\8.1\Include\winrt\xaml\design (Assuming you work with x64).
I have two Pages used for printing.
1) PagePrinting.xaml
2) FormattedPage.xaml
in PagePrinting.xaml , I used the code below to reference the FormattedPage.xaml
FrameworkElement page1;
page1 = new FormattedPage();
CanvasPrintContainer.Children.Add(page1);
The problem:
The txtBlkDatePrint is blank when it is shown in PagePrinting.xaml
What I need to do?
in CodeBehind of FormattedPage.xaml :
protected override void OnNavigatedTo(NavigationEventArgs e)
{
txtBlkDatePrint.Text = DateTime.Today.ToString("d");
}
FormattedPage.xaml:
< StackPanel x:Name="header" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="10,10,0,0" Grid.Row="0" Height="60">
<StackPanel Orientation="Horizontal" >
<RichTextBlock Foreground="Black" FontSize="20" TextAlignment="Left" FontFamily="Segoe UI">
<Paragraph>
<TextBlock x:Name="txtBlkDatePrint" Margin="10,10,0,0" HorizontalAlignment="Left" TextWrapping="Wrap" FontSize="28" Text="" VerticalAlignment="Top" Height="39" Width="204"/>
</Paragraph>
</RichTextBlock>
</StackPanel>
</StackPanel>
So, Paragraph takes in a collection of Blocks as Content, of which TextBlock ironically is not. Try instead using a Run.
<StackPanel x:Name="header" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="10,10,0,0" Grid.Row="0" Height="60">
<StackPanel Orientation="Horizontal" >
<RichTextBlock Foreground="Black" FontSize="20" TextAlignment="Left" FontFamily="Segoe UI">
<Paragraph>
<Run x:Name="txtBlkDatePrint" TextWrapping="Wrap" FontSize="28" Text=""/>
</Paragraph>
</RichTextBlock>
</StackPanel>
</StackPanel>
Though, if you just want to display simple text, you may not need the RichTextBlock at all.
I have a Movie class with a Dim _characters = New ObservableCollection(of String)
In my MainWindow.vb i have,
Dim movies = New ObservableCollection(of Movie)
Me.parentG.DataContext = Me.movies
i want to add characters to the movie based on button click at runtime.
How can i get the particaular movie for which the character button was clicked?
MainWindow.xaml:-
<Grid Name="parentG" >
<ItemsControl ItemsSource="{Binding}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100"></ColumnDefinition>
<ColumnDefinition Width="100"></ColumnDefinition>
<ColumnDefinition Width="700"></ColumnDefinition>
</Grid.ColumnDefinitions>
<TextBox Grid.Column="0" Text="{Binding MovieName}" />
<Button Grid.Column="1" Content="New Character" Click="newCharacterButton_Click" Height="20" Width="100" HorizontalAlignment="Left" />
<ListBox Grid.Column="2" Name="cList" ItemsSource="{Binding Characters}">
<ListBox.ItemTemplate >
<DataTemplate >
<TextBox Text="{Binding Name}"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Grid>
finally figured it out. Below are the steps :-
in the button handler, convert sender to Button
get its parent, in my case it was the Grid
Get the DataContext of the Grid, convert it to (in this case), Movie
Get index of this Movie in the Movie array, assuming an index property existed for each Movie, and was set during initialization.
Add a character to this movie
I have the following XAML code:
<DataTemplate x:Key="NewsDataTemplate">
<StackPanel Width="400" Height="100" Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center" >
<TextBlock x:Name="NewsText" Text="{Binding Text}" Margin="8,4" TextWrapping="Wrap" Width="384" Style="{StaticResource PhoneTextGroupHeaderStyle}" />
</StackPanel>
</DataTemplate>
I want to NewsText TextBlock can be as height as it needs but also I want to set a minimum height:
NewsText will have 100 or higher height.
How can I do that?
Try the MinHeight property...
FrameworkElement.MinHeight Property