datatemplate

ControlTemplate with DataTrigger Vs. DataTemplate with DataTemplateSelector

China☆狼群 提交于 2019-11-28 07:01:37
I have a generic control which displays an editor based on the type property inside a ViewModel. Currently it's implemented using Control , ControlTemplate and DataTrigger like this - <Control x:Name="MainControl" Grid.Column="1" TargetUpdated="OnTargetUpdated"> <Control.Style> <Style> <Style.Triggers> <DataTrigger Binding="{Binding Path=EditorType}" Value="{x:Static view:EditorType.Bool}"> <Setter Property="Control.Template" Value="{StaticResource boolTemplate}" /> </DataTrigger> <DataTrigger Binding="{Binding Path=EditorType}" Value="{x:Static view:EditorType.Text}"> <Setter Property=

'Cannot find governing FrameworkElement…' warning when binding inside DataTemplates

空扰寡人 提交于 2019-11-28 02:48:08
问题 I'm getting this warning in Visual Studio output window when binding on a SolidColorBrush property inside a DataTemplate : System.Windows.Data Error: 2 : Cannot find governing FrameworkElement or FrameworkContentElement for target element. BindingExpression:Path=MyColor; DataItem=null; target element is 'SolidColorBrush' (HashCode=22943289); target property is 'Color' (type 'Color') If I bind directly on the rectangle element, outside the DataTemplate , it all works well. Can anyone explain

How to group consecutive similar items of a collection?

有些话、适合烂在心里 提交于 2019-11-28 01:38:04
Consider the following collection. True False False False True True False False I want to display it in a structured way, say, in a TreeView . I want to be able to draw borders around entire groups and such. True Group True False Group False False False True Group True True False Group False False How do I accomplish this with as little procedural code as possible? This does what you're looking for and is generic: private static IEnumerable<IGrouping<int, T>> GroupConsecutive<T>(this IEnumerable<T> set, Func<T, T, bool> predicate) { var i = 0; var k = 0; var ranges = from e in set let idx = +

How do I update an existing element of an ObservableCollection?

ε祈祈猫儿з 提交于 2019-11-28 01:20:41
I have an instance of ObservableCollection bound to a WPF listbox with two separate data templates (one for display, one for editing). The data template for editing has a one-way binding on the textbox, and a Save button. What changes do I need to make so that when I press the Save button (after putting the list item in edit mode), the value I change the textbox to replaces the value in the ObservableCollection (and the display)? Alan Mendelevich Items in your collection should be of type that implements INotifyPropertyChanged interface. This way your list box will be notified that property

How to bind DataTemplate datatype to interface?

百般思念 提交于 2019-11-27 22:59:42
问题 I am writing a composite loosely coupled MVVM WPF application and child VMs in a parent VM are interfaces rather than class instances, e.g. public IChildViewModel { get; set; } Now how do I render this property using a DataTemplate? like: <DataTemplate DataType="{x:Type contracts:IChildViewModel}"> I understand due to the nature of interfaces (multiple inheritance etc.) WPF does not allow this direct binding. But as interfaces should be used widely in loosely coupled applications, is there

WPF: How to bind to only one item in a collection, not using ItemsControl since I don't want to display all of them

纵饮孤独 提交于 2019-11-27 21:43:22
问题 I have this requirement, that I have a collection of items (ObservableCollection), but I only want to display the first item. The requirement comes from the fact that in most of the case, the collection only contains one item. And due to the space limit, even if there is more than one items in the collection, we'd like to display the number of the items, details of the first one (same presentation as prior situation) and a ... symbol to indicate to the user that there is more items. And when

Inline editing TextBlock in a ListBox with Data Template (WPF)

南笙酒味 提交于 2019-11-27 20:21:20
问题 Using WPF, I have a ListBox control with a DataTemplate inside it. The relevant XAML code is shown below: <ListBox Name="_todoList" Grid.Row="1" BorderThickness="2" Drop="todoList_Drop" AllowDrop="True" HorizontalContentAlignment="Stretch" ScrollViewer.HorizontalScrollBarVisibility="Disabled" AlternationCount="2"> <ListBox.ItemTemplate> <DataTemplate> <Grid Margin="4"> <Grid.ColumnDefinitions> <ColumnDefinition Width="Auto" /> <ColumnDefinition Width="*" /> </Grid.ColumnDefinitions> <CheckBox

Silverlight 3: ListBox DataTemplate HorizontalAlignment

做~自己de王妃 提交于 2019-11-27 20:04:23
I have a ListBox with it's ItemTemplate bound to a DataTemplate. My problem is I cannot get the elements in the template to stretch to the full width of the ListBox. <ListBox x:Name="listPeople" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Margin="0,0,0,0" Background="{x:Null}" SelectionMode="Extended" Grid.Row="1" ItemTemplate="{StaticResource PersonViewModel.BrowserDataTemplate}" ItemsSource="{Binding Mode=OneWay, Path=SearchResults}" > </ListBox> <DataTemplate x:Key="PersonViewModel.BrowserDataTemplate"> <ListBoxItem HorizontalAlignment="Stretch" VerticalAlignment="Stretch">

Display a default DataTemplate in a ContentControl when its content is null or empty?

我的未来我决定 提交于 2019-11-27 20:03:57
问题 I would think this is possible, but the obvious way isn't working. Currently, I'm doing this: <ContentControl Content="{Binding HurfView.EditedPart}"> <ContentControl.Resources> <Style TargetType="ContentControl" x:Key="emptytemplate"> <Style.Triggers> <DataTrigger Binding="{Binding RelativeSource={x:Static RelativeSource.Self}, Path=Content}" Value="{x:Null}"> <Setter Property="ContentControl.Template"> <Setter.Value> <ControlTemplate> <Grid HorizontalAlignment="Stretch" VerticalAlignment=

WPF ListView with GridViewColumn and DataTemplate

♀尐吖头ヾ 提交于 2019-11-27 19:45:38
I have a CheckedListBox control which is created by adding a DataTemplate with a CheckBox to a ListView . The problem is that I need columns too. The following code doesn't display the check boxes: <ListView x:Name="lbDatabases" Height="138" Width="498" Canvas.Left="44" Canvas.Top="146"> <ListView.View> <GridView> <GridViewColumn DisplayMemberBinding="{Binding DbName}" Header="Databases" Width="498"/> </GridView> </ListView.View> <ListView.ItemTemplate> <DataTemplate> <CheckBox IsChecked="{Binding IsActive}" Checked="AnyChange" Unchecked="AnyChange" Style="{x:Null}" Content="{Binding DbName}"