views:

1395

answers:

2

ok, sorry for the overly broad question, but lets see what you guys suggest..

I have a WPF ListView loaded by an XML file, using XAML (code below)

I have a second xml file with items that match what is in my ListView. However, if there is not a match in the 2nd file, then i want that listitem disabled.

a simple example:

my ListView has in it:

                   Joe
                   Fred
                   Jim

(because it was loaded with the first xml file)

my 2nd xml file has, essentially:

                  Joe
                  Jim

I want the ListView to somehow consume this second file as well & disable "Fred"

I am assuming that it would be some sort of "Filter" I would apply somewhere in XAML.

 <ListView Margin="11,93,0,12" 
     ItemsSource="{Binding}"
     SelectionMode="Multiple"
     Name="lvwSourceFiles" Cursor="Hand" TabIndex="6" VerticalContentAlignment="Center" SelectionChanged="lvwSourceFiles_SelectionChanged" HorizontalAlignment="Left" Width="306">
  <ListBox.DataContext>
   <XmlDataProvider x:Name="xmlSourceFiles" XPath="AssemblyUpdaterSource/sources/source/File" />
  </ListBox.DataContext>
  <ListView.ItemContainerStyle>
   <Style TargetType="{x:Type ListViewItem}">
    <EventSetter Event="PreviewMouseRightButtonDown"
                                         Handler="OnSourceListViewItemPreviewMouseRightButtonDown" />
   </Style>
  </ListView.ItemContainerStyle>
 </ListView>
+3  A: 

My solution is not so simple, you need to create a dataTemplate for the items in the list. the data template should have a datatrigger, that means that you need to have some kind of property in the itemssource that tells you if the item exists in the other xml file.

so what i'm trying to say is that u need to read the xml file from code and generate your own custom class that will contain the name prop and the Exists property and bind it to the other file,

another solution that i thought of wile i was writing the answer is to bind the isenabled property of the item to a converter that will get the name and check the other file and return a boolean.

Chen Kinnrot
@Chen could you give an example of how to bind to a converter like that?
KevinDeus
Not necessarily. You do not need to use a DataTemplate for this. The binding with converter can be done in the ItemContainerStyle.
Charlie
A: 
Charlie