I successfully added a listbox with databinding in my xaml:
But i forgot which attribute to use for the items header. My items contain to Textboxes "name", "money earned" and if i add items my items say for example "Mustermann", "300" but i need a headertemplate above the items which says "name" and "money earned" how do i add such a header for the items?
The xaml I already wrote isn't relevant for this question but if you are interested:
<ListBox x:Name="WorkersList" ItemsSource="{Binding}" MaxWidth="480" MaxHeight="400" VerticalAlignment="Top" HorizontalAlignment="Left">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding name}" HorizontalAlignment="Center" Width="100"></TextBlock>
<TextBlock Text="{Binding gehalt}" HorizontalAlignment="Center" Width="100"></TextBlock>
<ToggleSwitch></ToggleSwitch>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
You could use a ListView with a GridView. In each GridViewColumn, there is a property called Header.
EDIT:
You could use a ListView. Apparently there is a ListView.Header property in W10 apps. Have a look at this. Something like the following could work:
<ListView>
<ListView.Header>
<StackPanel>
<TextBlock Text="Name"/>
<TextBlock Text="Money earned"/>
</StackPanel>
</ListView.Header>
</ListView>
First of all,ListBox doesn't support Header
I'm not sure if i understand your question correctly, but If you mean you wanna have something like Table (have a header and data in it) I suggest you to use some useful classes like MyToolkit (DataGrid)
Helpful question in Stackoverflow
Related
I'm trying to use a SplitView whose Buttons come from data binding. Here is the code:
<SplitView Name="AnnouncementSplitView"
DisplayMode="CompactInline"
OpenPaneLength="200"
CompactPaneLength="56"
HorizontalAlignment="Left" Grid.Row="1">
<ListView ItemsSource="{x:Bind Parts}"
SelectionMode="Single"
Name="CongregationList"
SelectionChanged="LoadAnnouncements">
<ListView.ItemTemplate>
<DataTemplate x:DataType="data:Part">
<StackPanel Orientation="Horizontal">
<TextBlock Name="PartImage"
Text=""
FontFamily="Segoe MDL2 Assets"/>
<TextBlock Name="PartName"
Text="{x:Bind PartName}"
Margin="20,0,0,0"/>
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</SplitView>
I get an error at the following line:
x:DataType="data:Part"
that the class Part does not exist in the namespace defind by data although it does..
The mistake was that that I had created the class after I wrote the code in XAML. So when it was written the compiler tried to find a nonexisting class. All I had to do is rewrite the XAML code, clean and rebuild the solution...
I need a pivot page that in every pivot page there is a longlistselector to list the data...
this is the code that i write when i create a simple pivot page
<phone:PivotItem Header="all">
<phone:LongListSelector Name="AllNotes"
Background="Black"
Margin="0,0,0,0">
<phone:LongListSelector.ItemTemplate>
<DataTemplate>
<StackPanel Background="White"
Margin="0,17,0,0">
<TextBlock Text="aaaa">
</TextBlock>
</StackPanel>
</DataTemplate>
</phone:LongListSelector.ItemTemplate>
</phone:LongListSelector>
</phone:PivotItem>
but there isn't anything in the pivot item
i mean by defining a data template and then a stackpanel, there is nothing shown in the pivot item
can you help me ti figure out whats happening exactly?
here is my binding code
<phone:Pivot Title="MY NOTEPAD"
Background="DarkCyan">
<!-- All Notes -->
<phone:PivotItem Header="all">
<phone:LongListSelector Name="FirstListBox"
ItemsSource="{Binding AllNotes}"
Background="Black"
Margin="0,0,0,0">
<phone:LongListSelector.ItemTemplate>
<DataTemplate>
<StackPanel Margin="0,17,0,0">
<TextBlock Text="{Binding Title}"
TextWrapping="Wrap"/>
<TextBlock Text="{Binding Memory}"
TextWrapping="Wrap"/>
</StackPanel>
</DataTemplate>
</phone:LongListSelector.ItemTemplate>
</phone:LongListSelector>
</phone:PivotItem>
now what you think about it?
I finally solve this problem in the way that I don't believe it!
The answer is that we have to start writing the application in the base of Pivot Application !!!
That I don't believe this in the first place!
But Thank You Anyway :)
I would like to change the background of my grid to white when you hover over or select it. I'd also like to change the color of the text inside at the same time to black. This is specific to one page only, so it would need to be applied with an XKey or something as a guess. The grid starts with a transparent background, also.
I'm really struggling to find the direction for this. Please let me know if you have any ideas or links!
Here's my code:
<GridView.ItemTemplate>
<DataTemplate>
<Grid VerticalAlignment="Top" HorizontalAlignment="Left" Width="335" Height="152">
<StackPanel Orientation="Horizontal" Margin="2,2,2,2" VerticalAlignment="Top" HorizontalAlignment="Left">
<StackPanel Margin="13,0,13,0" Orientation="Vertical" VerticalAlignment="Top" HorizontalAlignment="Left">
<StackPanel Orientation="Horizontal" VerticalAlignment="Bottom">
<TextBlock Style="{StaticResource SmallText}" Text="{Binding Town}" />
<TextBlock Style="{StaticResource SmallText}" Text=", "/>
<TextBlock Style="{StaticResource SmallText}" Text="{Binding State}"/>
<TextBlock Style="{StaticResource SmallText}" Text=", "/>
<TextBlock Style="{StaticResource SmallText}" Text="{Binding Postcode}"/>
</StackPanel>
</StackPanel>
</StackPanel>
</Grid>
</DataTemplate>
</GridView.ItemTemplate>
Thanks for any help.
It seems like you would probably want to modify your GridView's ItemContainerStyle and change its background and visual states to match your requirements. Check my answer to an earlier question related to restyling items here to learn how to extract and modify these styles and templates.
I am building a windows 8 metro app for fun/learning etc.
I have created a listview of text items that have descriptions, images etc. Inside the description, there are often hyperlinks that I would like to make clickable.
However, when binding to a textblock, xaml hyperlink code is displayed as text. Searching arround, it looks like I need to use a richtextblock for hyperlinks. I can't seem to figure out how to bind a hyperlink to it. I have found many examples from wpf showing how to extend the richtextblock using flowdocument. Flowdocument doesn't exist in the current consumer preview version of the framework.
I am reaching out to see if anyone has solved this issue or has any suggestions on what path to head down.
Edit:
Code I have Currently
right now I am just binding the "text" field from my Statuses Object to a textblock binding on "text"
I have URL's in the text field which I want to be able to make clickable.
As a test I was replacing the text field of the first object with hyperlink markup
ex.
feed_results[0].text = "<hyperlink .....
then trying to bind to texblock and richtextblock
Xaml
<ListView x:Name="ItemListView" ItemsSource="{Binding}" Background="Black" Width="372" VerticalAlignment="Top" Margin="50,0,0,0">
<ListView.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Vertical" MinHeight="100">
<StackPanel Orientation="Horizontal">
<Image Source="{Binding user.profile_image_url}" Margin="0,0,15,0" VerticalAlignment="Top" />
<StackPanel Orientation="Vertical">
<TextBlock HorizontalAlignment="Left" Foreground="Gray" Text="{Binding user.name}" FontWeight="Bold" TextWrapping="Wrap" MaxWidth="200" />
<TextBlock HorizontalAlignment="Left" Foreground="Gray" Text="{Binding text}" TextWrapping="Wrap" MaxWidth="200" />
</StackPanel>
</StackPanel>
<StackPanel Margin="0,15,0,0" HorizontalAlignment="Right">
<TextBlock Text="{Binding created_at, Converter={StaticResource StringConverter},ConverterParameter=Released: \{0:d\}}" HorizontalAlignment="Center" Foreground="Gray" />
</StackPanel>
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
Backend Code
FeedResult<Statuses> r2 = await feed.StatusesAsync(1, 50);
if (!r2.HasError)
{
feed_results = r2.Result;
Dispatcher.Invoke(Windows.UI.Core.CoreDispatcherPriority.High, new Windows.UI.Core.InvokedHandler((o, a) =>
{
ItemListView1.ItemsSource = feed_results;
}), this, null);
}
Microsoft removed support for inline hyperlinks from Metro XAML. You can still use HyperlinkButton for non inline hyperlinks, or if your inline hyperlinks short (1-2 words) then you could place HyperlinkButton inside of InlineUIContainer in RichTextBlock. Later solution would require some code, just using binding won't do it.
<toolkit:LongListSelector>
<toolkit:LongListSelector.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Name}" FontSize="22" TextWrapping="Wrap" />
<TextBlock Name="Info" FontSize="18" TextWrapping="Wrap" />
</StackPanel>
</DataTemplate>
</toolkit:LongListSelector.ItemTemplate>
</toolkit:LongListSelector>
I have the above LongListSelector which selects the "Name"(Binded in the first Textblock )values from a list. I also wanted to additional text to it,for which i created one more Textblock below that. I couldn't add the text to the second TextBlock like(Info.Text="HI") because it is inside the LonglistSelector
How to give the values to the second Textblock??
Thanks
Do you mean Info is a property on the DataContext of the page and not on the current item where Name is?
If so, you can use a DataContextProxy to get to the data outside of the list item. If not, you'll have to be more clear on what you mean.