Click here to Skip to main content
15,897,273 members
Please Sign up or sign in to vote.
4.00/5 (2 votes)
See more:
Hi!
I’m a beginner when it comes to WPF so please forgive me.
I need a grid which binds to two objects as datasources and occasionally updates the content
I took http://www.switchonthecode.com/tutorials/wpf-tutorial-using-the-listview-part-1 as an example which works perfectly

XML
<Window x:Class="WpfApplication17.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        DataContext="{Binding RelativeSource={RelativeSource Self}}"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <StackPanel>
            <ListView Name="MyListview" ItemsSource="{Binding GameCollection}">
                <ListView.View>
                    <GridView>
                        <GridViewColumn Width="140" Header="Game Name" DisplayMemberBinding="{Binding GameName}"  />
                        <GridViewColumn Width="140" Header="Creator" DisplayMemberBinding="{Binding Creator}" />
                        <GridViewColumn Width="140" Header="Publisher" DisplayMemberBinding="{Binding Publisher}" />
                    </GridView>
                </ListView.View>
            </ListView>
            <Button HorizontalAlignment="Right" Margin="5,5,5,5" Content="Add Row" Click="AddRow_Click" />
        </StackPanel>
    </Grid>
</Window>


However I have problems with the following lines
DataContext="{Binding RelativeSource={RelativeSource Self}}";

Please be so nice and explain this line to me.
How do I rewrite the code without the RelativeSource binding in code-behind and add two sources to the grid



Any help is appreciated

Thanks you in advance!


Mat
Posted

1 solution

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900