Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. WCF and WF
  4. Binding cells in ListView

Binding cells in ListView

Scheduled Pinned Locked Moved WCF and WF
wpfdatabasewcfcomxml
4 Posts 2 Posters 3 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    AAKAra
    wrote on last edited by
    #1

    Is there a way i could bind each cell in the ListViewItem to a different Property? <Window x:Class="SDKSample.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <Window.Resources> <!--Define data for ListView--> <XmlDataProvider x:Key="MyData" XPath="/Info"> <x:XData> <Info xmlns=""> <AccessEvents Name="A" /> <AccessEvents Name="B" /> <AccessEvents Name="C"/> </Info> </x:XData> </XmlDataProvider> <Style x:Key="MyContainer" TargetType="{x:Type ListViewItem}"> <Setter Property="Margin" Value="0,1,0,0"/> <Setter Property="Height" Value="21"/> <Style.Triggers> <Trigger Property="IsMouseOver" Value="true"> <Setter Property="Foreground" Value="Blue" /> <Setter Property="Cursor" Value="Hand"/> </Trigger> <MultiTrigger> <MultiTrigger.Conditions> <Condition Property="IsSelected" Value="true" /> <Condition Property="Selector.IsSelectionActive" Value="true" /> </MultiTrigger.Conditions> <Setter Property="Foreground" Value="Yellow" /> </MultiTrigger> </Style.Triggers> </Style> <DataTemplate x:Key="SecondCell"> <StackPanel Orientation="Horizontal"> <CheckBox IsChecked="{Binding Path=IsSelected, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListViewItem}}}"/> </StackPanel> </DataTemplate> <!--</SnippetCheckBoxDataTemplate>--> </Window.Resources> <StackPanel> <TextBlock Foreground="Blue" FontSize="14" Margin="10,10,0,0"> Select Song to Play </TextBlock> <!--<SnippetListView>--> <ListView ItemsSource="{Binding Source={StaticResource MyData}, XPath=AccessEvents}" ItemContainerStyle="{StaticResource MyContainer}" SelectionChanged="mySelectionChanged" SelectionMode="Single" Name="myPlaylist" Margin="10,10,0,0"> <ListView.View> <GridView> <!--<SnippetGridViewColumnCheckBox>-->

    M 1 Reply Last reply
    0
    • A AAKAra

      Is there a way i could bind each cell in the ListViewItem to a different Property? <Window x:Class="SDKSample.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <Window.Resources> <!--Define data for ListView--> <XmlDataProvider x:Key="MyData" XPath="/Info"> <x:XData> <Info xmlns=""> <AccessEvents Name="A" /> <AccessEvents Name="B" /> <AccessEvents Name="C"/> </Info> </x:XData> </XmlDataProvider> <Style x:Key="MyContainer" TargetType="{x:Type ListViewItem}"> <Setter Property="Margin" Value="0,1,0,0"/> <Setter Property="Height" Value="21"/> <Style.Triggers> <Trigger Property="IsMouseOver" Value="true"> <Setter Property="Foreground" Value="Blue" /> <Setter Property="Cursor" Value="Hand"/> </Trigger> <MultiTrigger> <MultiTrigger.Conditions> <Condition Property="IsSelected" Value="true" /> <Condition Property="Selector.IsSelectionActive" Value="true" /> </MultiTrigger.Conditions> <Setter Property="Foreground" Value="Yellow" /> </MultiTrigger> </Style.Triggers> </Style> <DataTemplate x:Key="SecondCell"> <StackPanel Orientation="Horizontal"> <CheckBox IsChecked="{Binding Path=IsSelected, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListViewItem}}}"/> </StackPanel> </DataTemplate> <!--</SnippetCheckBoxDataTemplate>--> </Window.Resources> <StackPanel> <TextBlock Foreground="Blue" FontSize="14" Margin="10,10,0,0"> Select Song to Play </TextBlock> <!--<SnippetListView>--> <ListView ItemsSource="{Binding Source={StaticResource MyData}, XPath=AccessEvents}" ItemContainerStyle="{StaticResource MyContainer}" SelectionChanged="mySelectionChanged" SelectionMode="Single" Name="myPlaylist" Margin="10,10,0,0"> <ListView.View> <GridView> <!--<SnippetGridViewColumnCheckBox>-->

      M Offline
      M Offline
      MIHAI_MTZ
      wrote on last edited by
      #2

      First you need to think if you really need to do this. It seems a bit odd what you want. One way to do it, is using a template selector (DataTemplateSelector to be more precise). With this thing you can create several templates and, based on some properties of the object you are binding to (in this case "Name"), select one of them. Of course this only works if you only have a few templates... Here's a nice example: http://www.beacosta.com/blog/?p=16[^] Mihai,

      A 1 Reply Last reply
      0
      • M MIHAI_MTZ

        First you need to think if you really need to do this. It seems a bit odd what you want. One way to do it, is using a template selector (DataTemplateSelector to be more precise). With this thing you can create several templates and, based on some properties of the object you are binding to (in this case "Name"), select one of them. Of course this only works if you only have a few templates... Here's a nice example: http://www.beacosta.com/blog/?p=16[^] Mihai,

        A Offline
        A Offline
        AAKAra
        wrote on last edited by
        #3

        Yes I would go for ItemDataTemplate, this is what I need I have a list of strings and a list of checkbox like this A, Checkbox Hello B, CheckBox Hi C, CheckBox Bye How do i show it in a ListView? Thanks In Advance

        M 1 Reply Last reply
        0
        • A AAKAra

          Yes I would go for ItemDataTemplate, this is what I need I have a list of strings and a list of checkbox like this A, Checkbox Hello B, CheckBox Hi C, CheckBox Bye How do i show it in a ListView? Thanks In Advance

          M Offline
          M Offline
          MIHAI_MTZ
          wrote on last edited by
          #4

          Like this:

          <Window x:Class="SDKSample.Window1"
          xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
          xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
          <Window.Resources>
          
          <XmlDataProvider x:Key="MyData" XPath="/Info">
          	<x:XData>
          		<Info xmlns="">
          			<AccessEvents Name="A" Text="Hello"/>
          			<AccessEvents Name="B" Text="Hi" />
          			<AccessEvents Name="C" Text="Bye" />
          		</Info>
          	</x:XData>
          </XmlDataProvider>
          
          <DataTemplate x:Key="SecondCell">
          	<CheckBox IsChecked="{Binding Path=IsSelected, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListViewItem}}}" Content ="{Binding XPath=@Text}"/>
          </DataTemplate>
          
          </Window.Resources>
          
          <ListView ItemsSource="{Binding Source={StaticResource MyData}, XPath=AccessEvents}" >
          	<ListView.View>
          		<GridView>
          			<GridViewColumn Header="Access Event" DisplayMemberBinding="{Binding XPath=@Name}" Width="150"/>
          			<GridViewColumn Header="Deliver" CellTemplate="{StaticResource SecondCell}" Width="80"/>
          		</GridView>
          	</ListView.View>
          </ListView>
          </Window>
          
          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups