Search Results

Search found 56 results on 3 pages for 'hierarchicaldatatemplate'.

Page 1/3 | 1 2 3  | Next Page >

  • WPF: HierarchicalDataTemplate ItemsPanel

    - by Echilon
    I have a TreeView which uses a custom ItemsPanel to show the first level of items in a StackPanel, but I need to show subitems in a StackPanel too. The problem is, the second level of items are shown in a WrapPanel, and as HierarchicalDataTemplate doesn't have an itemsPanel property I'm not sure how to do this. This is my xaml: <TreeView x:Name="treGlobalCards"> <TreeView.ItemsPanel> <ItemsPanelTemplate> <StackPanel IsItemsHost="True" Orientation="{Binding Orientation,RelativeSource={x:Static RelativeSource.TemplatedParent}}" MaxWidth="{Binding ActualWidth,RelativeSource={RelativeSource AncestorType={x:Type ScrollContentPresenter}}}"/> </ItemsPanelTemplate> </TreeView.ItemsPanel> <TreeView.ItemTemplate> <HierarchicalDataTemplate x:Key="CardTypeTemplate" ItemsSource="{Binding Cards}"> <TextBlock Text="{Binding Path=CardType}"/> </HierarchicalDataTemplate> </TreeView.ItemTemplate> </TreeView>

    Read the article

  • Filtering in a HierarchicalDataTemplate via MarkupExtension?

    - by Dan Bryant
    I'm trying to create a MarkupExtension to allow filtering of items in an ItemsSource of a HierarchicalDataTemplate. In particular, I'd like to be able to supply a method name that will be executed on the DataContext in order to perform the filtering. The usage syntax I'm after looks like this: <HierarchicalDataTemplate DataType="{x:Type src:DeviceBindingViewModel}" ItemsSource="{Utilities:FilterCollection {Binding Definition.Entries}, MethodName=FilterEntries}"> <StackPanel Orientation="Horizontal"> <Image Source="{StaticResource BindingImage}" Width="24" Height="24" Margin="3"/> <TextBlock Text="{Binding DisplayName}" FontSize="12" VerticalAlignment="Center"/> </StackPanel> </HierarchicalDataTemplate> My code for the custom MarkupExtension looks like this: public sealed class FilterCollectionExtension : MarkupExtension { private readonly MultiBinding _binding; private Predicate<Object> _filterMethod; public string MethodName { get; set; } public FilterCollectionExtension(Binding binding) { _binding = new MultiBinding(); _binding.Bindings.Add(binding); //We package a reference to the DataContext with the binding so that the Converter has access to it var selfBinding = new Binding {RelativeSource = RelativeSource.Self}; _binding.Bindings.Add(selfBinding); _binding.Converter = new InternalConverter(this); } public FilterCollectionExtension(Binding binding, string methodName) : this(binding) { MethodName = methodName; } public override object ProvideValue(IServiceProvider serviceProvider) { return _binding; } private bool FilterInternal(Object dataContext, Object value) { //Filtering is only applicable if a DataContext is defined if (dataContext != null) { if (_filterMethod == null) { var type = dataContext.GetType(); var method = type.GetMethod(MethodName, new[] { typeof(Object) }); if (method == null || method.ReturnType != typeof(bool)) throw new InvalidOperationException("Could not locate a filter predicate named " + MethodName + " on the DataContext"); _filterMethod = (Predicate<Object>)Delegate.CreateDelegate(typeof(Predicate<Object>), dataContext, method); } else { if (_filterMethod.Target != dataContext) { _filterMethod = (Predicate<Object>) Delegate.CreateDelegate(typeof (Predicate<Object>), dataContext, _filterMethod.Method); } } if (_filterMethod != null) return _filterMethod(value); } //If no filtering resolved, just allow all elements return true; } private class InternalConverter : IMultiValueConverter { private readonly FilterCollectionExtension _owner; public InternalConverter(FilterCollectionExtension owner) { _owner = owner; } public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture) { var enumerable = values[0]; var targetElement = (FrameworkElement)values[1]; var view = CollectionViewSource.GetDefaultView(enumerable); view.Filter = item => _owner.FilterInternal(targetElement.DataContext, item); return view; } public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture) { throw new NotSupportedException("Cannot convert back"); } } } I can see that the extension is instantiated and I can see it return the MultiBinding that is used by the Template. I also see the call to the InternalConverter.Convert method, which sees the expected parameters (I see the collection provided by the nested {Binding}) and is successfully able to retrieve the ICollectionView for the incoming collection. The only problem is that FilterInternal never gets called. The template is ultimately being used by a TreeView, if that's relevant. I haven't been able to figure out why the FilterInternal method is not being called and I was hoping somebody might be able to offer some insight.

    Read the article

  • HierarchicalDataTemplate Distinct leaves

    - by miguel
    I have a set of data that is structured like this: ItemA.GroupA ItemB.GroupA ItemC.GroupB ItemD.GroupC I need to present the data in a WPF Tree View like this: GroupA --- ItemA --- ItemB GroupB --- ItemC GroupC --- ItemD What XAML can I use to group the leaves by distinct value? For instance, there could be multple items in the collection which are GroupA.ItemA, however, I only want to present the node and leaf once.

    Read the article

  • TreeViewItem - Use ControlTemplate and HierarchicalDataTemplate together

    - by CrownJ
    I'm using HierarchicalDataTemplate in my TreeView, and I wanted to also overwrite the default template for the TreeViewItem so that when an item is selected, it only highlights the text, not including the icon next to it. <TreeView.ItemTemplate> <HierarchicalDataTemplate ItemsSource="{Binding Children}"> <TreeViewItem Style="{StaticResource TreeViewItemStyle}" Header="{Binding DisplayText}" /> </HierarchicalDataTemplate> </TreeView.ItemTemplate> <TreeView.Resources> <Style x:Key="TreeViewItemFocusVisual"> <Setter Property="Control.Template"> <Setter.Value> <ControlTemplate> <Rectangle/> </ControlTemplate> </Setter.Value> </Setter> </Style> <Style x:Key="ExpandCollapseToggleStyle" TargetType="{x:Type ToggleButton}"> <Setter Property="Focusable" Value="False"/> <Setter Property="Width" Value="19"/> <Setter Property="Height" Value="13"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type ToggleButton}"> <Border Width="19" Height="13" Background="Transparent"> <Border Width="9" Height="9" SnapsToDevicePixels="true" BorderBrush="#FF7898B5" BorderThickness="1" CornerRadius="1"> <Border.Background> <LinearGradientBrush EndPoint="1,1" StartPoint="0,0"> <GradientStop Color="White" Offset=".2"/> <GradientStop Color="#FFC0B7A6" Offset="1"/> </LinearGradientBrush> </Border.Background> <Path x:Name="ExpandPath" Fill="Black" Margin="1,1,1,1" Data="M 0 2 L 0 3 L 2 3 L 2 5 L 3 5 L 3 3 L 5 3 L 5 2 L 3 2 L 3 0 L 2 0 L 2 2 Z"/> </Border> </Border> <ControlTemplate.Triggers> <Trigger Property="IsChecked" Value="True"> <Setter Property="Data" TargetName="ExpandPath" Value="M 0 2 L 0 3 L 5 3 L 5 2 Z"/> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> <Style x:Key="{x:Type TreeViewItem}" TargetType="{x:Type TreeViewItem}"> <Setter Property="Background" Value="Transparent"/> <Setter Property="HorizontalContentAlignment" Value="{Binding HorizontalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/> <Setter Property="VerticalContentAlignment" Value="{Binding VerticalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/> <Setter Property="Padding" Value="1,0,0,0"/> <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/> <Setter Property="FocusVisualStyle" Value="{StaticResource TreeViewItemFocusVisual}"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type TreeViewItem}"> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="Auto"/> <ColumnDefinition Width="Auto"/> <ColumnDefinition Width="*"/> </Grid.ColumnDefinitions> <Grid.RowDefinitions> <RowDefinition Height="Auto"/> <RowDefinition/> </Grid.RowDefinitions> <ToggleButton x:Name="Expander" Style="{StaticResource ExpandCollapseToggleStyle}" ClickMode="Press" IsChecked="{Binding IsExpanded, RelativeSource={RelativeSource TemplatedParent}}"/> <StackPanel Orientation="Horizontal" Grid.Column="1" > <Image Width="16" Height="16" Margin="3,0" Source="{Binding Path=ImageSource}" /> <Border x:Name="Bd" SnapsToDevicePixels="true" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Margin="0" Padding="0"> <ContentPresenter x:Name="PART_Header" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" ContentSource="Header"/> </Border> </StackPanel> <ItemsPresenter x:Name="ItemsHost" Grid.Column="1" Grid.ColumnSpan="2" Grid.Row="1"/> </Grid> <ControlTemplate.Triggers> <Trigger Property="IsExpanded" Value="false"> <Setter Property="Visibility" TargetName="ItemsHost" Value="Collapsed"/> </Trigger> <Trigger Property="HasItems" Value="false"> <Setter Property="Visibility" TargetName="Expander" Value="Hidden"/> </Trigger> <Trigger Property="IsSelected" Value="true"> <Setter Property="Background" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}"/> <Setter Property="Control.Foreground" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.HighlightTextBrushKey}}"/> </Trigger> <MultiTrigger> <MultiTrigger.Conditions> <Condition Property="IsSelected" Value="true"/> <Condition Property="IsSelectionActive" Value="false"/> </MultiTrigger.Conditions> <Setter Property="Background" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"/> <Setter Property="Control.Foreground" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/> </MultiTrigger> <Trigger Property="IsEnabled" Value="false"> <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> <Style.Triggers> <Trigger Property="VirtualizingStackPanel.IsVirtualizing" Value="true"> <Setter Property="ItemsPanel"> <Setter.Value> <ItemsPanelTemplate> <VirtualizingStackPanel/> </ItemsPanelTemplate> </Setter.Value> </Setter> </Trigger> </Style.Triggers> </Style> </TreeView.Resources> I couldn't find a way to use both the HierarchicalDataTemplate and ControlTemplate together so I can specify the ItemsSource and also change parts of the control's behavior. When I do the above code, it won't select the treeviewitem at all.

    Read the article

  • geting information from Treeview with HierarchicalDataTemplate

    - by lina
    Good day! I have such a template: <common:HierarchicalDataTemplate x:Key="my2ndPlusHierarchicalTemplate" ItemsSource="{Binding Children}"> <StackPanel Margin="0,2,5,2" Orientation="Vertical" Grid.Column="2"> <CheckBox IsTabStop="False" IsChecked="False" Click="ItemCheckbox_Click" Grid.Column="1" /> <TextBlock Text="{Binding Name}" FontSize="16" Foreground="#FF100101" HorizontalAlignment="Left" FontFamily="Verdana" FontWeight="Bold" /> <TextBlock Text="{Binding Description}" FontFamily="Verdana" FontSize="10" HorizontalAlignment="Left" Foreground="#FFA09A9A" FontStyle="Italic" /> <TextBox Width="100" Grid.Column="4" Height="24" LostFocus="TextBox_LostFocus" Name="tbNumber"></TextBox> </StackPanel> </common:HierarchicalDataTemplate> for a Treeview <controls:TreeView x:Name="tvServices" ItemTemplate="{StaticResource myHierarchicalTemplate}" ItemContainerStyle="{StaticResource expandedTreeViewItemStyle}" Grid.Column="1" Grid.Row="2" Grid.ColumnSpan="3" BorderBrush="#FFC1BCBC" FontFamily="Verdana" FontSize="14"> </controls:TreeView> I want to know the Name property of each TextBox in Treeview to make validation of each textbox such as: private void TextBox_LostFocus(object sender, RoutedEventArgs e) { tbNumber.ClearValidationError(); if ((!tbNumber.Text.IsZakazNumberValid()) && (tbNumber.Text != "")) { tbNumber.SetValidation(MyStrings.NumberError); tbNumber.RaiseValidationError(); isValid = false; } else { isValid = true; } } and I wnat to see what check boxes were checked how can I do it?

    Read the article

  • Can't use attached property on combobox inside hierarchical datatemplate WPF

    - by jesse_t_r
    I'm hoping to use an attached property to assign a command to the selection changed event of a combobox that is embedded inside a treeview. I'm attempting to set the attached property inside the hierchical data template for the tree but the command is not set and does not fire when the item in the combobox is changed. I've found that setting the attached property directly on a combobox outside of a datatemplate works fine; here is how I'm trying to set the property in the template: <HierarchicalDataTemplate x:Key="template1" ItemsSource="{Binding Path=ChildColumns}"> <Border Background="{StaticResource TreeItem_Background}" BorderBrush="Blue" BorderThickness="2" CornerRadius="5" Margin="2,5,5,2" HorizontalAlignment="Left" > <Grid> <Grid.ColumnDefinitions > <ColumnDefinition Width="Auto"/> <ColumnDefinition Width="*"/> <ColumnDefinition Width="*"/> </Grid.ColumnDefinitions> <Grid.RowDefinitions> <RowDefinition /> <RowDefinition /> </Grid.RowDefinitions> <TextBlock MinWidth="80" HorizontalAlignment="Left" Grid.Column="0" Margin="5,2,2,2" Grid.Row ="0" Text="{Binding Path=ColName}"/> <ComboBox Name="cboColType" Grid.Column="1" HorizontalAlignment="Right" ItemsSource="{Binding Source={StaticResource dataFromEnum}}" SelectedItem="{Binding Path=ColumnType}" Margin="2,2,2,2" local:ItemSelectedBehavior.ItemSelected="{Binding Path=LoadConfigCommand}" /> </Grid> </Border> </HierarchicalDataTemplate> I also tried creating a style <Style x:Key="childItemStyle" TargetType="{x:Type FrameworkElement}"> <Setter Property="local:ItemSelectedBehavior.ItemSelected" Value="{Binding Path=LoadConfigCommand}" /> </Style> and setting the itemcontainerstyle to the style in the hierarchical datatemplate..still no luck .. <HierarchicalDataTemplate> ... <ComboBox Name="cboColType" Grid.Column="1" HorizontalAlignment="Right" ItemsSource="{Binding Source={StaticResource dataFromEnum}}" SelectedItem="{Binding Path=ColumnType}" Margin="2,2,2,2" ItemContainerStyle={StaticeResource childItemStyle}" /> ... </HierarchicalDataTemplate> I'm still learning a lot about WPF so I'm assuming there is something particular about the hierchical datatemplate that is not allowing the attache dproperty to be set..I have found similar posts in the forums and tried to implement their solutions as above, but after a day of searching and experimenting wiht no luck I'm hoping some one has an idea about this...

    Read the article

  • Get logical path from treeview which has HierarchicalDataTemplate

    - by phenevo
    Hi, I have a structure of geography objects: Country Areas, Provinces, Cities and Hotels Country has regions, regions provinces etc... Whne I'll click City node I wanna to get logical path eg: France,Provanse,SomeProvince,Montpellier,Coral Hotel. Each class has fields: name, code nad listOf... Treeview works great, but this method not: private void structureTree_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e) { if (structureTree.SelectedItem is Hotel) { objectCode = ((Hotel)structureTree.SelectedItem).Code; TreeViewItem item = e.OriginalSource as TreeViewItem; DependencyObject parent = VisualTreeHelper.GetParent(item); dlgEditHotel(objectCode, structureTree.Parent.ToString()); } }

    Read the article

  • HierarchicalDataTemplate Link By Parent

    - by Andrew Kalashnikov
    Hello colleagues. I want bind my treeview. There are a lot of samples binding treeview by object, which contains children collection. I've got domain having just Parent pointer. public class Service : BaseDomain { public virtual string Name { get; set; } public virtual string Description { get; set; } public virtual Service Parent { get; set; } } Can I bind collection of this objects to my treeView. Thanks

    Read the article

  • How can I bind a instance of a custom class to a WPF TreeListView without bugs?

    - by user327104
    First, from : http://blogs.msdn.com/atc_avalon_team/archive/2006/03/01/541206.aspx I get a nice TreeListView. I left the original classes (TreeListView, TreeListItemView, and LevelToIndentConverter) intact, the only code y have Added is on the XAML, here is it: <Style TargetType="{x:Type l:TreeListViewItem}"> .... </ControlTemplate.Triggers> <ControlTemplate.Resources> <HierarchicalDataTemplate DataType="{x:Type local:FileInfo}" ItemsSource="{Binding Childs}"> </HierarchicalDataTemplate> </ControlTemplate.Resources> </ControlTemplate> ... here is my custom class public class FileInfo { private List<FileInfo> childs; public FileInfo() { childs = new List<FileInfo>(); } public bool IsExpanded { get; set; } public bool IsSelected { get; set; } public List<FileInfo> Childs { get { return childs; } set { } } public string FileName { get; set; } public string Size { get; set; } } And before I use my custom class I remove all the items inside the treeListView1: <l:TreeListView> <l:TreeListView.Columns> <GridViewColumn Header="Name" CellTemplate="{StaticResource CellTemplate_Name}" /> <GridViewColumn Header="IsAbstract" DisplayMemberBinding="{Binding IsAbstract}" Width="60" /> <GridViewColumn Header="Namespace" DisplayMemberBinding="{Binding Namespace}" /> </l:TreeListView.Columns> </l:TreeListView> So finaly I add this code to bind a Instance of my class to the TreeListView: private void Window_Loaded(object sender,RoutedEventArgs e) { FileInfo root = new FileInfo() { FileName = "mis hojos", Size="asdf" }; root.Childs.Add(new FileInfo(){FileName="sub", Size="123456" }); treeListView1.Items.Add(root); root.Childs[0].Childs.Add(new FileInfo() { FileName = "asdf" }); root.Childs[0].IsExpanded = true; } So the bug is that the button to expand the elementes dont appear and when a node is expanded by doble click the child nodes dont look like child nodes. Please F1 F1 F1 F1 F1 F1 F1 F1.

    Read the article

  • Hierarchical templating multiple object types in silverlight

    - by Dan Wray
    Is it possible and if so what is the best way to implement the following hierarchical structure in a silverlight (4) TreeView control? (where Item and Group are classes which can exist in the tree). Group | |-Item | |-Group | | | |-Item | | | |-Item | |-Item The structure could of course be arbitrarily more complex than this, if needed. HierarchicalDataTemplates appear to be the way to approach this, but I'm specifically having trouble understanding how I might apply the template to interpret the different classes correctly. A similar question was asked for WPF, the answer for which made use of the TargetType property on the HierarchicalDataTemplate, but I am uncertain whether that property is available in the silverlight version since I don't appear to have access to it in my environment.

    Read the article

  • How can I modify my classes to use it's collections in WPF TreeView

    - by Victor
    Hello, i'am trying to modify my objects to make hierarchical collection model. I need help. My objects are Good and GoodCategory: public class Good { int _ID; int _GoodCategory; string _GoodtName; public int ID { get { return _ID; } } public int GoodCategory { get { return _GoodCategory; } set { _GoodCategory = value; } } public string GoodName { get { return _GoodName; } set { _GoodName = value; } } public Good(IDataRecord record) { _ID = (int)record["ID"]; _GoodtCategory = (int)record["GoodCategory"]; } } public class GoodCategory { int _ID; string _CategoryName; public int ID { get { return _ID; } } public string CategoryName { get { return _CategoryName; } set { _CategoryName = value; } } public GoodCategory(IDataRecord record) { _ID = (int)record["ID"]; _CategoryName = (string)record["CategoryName"]; } } And I have two Collections of these objects: public class GoodsList : ObservableCollection<Good> { public GoodsList() { string goodQuery = @"SELECT `ID`, `ProductCategory`, `ProductName`, `ProductFullName` FROM `products`;"; using (MySqlConnection conn = ConnectToDatabase.OpenDatabase()) { if (conn != null) { MySqlCommand cmd = conn.CreateCommand(); cmd.CommandText = productQuery; MySqlDataReader rdr = cmd.ExecuteReader(); while (rdr.Read()) { Add(new Good(rdr)); } } } } } public class GoodCategoryList : ObservableCollection<GoodCategory> { public GoodCategoryList () { string goodQuery = @"SELECT `ID`, `CategoryName` FROM `product_categoryes`;"; using (MySqlConnection conn = ConnectToDatabase.OpenDatabase()) { if (conn != null) { MySqlCommand cmd = conn.CreateCommand(); cmd.CommandText = productQuery; MySqlDataReader rdr = cmd.ExecuteReader(); while (rdr.Read()) { Add(new GoodCategory(rdr)); } } } } } So I have two collections which takes data from the database. But I want to use thats collections in the WPF TreeView with HierarchicalDataTemplate. I saw many post's with examples of Hierarlichal Objects, but I steel don't know how to make my objects hierarchicaly. Please help.

    Read the article

  • How to set the RelativeSource in a DataTemplate that is nested in a HierarchicalDataTemplate?

    - by Dabblernl
    I have the following XAML, that does all that it is supposed to, except that the MultiBinding on the FontSize fails on retrieving the Users. As you can see Users is an IEnumerable<UserData> that is part of the HierarchicalDataTemplate's DataContext. How do I reference it?? <TreeView Name="AllGroups" ItemsSource="{Binding}" > <TreeView.Resources> <HierarchicalDataTemplate DataType="{x:Type PrivateMessengerUI:GroupContainer}" ItemsSource="{Binding Users}" > <Label Content="{Binding GroupName}"/> </HierarchicalDataTemplate> <DataTemplate DataType="{x:Type PrivateMessenger:UserData}"> <TextBlock Text="{Binding Username}" ToolTip="{StaticResource UserDataGroupBox}" Name="GroupedUser" MouseDown="GroupedUser_MouseDown"> <TextBlock.FontSize> <MultiBinding Converter="{StaticResource LargeWhenIAmSelected}"> <Binding ElementName="Root" Path="SelectedUser"/> <Binding RelativeSource="???" Path="DataContext.Users"/> </MultiBinding> </TextBlock.FontSize> </TextBlock> </DataTemplate> </TreeView.Resources> </TreeView>

    Read the article

  • WPF - DataTemplate to show only one hierarchical level in recursive data

    - by Paull
    Hi all, I am using a tree to display my data: persons grouped by their teams. In my model a team can contain another team, so the recursion. I want do display details about the selected node of the tree using a contentpresenter. If the selection is a person, everything is fine: I can show the person name or datails without problem using a simple datatemplate. If the selection is a team I would like to display the team name followed by a list of member names. If one of these members is another team I would like to display just the team name, without recursion... My code here is wrong because it displays data in a recursive way, what is the right way of doing it? Thanks in advance for any help! best regards, Paolo <ContentPresenter Content="{Binding Path=SelectedItem, ElementName=PeopleTree}" > <ContentPresenter.Resources> <DataTemplate DataType="{x:Type my:PersonViewModel}"> <TextBlock Text="{Binding PersonName}"/> </DataTemplate> <DataTemplate DataType="{x:Type my:TeamViewModel}"> <StackPanel> <TextBlock Text="{Binding TeamName}" /> <ListBox ItemsSource="{Binding Members}" /> </StackPanel> </DataTemplate> </ContentPresenter.Resources> </ContentPresenter>

    Read the article

  • How to group consecutive similar items of a collection?

    - by CannibalSmith
    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?

    Read the article

  • help with grouping and sorting for TreeView in xaml

    - by danhotb
    I am having problems getting my head around grouping and sorting in xaml and hope someone can get me straightened out! I have creaed an xml file from a tree of files and folders (just like windows explorer) that can be serveral levels deep. I have bound a TreeView control to an xml datasource and it works great! It sorts everything alphabetically but ... I would like it to sort all folders first then all files, rather than folders listed with files, as it does now. the xml : if you load this to a treeviw it will display the two files before the folder because they are first in alpha-order. here is my code: <!-- This will contain the XML-data. --> <XmlDataProvider x:Key="xmlDP" XPath="*"> <x:XData> <Select_Project /> </x:XData> </XmlDataProvider> <!-- This HierarchicalDataTemplate will visualize all XML-nodes --> <HierarchicalDataTemplate DataType="project" ItemsSource ="{Binding}"> <TextBlock Text="{Binding XPath=@name}" /> </HierarchicalDataTemplate> <HierarchicalDataTemplate DataType="folder" ItemsSource ="{Binding}"> <TextBlock Text="{Binding XPath=@name}" /> </HierarchicalDataTemplate> <HierarchicalDataTemplate DataType="file" ItemsSource ="{Binding}"> <TextBlock Text="{Binding XPath=@name}" /> </HierarchicalDataTemplate> <CollectionViewSource x:Key="projectView" Source="{StaticResource xmlDP}"> <CollectionViewSource.SortDescriptions> <!-- ADD SORT DESCRIPTION HERE --> </CollectionViewSource.SortDescriptions> </CollectionViewSource> <TreeView Margin="11,79.992,18,19.089" Name="tvProject" BorderThickness="1" FontSize="12" FontFamily="Verdana"> <TreeViewItem ItemsSource="{Binding Source={StaticResource xmlDP}, XPath=*}" Header="Project"/> </TreeView>

    Read the article

  • Avoid the collapsing effect on TreeView after updating data

    - by Manolete
    I have a TreeView used to display events. It works great, however every time new events are coming in and populating the tree collapse the tree again to the original position. That is very annoying when the refresh time is less than 1 second and it does not allow the user to interact with the items of the tree. Is there any way to avoid this behaviour? <TreeView Margin="1" BorderThickness="0" Name="eventsTree" ItemsSource="{Binding EventAlertContainers}" Background="#00000000" ScrollViewer.VerticalScrollBarVisibility="Auto" FontSize="14" VirtualizingStackPanel.IsVirtualizing="True"> <TreeView.Resources> <HierarchicalDataTemplate DataType="{x:Type C:EventAlertContainer}" ItemsSource="{Binding EventAlerts}"> <StackPanel Orientation="Horizontal"> <Image Width="20" Height="20" Margin="3,0" Source="Resources\Process_info_32.png" /> <TextBlock FontWeight="Bold" FontSize="16" Text="{Binding Description}" /> </StackPanel> </HierarchicalDataTemplate> <HierarchicalDataTemplate DataType="{x:Type C:EventAlert}" ItemsSource="{Binding Events}"> <StackPanel Orientation="Horizontal"> <Image Width="20" Height="20" Margin="0,0" Source="Resources\clock2_32.jpg" /> <TextBlock FontWeight="DemiBold" FontSize="14" Text="{Binding Name}" /> </StackPanel> </HierarchicalDataTemplate> <HierarchicalDataTemplate DataType="{x:Type C:Event}"> <StackPanel Orientation="Horizontal"> <Image Width="20" Height="20" Margin="0,0" Source="Resources\Task_32.png" /> <StackPanel Orientation="Vertical"> <TextBlock FontSize="12" Text="{Binding Name}" /> </StackPanel> </StackPanel> </HierarchicalDataTemplate> </TreeView.Resources> </TreeView>

    Read the article

  • Trouble using CollectionViewSource in Silverlight

    - by Johnny
    Hi, I having some trouble when implementing the CollectionViewSource in silverlight. I'm new in this topic, so basically I've been following what I find searching through the web. Here's what I've been trying to do so far. I'm creating a CollectionViewSource in the resources tag: <UserControl.Resources> <CollectionViewSource x:Key="TestCVS"> <CollectionViewSource.SortDescriptions> <scm:SortDescription PropertyName="Value" Direction="Ascending" /> </CollectionViewSource.SortDescriptions> </CollectionViewSource> </UserControl.Resources> Then I'm binding my TestCVS in a HierarchicalDataTemplate: <common:HierarchicalDataTemplate ItemsSource="{Binding Source={StaticResource TestCVS}}"> <common:HierarchicalDataTemplate.ItemTemplate> <common:HierarchicalDataTemplate> <Border BorderBrush="#FF464646" BorderThickness="1" CornerRadius="3" Padding="5"> <Grid> <Grid.RowDefinitions> <RowDefinition /> <RowDefinition /> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition Width="Auto"/> <ColumnDefinition Width="*"/> </Grid.ColumnDefinitions> <StackPanel Orientation="Horizontal" HorizontalAlignment="Left"> <TextBlock TextWrapping="Wrap" Text="{Binding MyClassField}"/> </StackPanel> </Grid> </Border> </common:HierarchicalDataTemplate> </common:HierarchicalDataTemplate.ItemTemplate> </common:HierarchicalDataTemplate> Now, in the code behind I'm assigning the Source for the TestCVS in a property, like this: private ObservableCollection<MyClass> _MyClass; public ObservableCollection<MyClass> MyClass { get { return _MyClass; } set { var testCVS = (this.Resources["TestCVS"] as CollectionViewSource); if (testCVS != null) testCVS.Source = value; } } After testing this I realize that the information is not showing on screen and I don't really know why, can anyone help me on this matter? Hope this makes any sense, thanks in advance!

    Read the article

  • WPF TreeViewItem + Change the Highlight Color

    - by flurreh
    Hello, I have got a TreeView with a HierarchicalDataTemplate. <HierarchicalDataTemplate x:Key="treeViewItemTemplate" ItemsSource="{Binding GetChildren}"> <DockPanel Margin="0,8,8,0"> <Image Source="{Binding GetImage}" Width="16" Height="16" /> <local:MonitorTriStateCheckBox Margin="4,0,0,0" IsChecked="{Binding IsChecked}" Click="CheckBox_Clicked" Tag="{Binding UniqueKey}" Style="{DynamicResource CheckBox}"></local:MonitorTriStateCheckBox> <TextBlock Margin="4,0,0,0" Text="{Binding Name}" Style="{DynamicResource TextBlock}"> </TextBlock> </DockPanel> <HierarchicalDataTemplate.Triggers> <Trigger Property="TreeViewItem.IsSelected" Value="True"> <Setter Property="TreeViewItem.Background" Value="Orange" /> </Trigger> </HierarchicalDataTemplate.Triggers> </HierarchicalDataTemplate> As you can see in the code, i set the is selected Trigger of the TreeViewItem, but this has no effect. I alos tried this: <TreeView.ItemContainerStyle> <Style TargetType="{x:Type TreeViewItem}"> <Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay}" /> <Setter Property="Visibility" Value="{Binding IsVisible, Mode=TwoWay}" /> <Style.Triggers> <Trigger Property="IsSelected" Value="True"> <Setter Property="Background" Value="Orange" /> </Trigger> </Style.Triggers> </Style> </TreeView.ItemContainerStyle> But that had no effect either. Has anyone got an idea what to do, to change the hightlight color of a TreeViewItem?

    Read the article

  • WPF MenuItem.Command binding to ElementName results to System.Windows.Data Error: 4 : Cannot find so

    - by e28Makaveli
    I have the following XAML: <UserControl x:Class="EMS.Controls.Dictionary.TOCControl" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:vm="clr-namespace:EMS.Controls.Dictionary.Models" xmlns:diagnostics="clr-namespace:System.Diagnostics;assembly=WindowsBase" x:Name="root" > <TreeView x:Name="TOCTreeView" Background="White" Padding="3,5" ContextMenuOpening="TOCTreeView_ContextMenuOpening" ItemsSource="{Binding Children}" BorderBrush="{x:Null}" > <TreeView.ItemTemplate> <HierarchicalDataTemplate ItemsSource="{Binding Path=Children, Mode=OneTime}"> <Grid > <Grid.ColumnDefinitions> <ColumnDefinition Width="Auto"/> <!--<ColumnDefinition Width="Auto"/>--> <ColumnDefinition Width="*"/> </Grid.ColumnDefinitions> <!--<CheckBox VerticalAlignment="Center" IsChecked="{Binding IsVisible}"/>--> <ContentPresenter Grid.Column="0" Height="16" Width="20" Content="{Binding LayerRepresentation}" /> <!--<ContentPresenter Grid.Column="1" > <ContentPresenter.Content> Test </ContentPresenter.Content> </ContentPresenter>--> <TextBlock Grid.Column="2" FontWeight="Normal" Text="{Binding Path=Alias, Mode=OneWay}" > <ToolTipService.ToolTip> <TextBlock Text="{Binding Description}" TextWrapping="Wrap"/> </ToolTipService.ToolTip> </TextBlock> </Grid> <HierarchicalDataTemplate.ItemTemplate> <HierarchicalDataTemplate ItemsSource="{Binding Path=Children, Mode=OneTime}"> <!--<DataTemplate>--> <Grid > <Grid.ColumnDefinitions> <ColumnDefinition Width="Auto"/> <ColumnDefinition Width="Auto"/> <ColumnDefinition Width="*"/> </Grid.ColumnDefinitions> <CheckBox VerticalAlignment="Center" IsChecked="{Binding IsVisible}"/> <ContentPresenter Grid.Column="1" Content="{Binding LayerRepresentation, Mode=OneWay}" /> <TextBlock Margin="0,1,0,1" Text="{Binding Path=Alias, Mode=OneWay}" Grid.Column="2"> <ToolTipService.ToolTip> <TextBlock Text="{Binding Description}" TextWrapping="Wrap"/> </ToolTipService.ToolTip> </TextBlock> </Grid> <!--</DataTemplate>--> </HierarchicalDataTemplate> </HierarchicalDataTemplate.ItemTemplate> </HierarchicalDataTemplate> </TreeView.ItemTemplate> <TreeView.ContextMenu> <ContextMenu> <MenuItem Name="miRemove" Header="Remove" Command="{Binding ElementName=root, Path=RemoveItemCmd, diagnostics:PresentationTraceSources.TraceLevel=High}"> <MenuItem.Icon> <Image Source="../images/16x16/Delete.png"/> </MenuItem.Icon> </MenuItem> <MenuItem Header="Properties" Command="{Binding ElementName=root, Path=GetItemPropertiesCmd}"/> </ContextMenu> </TreeView.ContextMenu> </TreeView> </UserControl> Code behind for this UserControl has two ICommand properties with names: RemoveItemCmd and GetItemPropertiesCmd. However, I get System.Windows.Data Error: 4 : Cannot find source for binding with reference 'ElementName=root'. BindingExpression:Path=RemoveItemCmd; DataItem=null; target element is 'MenuItem' (Name='miRemove'); target property is 'Command' (type 'ICommand') System.Windows.Data Error: 4 : Cannot find source for binding with reference 'ElementName=root'. BindingExpression:Path=GetItemPropertiesCmd; DataItem=null; target element is 'MenuItem' (Name=''); target property is 'Command' (type 'ICommand') when UserControl is constructed. Why is this and how do I resolve?

    Read the article

  • ObservableCollection is not updating Multibinding in C# WPF

    - by Decept
    I have a TreeView that creates all its items from databound ObservableCollections. I have a hierarchy of GameNode objects, each object has two ObservableCollections. One collections has EntityAttrib objects and the other have GameNode objects. You could say that the GameNode object represents folders and EntityAttrib represents files. To display both attrib and GameNodes in the same TreeView I use Multibinding. This all works fine in startup, but when I add a new GameNode somewhere in the hierarchy the TreeView is not updated. I set a breakpoint in my converter method but it's not called when adding a new GameNode. It seems that the ObservableCollection is not notifying the MultiBinding of the change. If I comment out the MultiBinding and only bind the GameNode collection it works as expected. XAML: <HierarchicalDataTemplate DataType="{x:Type local:GameNode}"> <HierarchicalDataTemplate.ItemsSource> <MultiBinding Converter="{StaticResource combineConverter}"> <Binding Path="Attributes" /> <Binding Path="ChildNodes" /> </MultiBinding> </HierarchicalDataTemplate.ItemsSource> <TextBlock Text="{Binding Path=Name}" ContextMenu="{StaticResource EntityCtxMenu}"/> </HierarchicalDataTemplate> C#: public class GameNode { string mName; public string Name { get { return mName; } set { mName = value; } } GameNodeList mChildNodes = new GameNodeList(); public GameNodeList ChildNodes { get { return mChildNodes; } set { mChildNodes = value; } } ObservableCollection<EntityAttrib> mAttributes = new ObservableCollection<EntityAttrib>(); public ObservableCollection<EntityAttrib> Attributes { get { return mAttributes; } set { mAttributes = value; } } } GameNodeList is a subclassed ObservableCollection

    Read the article

  • WPF Control Background under GridViewColumn

    - by sergo_lsn
    Hi, I'd like make background for colums like in this image http://www.freeimagehosting.net/image.php?e2435df982.png I have CheckBoxes on the left and TreeView on the right. In one column I have checkboxes in other I have treeview. In column with checkboxes I need set background. Background has to be permanent. .... </DataTemplate> </GridViewColumn.CellTemplate> </GridViewColumn> <GridViewColumn Width="25"> All column has to have background not only cell <GridViewColumn.CellTemplate> <DataTemplate> <CheckBox> <CheckBox.Resources> <ResourceDictionary> <ResourceDictionary.MergedDictionaries> .... </ResourceDictionary.MergedDictionaries> </ResourceDictionary> </CheckBox.Resources> </CheckBox> </DataTemplate> </GridViewColumn.CellTemplate> </GridViewColumn> </GridViewColumn> <GridViewColumn Width="300"/> </TreeListView.Columns> <TreeListView.Resources> <ResourceDictionary> <ResourceDictionary.MergedDictionaries> ... TreeView.xaml </ResourceDictionary.MergedDictionaries> </ResourceDictionary> </TreeListView.Resources> <TreeListView.ItemTemplate> <HierarchicalDataTemplate> <HierarchicalDataTemplate.ItemsSource> .... </HierarchicalDataTemplate.ItemsSource> </HierarchicalDataTemplate> </TreeListView.ItemTemplate> </TreeListView>

    Read the article

  • Bind to a method in WPF?

    - by Cameron MacFarland
    How do you bind to an objects method in this scenario in WPF? public class RootObject { public string Name { get; } public ObservableCollection<ChildObject> GetChildren() {...} } public class ChildObject { public string Name { get; } } XAML: <TreeView ItemsSource="some list of RootObjects"> <TreeView.Resources> <HierarchicalDataTemplate DataType="{x:Type data:RootObject}" ItemsSource="???"> <TextBlock Text="{Binding Path=Name}" /> </HierarchicalDataTemplate> <HierarchicalDataTemplate DataType="{x:Type data:ChildObject}"> <TextBlock Text="{Binding Path=Name}" /> </HierarchicalDataTemplate> </TreeView.Resources> </TreeView> Here I want to bind to the GetChildren method on each RootObject of the tree. EDIT Binding to an ObjectDataProvider doesn't seem to work because I'm binding to a list of items, and the ObjectDataProvider needs either a static method, or it creates it's own instance and uses that. For example, using Matt's answer I get: System.Windows.Data Error: 33 : ObjectDataProvider cannot create object; Type='RootObject'; Error='Wrong parameters for constructor.' System.Windows.Data Error: 34 : ObjectDataProvider: Failure trying to invoke method on type; Method='GetChildren'; Type='RootObject'; Error='The specified member cannot be invoked on target.' TargetException:'System.Reflection.TargetException: Non-static method requires a target.

    Read the article

  • WPF HiercharchicalDataTemplate.DataType: How to react on interfaces?

    - by David Schmitt
    Problem I've got a collection of IThings and I'd like to create a HierarchicalDataTemplate for a TreeView. The straightforward DataType={x:Type local:IThing} of course doesn't work, probably because the WPF creators didn't want to handle the possible ambiguities. Since this should handle IThings from different sources at the same time, referencing the implementing class is out of question. Current solution For now I'm using a ViewModel which proxies IThing through a concrete implementation: public interface IThing { string SomeString { get; } ObservableCollection<IThing> SomeThings { get; } // many more stuff } public class IThingViewModel { public IThing Thing { get; } public IThingViewModel(IThing it) { this.Thing = it; } } <!-- is never applied --> <HierarchicalDataTemplate DataType="{x:Type local:IThing}"> <!-- is applied, but looks strange --> <HierarchicalDataTemplate DataType="{x:Type local:IThingViewModel}" ItemsSource="{Binding Thing.SomeThings}"> <TextBox Text="{Binding Thing.SomeString}"/> </HierarchicalDataTemplate> Question Is there a better (i.e. no proxy) way?

    Read the article

  • Is it possible to template a template in WPF XAML?

    - by imekon
    Is it possible to use templates within templates? For instance, I have the following two templates: <HierarchicalDataTemplate x:Key="RecursiveTemplate" ItemsSource="{Binding Children}"> <StackPanel Margin="1" Orientation="Horizontal"> <Ellipse Fill="DarkGreen" Width="14" Height="14"/> <TextBlock MouseDown="OnTreeMouseDown" TargetUpdated="OnTargetUpdated" Visibility="{Binding Editing, Converter={StaticResource visibilityInverter}}" Margin="5" Text="{Binding Name}"/> <TextBox PreviewKeyDown="OnTreeKeyDown" Visibility="{Binding Editing, Converter={StaticResource visibilityConverter}}" Margin="2" Text="{Binding Name}"/> </StackPanel> </HierarchicalDataTemplate> <HierarchicalDataTemplate x:Key="ContainerTemplate" ItemsSource="{Binding Children}"> <StackPanel Margin="1" Orientation="Horizontal"> <Ellipse Fill="DarkBlue" Width="14" Height="14"/> <TextBlock MouseDown="OnTreeMouseDown" TargetUpdated="OnTargetUpdated" Visibility="{Binding Editing, Converter={StaticResource visibilityInverter}}" Margin="5" Text="{Binding Name}"/> <TextBox PreviewKeyDown="OnTreeKeyDown" Visibility="{Binding Editing, Converter={StaticResource visibilityConverter}}" Margin="2" Text="{Binding Name}"/> </StackPanel> </HierarchicalDataTemplate> There's a section of identical XAML: <TextBlock MouseDown="OnTreeMouseDown" TargetUpdated="OnTargetUpdated" Visibility="{Binding Editing, Converter={StaticResource visibilityInverter}}" Margin="5" Text="{Binding Name}"/> <TextBox PreviewKeyDown="OnTreeKeyDown" Visibility="{Binding Editing, Converter={StaticResource visibilityConverter}}" Margin="2" Text="{Binding Name}"/> Is it possible to move that to a resource and refer to it by name, rather than repeat it?

    Read the article

  • silverlight treeview not loading subitems

    - by Jakob
    I'm interested in finding out why this isn't working: I have a treeview with some hierarchicaldatatemplates looking like this: <UserControl.Resources> <sdk:HierarchicalDataTemplate x:Key="nodeEntry"> <StackPanel Orientation="Horizontal"> <TextBlock Text="{Binding Path=Title}" /> </StackPanel> </sdk:HierarchicalDataTemplate> <sdk:HierarchicalDataTemplate x:Key="rootEntry" ItemsSource="{Binding Path=Nodes}" ItemTemplate="{StaticResource nodeEntry}"> <StackPanel Orientation="Horizontal"> <TextBlock Text="{Binding Path=Name}" /> </StackPanel> </sdk:HierarchicalDataTemplate> </UserControl.Resources> <sdk:TreeView Height="250" HorizontalAlignment="Left" ItemTemplate="{StaticResource rootEntry}" ItemsSource="{Binding ElementName=subjectDomainDataSource, Path=Data}" Name="rootTreeView" VerticalAlignment="Top" Width="180"/> The data is passed to the treeview from a domainservice using this method: public IEnumerable<Subject> GetSubjectList(Guid userid) { DataLoadOptions loadopts = new DataLoadOptions(); loadopts.LoadWith<Root>(s => s.Nodes); this.DataContext.LoadOptions = loadopts; return this.DataContext.Roots; } why then are only the root nodes shown in the treeview as if it only loaded a flat list, and not a hierarchy where the root Loads the NodesCollection?

    Read the article

1 2 3  | Next Page >