datatemplate

WPF Some styles not applied on DataTemplate controls

我们两清 提交于 2019-11-27 19:41:19
I am trying to learn something about WPF and I am quite amazed by its flexibility. However, I have hit a problem with Style s and DataTemplate s, which is little bit confusing. I have defined below test page to play around a bit with styles etc and found that the Style s defined in <Page.Resources> for Border and TextBlock are not applied in the DataTemplate , but Style for ProgressBar defined in exactly the same way is applied. Source code (I just use Kaxaml and XamlPadX to view the result) <Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas

Selecting a ListBoxItem when its inner ComboBox is focused

本秂侑毒 提交于 2019-11-27 19:10:41
I have a DataTemplate that will be a templated ListBoxItem, this DataTemplate has a ComboBox in it which when it has focus I want the ListBoxItem that this template represents to become selected, this looks right to me. but sadly enough it doesn't work =( So the real question here is within a DataTemplate is it possible to get or set the value of the ListBoxItem.IsSelected property via a DataTemplate.Trigger ? <DataTemplate x:Key="myDataTemplate" DataType="{x:Type local:myTemplateItem}"> <Grid x:Name="_LayoutRoot"> <ComboBox x:Name="testComboBox" /> </Grid> <DataTemplate.Triggers> <Trigger

WPF ListView with buttons on each line

∥☆過路亽.° 提交于 2019-11-27 18:48:53
I have a list of Games which just has an ID , a Date , and a Time . I am setting this list as the DataContext . I then have a DataTemplate for these games that is: <DataTemplate DataType="{x:Type loc:Game}"> <Grid> <Grid.RowDefinitions> <RowDefinition Height="auto"></RowDefinition> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition Width="100"></ColumnDefinition> <ColumnDefinition Width="100"></ColumnDefinition> <ColumnDefinition Width="100"></ColumnDefinition> </Grid.ColumnDefinitions> <TextBlock Name="dateBlock" Grid.Column="0" Grid.Row="1" Text="{Binding Date, StringFormat=d}

Always show FooterTemplate, even no data

偶尔善良 提交于 2019-11-27 18:48:25
问题 Is there a short way to make a FooterTemplate (in a GridView) always visible, even when DataSource is empty? 回答1: If you want it to always display, regardless of content, can't you just put the footer html outside the GridView , instead of in the FooterTemplate ? If that's not an option for some reason, then you can either add an null row to your data source if it's empty, or subclass the GridView & override the default behaviour. Those are the only options I'm aware of (although its been a

How do I make a WPF data template fill the entire width of the listbox?

非 Y 不嫁゛ 提交于 2019-11-27 17:56:49
I have a ListBox DataTemplate in WPF. I want one item to be tight against the left side of the ListBox and another item to be tight against the right side, but I can't figure out how to do this. So far I have a Grid with three columns, the left and right ones have content and the center is a placeholder with it's width set to "*". Where am I going wrong? Here is the code: <DataTemplate x:Key="SmallCustomerListItem"> <Grid HorizontalAlignment="Stretch"> <Grid.RowDefinitions> <RowDefinition/> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition/> <ColumnDefinition Width="*"/>

Animate WPF Datatemplate when item added to Listbox?

那年仲夏 提交于 2019-11-27 17:37:22
In my project I have a WPF Listbox bound to an ObservableCollection. Every time I add a new item to the Collection the same item is added to the Listbox automaticly. To display the items in the Listbox I use a XAML Datatemplate. What I want to do is animate an item once when it is added to the Collection/Listbox. Can this be done? As animation in the datatemplate maybe? I guess I need a trigger somehow to start this animate but what trigger is fired when a new item/datatemplate is added? I think an event trigger for the FrameworkElement.Loaded routed event could work. For example:

Concatenate strings instead of using a stack of TextBlocks

无人久伴 提交于 2019-11-27 17:25:46
I want to show a list of Customer objects in a WPF ItemsControl. I've created a DataTemplate for this: <DataTemplate DataType="{x:Type myNameSpace:Customer}"> <StackPanel Orientation="Horizontal" Margin="10"> <CheckBox"></CheckBox> <TextBlock Text="{Binding Path=Number}"></TextBlock> <TextBlock Text=" - "></TextBlock> <TextBlock Text="{Binding Path=Name}"></TextBlock> </StackPanel> </DataTemplate> So what I want basically is a simple list (with checkboxes) that contains NUMBER - NAME. Isn't there a way in which I can concat the number and name directly in the Binding part? PiRX There is

Binding a CollectionViewSource within a DataTemplate

不问归期 提交于 2019-11-27 16:12:06
问题 'ContentTemplate' is a DataTemplate that displays an object which has a member 'FooList' (an ObservableCollection). <DataTemplate x:Key="ContentTemplate"> <ListBox ItemsSource="{Binding Path=FOO}"> ... </ListBox> </DataTemplate> I need to be able to filter that FooList using a CollectionViewSource. This is usually been straight forward but I can't seem to get the binding to work within a DataTemplate. I attempted to this: <DataTemplate x:Key="ContentTemplate"> <DataTemplate.Resources>

How to display search results in a WPF items control with highlighted query terms

房东的猫 提交于 2019-11-27 15:11:56
I'd like to display search results within a WPF ItemsControl with the query terms highlighted. The search engine I use, Lucene.Net with the Highlighter plugin, returns strings with the query terms marked up like so: ...these <Bold>results</Bold> were found to be statistically significant... I can instruct the Highlighter plugin to use any set of markup tags to wrap a query term. I'm not limited to the <Bold> tag in the example above. For WPF, I'd likely make these <Run/> elements with a style attached. The challenge is to take the string I've been given and render it as if it were "actual XAML

How to get DataTemplate.DataTrigger to check for greater than or less than?

ε祈祈猫儿з 提交于 2019-11-27 14:33:57
The following DataTemplate.DataTrigger makes the age display red if it is equal to 30. How do I make the age display red if it is greater than 30? <DataTemplate DataType="{x:Type local:Customer}"> <Grid x:Name="MainGrid" Style="{StaticResource customerGridMainStyle}"> <Grid.ColumnDefinitions> <ColumnDefinition Width="100"/> <ColumnDefinition Width="150"/> </Grid.ColumnDefinitions> <Grid.RowDefinitions> <RowDefinition/> <RowDefinition/> <RowDefinition/> </Grid.RowDefinitions> <TextBlock Grid.Column="0" Grid.Row="0" Text="First Name" Margin="5"/> <TextBlock Grid.Column="1" Grid.Row="0" Text="