Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to get data using ListView Binding via MVVM in wpf?
    primarykey
    data
    text
    <p>i try to use generate MVVM pattern using Silverlight ListView. But if i bind data my silverlight control no data visualize. also no error return. i see empty gridview.</p> <h3>Model:</h3> <p><b>MyData.cs</b></p> <pre><code> public class MyData { public int ID { get; set; } public string Name { get; set; } public string Price { get; set; } public string Author { get; set; } public string Catalog { get; set; } } </code></pre> <h3>View:</h3> <p><b>BookViewer.xaml</b></p> <pre><code> &#60;UserControl x:Class="wpf.MVVM.Project.View.BookViewer" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Height="500" Width="700"&#62; &#60;Grid&#62; &#60;StackPanel&#62; &#60;ListView Margin="8" Height="400" Width="650" ItemsSource="{Binding Path=MyData}"&#62; &#60;ListView.View&#62; &#60;GridView &#62; &#60;GridViewColumn Header="ID" Width="Auto"&#62; &#60;GridViewColumn.CellTemplate&#62; &#60;DataTemplate&#62; &#60;TextBlock Text="{Binding ID}" TextAlignment="Right" Width="40"/&#62; &#60;/DataTemplate&#62; &#60;/GridViewColumn.CellTemplate&#62; &#60;/GridViewColumn&#62; &#60;GridViewColumn DisplayMemberBinding="{Binding Path=Name}" Header="Name" Width="100"/&#62; &#60;GridViewColumn DisplayMemberBinding="{Binding Path=Price}" Header="Price" Width="100"/&#62; &#60;GridViewColumn DisplayMemberBinding="{Binding Path=Author}" Header="Author" Width="100"/&#62; &#60;GridViewColumn DisplayMemberBinding="{Binding Path=Catalog}" Header="Catalog" Width="100"/&#62; &#60;/GridView&#62; &#60;/ListView.View&#62; &#60;/ListView&#62; &#60;/StackPanel&#62; &#60;/Grid&#62; &#60;/UserControl&#62; </code></pre> <h3>ViewModel:</h3> <p><b>MyDataViewModel.cs</b></p> <pre><code> public class MyDataViewModel { // public ObservableCollection&#60;MyData&#62; myData { get; set; } public List&#60;MyData&#62; GetData() { List&#60;MyData&#62; myDataList = new List&#60;MyData&#62;(); myDataList.Add(new MyData() { ID = 1, Name = "yusuf karatoprak", Author = "Mike Gold", Price = "6.7 TL", Catalog = "IT" }); myDataList.Add(new MyData() { ID = 2, Name = "yusuf karatoprak", Author = "Scott Gunitella", Price = "9.7 TL", Catalog = "IT" }); myDataList.Add(new MyData() { ID = 3, Name = "yusuf karatoprak", Author = "David Hayden", Price = "11.7 TL", Catalog = "IT" }); if (myDataList.Count &#62; 0) { return myDataList; } else return null; } } </code></pre> <h3>Window1.xaml</h3> <pre><code> public partial class Window1 : Window { public Window1() { InitializeComponent(); } private void Window_Loaded(object sender, RoutedEventArgs e) { MyDataViewModel myDataCtx = new MyDataViewModel(); MyDataDataView.DataContext = myDataCtx.GetData(); } }</code></pre> <pre><code> &#60;Window x:Class="wpf.MVVM.Project.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Window1" Height="1000" Width="900" xmlns:views="clr-namespace:wpf.MVVM.Project.View" Loaded="Window_Loaded"&#62; &#60;Grid&#62; &#60;views:BookViewer x:Name="MyDataDataView" Margin="0,0,0,0"&#62;&#60;/views:BookViewer&#62; &#60;/Grid&#62; &#60;/Window&#62; </code></pre> <p>i writed these codes but no data i can see.Look below:</p> <p><img src="https://i.stack.imgur.com/98mL9.png" alt="alt text"></p> <h3>i added 2 pics my debug mode:</h3> <p><img src="https://i.stack.imgur.com/ALnbO.png" alt="alt text"> <img src="https://i.stack.imgur.com/HqdBS.png" alt="alt text"></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload