index > Windows Presentation Foundation ("Avalon") > How To Get Element within a Listview CellTemplate

How To Get Element within a Listview CellTemplate

Hi,

In my application, I've an Listview:

<ContentControl Margin="5,0,5,5" Grid.Row="1" x:Name="MasterPane" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" RenderTransformOrigin="0.5,0.5" Template="{DynamicResource PanelTemplate}">

<ListView x:Name="MasterList" SelectionMode="Single" SelectionChanged="ChangeListViewSelectedItem" Width="Auto" Height="Auto" RenderTransformOrigin="0.5,0.5" ItemsSource="{Binding Mode=Default}" SelectedIndex="-1" Background="{x:Null}" BorderBrush="{x:Null}" Foreground="#FFFFFFFF" IsSynchronizedWithCurrentItem="True">

<ListView.View>

<GridView AllowsColumnReorder="True">

<GridView.ColumnHeaderContainerStyle>

<Style>

<Setter Property="GridViewColumnHeader.Template">

<Setter.Value>

<ControlTemplate TargetType="{x:Type GridViewColumnHeader}">

<Border Style="{StaticResource ListviewHeaderStyle}">

<Button Name="ColumnHeaderSortAndGroupButton" Click="ColumnHeaderSortAndGroupButton_Click" Content="{TemplateBinding GridViewColumnHeader.Content}" VerticalAlignment="Center" HorizontalAlignment="Center" VerticalContentAlignment="Center" Background="Transparent" BorderBrush="Transparent" BorderThickness="0" Foreground="White" />

</Border>

</ControlTemplate>

</Setter.Value>

</Setter>

</Style>

</GridView.ColumnHeaderContainerStyle>

<GridViewColumn Header="Produit" DisplayMemberBinding="{Binding ProductName}" Width="140" />

<GridViewColumn Header="Taille" CellTemplate="{StaticResource ListViewSizeColumn}" Width="50" />

<GridViewColumn x:Name="ImageColumn" Header="Media" CellTemplate="{StaticResource ListViewCheckBoxColumn}" Width="50" />

</GridView>

</ListView.View>

<ListView.GroupStyle>

<GroupStyle HeaderTemplate="{StaticResource GroupHeaderTemplate}" HidesIfEmpty="True" />

</ListView.GroupStyle>

</ListView>

</ContentControl>

With the DataTemplate shown below:

<DataTemplate x:Key="ListViewCheckBoxColumn">

<CheckBox Name="chkOffline" HorizontalAlignment="Center" />

</DataTemplate>

Using VisualTreeHelper on a item of my Listview, I know how I can get the checkbox for this specific item.

But in m case, I would like to get all the item. Indeed, my goal is to implement a "Check All/UnCheck All" part but I don't know how I can change the IsChecked property for each checkbox in my template....

Any ideas ?

Thanks




Blog on WPF / C# / .NET: http://blogs.developpeur.org/tom | Site: http://morpheus.developpez.com
Thomas LEBRUN

This blog entry shows how to solve a similar problem: http://www.infusionblogs.com/blogs/jsmith/archive/2006/08/13/720.aspx Specifically, check out the GetCheckBoxFromListBoxItem method.

HTH




Josh Smith - http://www.infusionblogs.com/blogs/jsmith/default.aspx
Josh Smith

Yes, I've already seen that post.

But this is in the case when you want to find the CheckBox in a particular ListView/ListBox item.

In my case, I want to find the CheckBox for all the item so unless doind a boucle (but I hope it will not bad for my application performance), I don't know how I can do.....




Blog on WPF / C# / .NET: http://blogs.developpeur.org/tom | Site: http://morpheus.developpez.com
Thomas LEBRUN
I was thinking that you might use the logic in the GetCheckBoxFromListBoxItem method in a loop, where you interate over every item in the ListView. It looks like Lee D has already solved this puzzle, though. :)


Josh Smith - http://www.infusionblogs.com/blogs/jsmith/default.aspx
Josh Smith

this might also help

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=622143&SiteID=1

lee d
I was going to say that I was sure that I saw that before...of course it was lee who solved it...what an overachiever man...


What's in your toolbelt? http://www.codeplex.com/Wiki/View.aspx?ProjectName=wpftoolbelt
ivolved_Mike_Brown
reply 6

You can use google to search for other answers

 

More Articles

• AutoScrolling Text in a ListBox?? Help Please
• BAML stream has version number '0.96' but parser can read only ve...
• Override properties set manualy with resourcedictionary.
• Introduction to XAML
• How do you walk the controls in a XAML page?
• MouseMove event handler delay
• Newest Interactive Designer xaml code compatibility ?!?!?!?
• Navigation between pages
• DropDown Menu Buttons
• Loading complete xaml files at runtime.
Bookmark and Share
Welcome to Bokebb   New Update  
 

New Articles

• Basic image issues.
• Bug when MouseLeave Event in ControlTemp
• Expression designer like docking
• How to use multiple filters on Items? (B
• How get click event from button embedded
• How to get the 2nd Window2 to Appear on
• PrintTicket.PageOrientation does not hav
• RichTextBox, turn off the Keyboard-langu
• Return XPS document from a web service
• Tricky: items with ARRAYs as properties:
• Session ID equivalent in XBAP
• Bug Fixes
• How to Bind to an ADO.NET Data Source.
• animate listbox items to scroll
• Reading Bitmap Pixel Colors very fast; M

Hot Articles

• WPF RichTextBox paste bug ???
• WPF in Vista OS applications?
• Polygon.Points Binding TwoWay
• VS.NET dockable tab groups in WPF?
• Possible BlockCollection bug - Need clar
• How is the control to which externals ar
• Intellisense in code behind
• Clocks and timelines and storyboards wit
• IRC Help Channel!
• TextRange
• TemplateBinding bug?
• Bug ? The Enabled control is not effecti
• TextBox in DataTeplate...
• Right-aligned pane in a StatusBar
• Z-order

Recommend Articles

• Scroll a ListView to bottom?
• Making NavigationUI frame specific
• Is there a wizard framework?
• XAML RSS Reader problem
• forms authentication with wba
• How to auto-size ListView column headers
• Override properties set manualy with res
• Best approach to overlay 3D effects on c
• Set Focus / Selection to child item
• PrintTicket.PageOrientation does not hav
• Setting foreground and background to be
• Next CTP Version for Orcas Tools
• error when hosting WPF control inside of
• WPF Text Box (Allowing only HH:MM:SS)
• Very slow grouping