I am using the folloowing class but its not allowing me to display show_times in my xaml its just comming up
popcornpk.datamodel.fetchtiming
public class FetchTiming
{
public string id { get; set; }
public string theater_name { get; set; }
public string address { get; set; }
public List<string> show_times { get; set; }
public string screen_id { get; set; }
public string title { get; set; }
}
public class MovieDetail
{
public MovieDetails movie_details { get; set; }
public List<FetchTiming> fetch_timing { get; set; }
}
My Class call
public async Task<MovieDetail> GetMovieShowtimesAsync()
{
string jsonresult = await WCFRESTServiceCall("GET", "movie_details");
var jarray = JsonConvert.DeserializeObject<MovieDetail>(jsonresult);
return jarray;
}
This is my xamlmethod call I hav eno idea what is going on the data is being returned ok but I just cant seem to dispaly it
private async void listViewShowtimes_Loaded(object sender, RoutedEventArgs e)
{
popcornpk_Dal _dal = new popcornpk_Dal();
MovieDetail _showTimes = await _dal.GetMovieShowtimesAsync();
var listView = (ListView)sender;
listView.ItemsSource = _showTimes.fetch_timing.ToList();
}
Xaml Of DataTemplate
<PivotItem x:Name="pvtShowTimes" Header="showtimes">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<ListView x:Name="listViewShowtimes" ItemsSource="{Binding}" Loaded="listViewShowtimes_Loaded">
<DataTemplate>
<StackPanel Height="505">
<TextBlock FontSize="13" x:Name="txtshowtime" Text="{Binding theater_name}" HorizontalAlignment="Left" Margin="19,223,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="212" Foreground="White" Height="29" SelectionChanged="txtTtile_SelectionChanged"/>
<TextBlock FontSize="13" x:Name="txtshow_times" Text="{Binding address}" HorizontalAlignment="Left" Margin="19,223,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="212" Foreground="White" Height="29" SelectionChanged="txtTtile_SelectionChanged"/>
</StackPanel>
</DataTemplate>
</ListView>
</Grid>
</PivotItem>
Below is a screen shot of the app running on the device any help be greatly apreciated.
Ok So i have it at least displaying the thertre name which is good on the show times screen but its still not allowing me to display the show_times field.
<ListView x:Name="listViewShowtimes" ItemsSource="{Binding}" Loaded="listViewShowtimes_Loaded">
<ListView.ItemTemplate>
<DataTemplate>
<Grid Grid.Row="0">
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition />
</Grid.ColumnDefinitions>
<TextBlock FontSize="13" Grid.Row="0" Grid.Column="0" x:Name="txtshowtime" Text="{Binding theater_name}" HorizontalAlignment="Left" TextWrapping="Wrap" VerticalAlignment="Top" Width="212" Foreground="White" Height="29" />
<TextBlock FontSize="13" Grid.Row="1" Grid.Column="0" x:Name="txtshow_times" Text="{Binding show_times}" HorizontalAlignment="Left" TextWrapping="Wrap" VerticalAlignment="Top" Width="212" Foreground="White" Height="29" />
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
I think what i need to no is how to bind a list of strings through xaml Problem I have i need the show times to appear below the cinema name you see their
You have Text="{Binding show_times}" so In your class FetchTiming,
public List<string> show_times { get; set; }
is a list so if you bind it to a TextBlock, it will simply do ToString(). You have to add inside the template another ListView like:
<TextBlock FontSize="13" Grid.Row="0" Grid.Column="0" x:Name="txtshowtime" Text="{Binding theater_name}" HorizontalAlignment="Left" TextWrapping="Wrap" VerticalAlignment="Top" Width="212" Foreground="White" Height="29" />
<ListView ItemsSource={Binding show_times} />
And will do the trick.
Related
this is my class TaskTodo and the method GetTask this method connect with sqlite and return a observable collection
using Microsoft.Data.Sqlite;
using System;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.IO;
using Windows.Storage;
namespace uwp_to_do_list
{
public class TaskTodo : INotifyPropertyChanged
{
public string NameTask { get; set; }
public DateTime Reminder { get; set; }
public string NameList { get; set; }
public DateTime Date { get; set; }
public string SubTask { get; set; }
public string Priority { get; set; }
public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
public ObservableCollection<TaskTodo> GetTasks()
{
var Tasks = new ObservableCollection<TaskTodo>();
//get data from sqlite3
string dbpath = Path.Combine(ApplicationData.Current.LocalFolder.Path, "TasksSqlite.db");
using (SqliteConnection db =
new SqliteConnection($"Filename={dbpath}"))
{
db.Open();
SqliteCommand selectCommand = new SqliteCommand
("SELECT Name_task from Task", db);
SqliteDataReader query = selectCommand.ExecuteReader();
while (query.Read())
{
TaskTodo taskTodo = new TaskTodo();
taskTodo.NameTask = query.GetString(0);
Tasks.Add(taskTodo);
}
db.Close();
}
return Tasks;
}
so i put this observable collection as the itemsource of listview, but this just show the type of the object not the field NameTask.
public MainView()
{
this.InitializeComponent();
TaskTodo taskTodo = new TaskTodo();
task_list.ItemsSource = taskTodo.GetTasks()
Debug.WriteLine(taskTodo.GetTasks()[4].NameTask);
}
i think the problem is in the xaml code because went i tested if the observable collection is empty
Debug.WriteLine(taskTodo.GetTasks()[4].NameTask);
the outpuy was tasxk3
my xaml code
<Page
x:Class="uwp_to_do_list.MainView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:uwp_to_do_list"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-
compatibility/2006" xmlns:fa="using:FontAwesome.UWP"
mc:Ignorable="d"
Background="#08090A"
>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="auto"></ColumnDefinition>
<ColumnDefinition Width="auto"></ColumnDefinition>
<ColumnDefinition Width="auto"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="auto"></RowDefinition>
</Grid.RowDefinitions>
<StackPanel Background="#04000E" Width="240"
Grid.Column="0"
Grid.Row="0" HorizontalAlignment="Left" >
<TextBlock Text="today" Foreground="White" FontSize="24"
HorizontalAlignment="Center" Margin="0,50,0,0">
</TextBlock>
<fa:FontAwesome Icon="CalendarCheckOutline" Height="40"
Width="40" FontSize="40" Foreground="Fuchsia"
HorizontalAlignment="Left" Margin="20,-35,0,0">
</fa:FontAwesome>
<TextBlock Text="Tomorrow" Foreground="White"
FontSize="24" HorizontalAlignment="Center"
Margin="0,20,0,0"></TextBlock>
<fa:FontAwesome Icon="CalendarOutline" Height="40"
Width="40" FontSize="40" Foreground="Fuchsia"
HorizontalAlignment="Left" Margin="20,-35,0,0">
</fa:FontAwesome>
<TextBlock Text="planning" Foreground="White"
FontSize="24" HorizontalAlignment="Center"
Margin="0,20,0,0"></TextBlock>
<fa:FontAwesome Icon="Calendar" Height="40" Width="40"
FontSize="40" Foreground="Fuchsia"
HorizontalAlignment="Left" Margin="20,-35,0,0">
</fa:FontAwesome>
<TextBlock Text="tasks" Foreground="White" FontSize="24"
HorizontalAlignment="Center" Margin="0,20,0,0">
</TextBlock>
<fa:FontAwesome Icon="Home" Height="40" Width="40"
FontSize="40" Foreground="Fuchsia"
HorizontalAlignment="Left" Margin="20,-35,0,0">
</fa:FontAwesome>
</StackPanel>
<TextBox Grid.Row="1" HorizontalAlignment="Left"
Grid.Column="0" Text="+ add a list " Background="#04000E"
Foreground="White" Height="50" Width="240" ></TextBox>
<TextBox x:Name="add_Task_textbox" Grid.Row="1"
Grid.Column="1" KeyDown="add_Task_textbox_KeyDown"
HorizontalAlignment="Center" VerticalAlignment="Center"
Text="+ add a task" Background="#04000E" Foreground="White"
Height="40" Width="1000" Margin="20,0,-20,0" />
<ListView x:Name="task_list" Grid.Row="0" Grid.Column="1"
Background="Transparent">
<ListViewItem>
<DataTemplate x:DataType="local:TaskTodo">
<TextBlock Width="100" Foreground="White" Text="{x:Bind
NameTask}"></TextBlock>
</DataTemplate>
</ListViewItem>
</ListView>
</Grid>
</Page>
for more context my github repository
You should set the ItemTemplate property to your DataTemplate instead of adding a ListViewItem:
<ListView x:Name="task_list" Grid.Row="0" Grid.Column="1"
Background="Transparent">
<ListView.ItemTemplate>
<DataTemplate x:DataType="local:TaskTodo">
<TextBlock Width="100" Foreground="White"
Text="{x:Bind NameTask}" />
</DataTemplate>
<ListView.ItemTemplate>
</ListView>
My Windows Phone app, have a ListBox populated from a collection produtos. This collection received values from a JSON.
In my ListBox, I "binding" all values from JSON (quantidade, descricao, valor_preco_a, codigo), and a another value (unidade) that it should be produtos.quantidade * produtos.valor_preco_a.
My ListBox:
<controls:PivotItem Header="Consulta" Name="consultaCartao">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<ListBox Name="List2" ItemsSource="{Binding produtosCartao}" HorizontalContentAlignment="Stretch" Grid.ColumnSpan="3" Margin="0,182,-66,0" Visibility="Collapsed">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Margin="0,0,0,17" Width="432" Height="Auto">
<StackPanel.Background>
<SolidColorBrush Color="#FFE8FF00" Opacity="0.2"/>
</StackPanel.Background>
<TextBlock Grid.Column="0" Text="{Binding descricao}" TextWrapping="Wrap" Style="{StaticResource PhoneTextNormalStyle}"/>
<TextBlock Grid.Column="3" TextWrapping="Wrap" Style="{StaticResource PhoneTextSubtleStyle}" Margin="20,5,12,0">
<Run Text="{Binding quantidade}" />
<Run Text="{Binding unidade}" />
</TextBlock>
<TextBlock Grid.Column="3" Text="{Binding valor, ConverterCulture=pt-BR, StringFormat=C2}" TextWrapping="Wrap" Style="{StaticResource PhoneTextNormalStyle}" Margin="300,-30,12,0"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
I trying with this code:
public ObservableCollection<produtos> produtosCartao { get; set; }
public class produtos
{
public double quantidade { get; set; }
public string descricao { get; set; }
public double valor_preco_a { get; set; }
public string codigo { get; set; }
public string unidade { get; set; }
public double valor { get; set; }
}
void webClient_DownloadStringCompletedProdutos(object sender, DownloadStringCompletedEventArgs e)
{
produtos produto = new produtos();
produto.valor = produto.valor_preco_a * produto.quantidade;
}
In order to use data binding en XAML, you have to set your DataContext property in your listbox.
DataContext property is an object where the xaml engine looks in order to find values that are binded.
You should take a look to this
I'm pretty new to MVVM so bear with me.
I'm working on an application that contains a contacts list. I've defined a contact user control with the following model:
public class Client
{
public string FirstName { get; set; }
public string MiddleName { get; set; }
public string LastName { get; set; }
public string PhoneNumber { get; set; }
public string Address1 { get; set; }
public string Address2 { get; set; }
public string City { get; set; }
public string State { get; set; }
public string ZipCode { get; set; }
public int CustomerID { get; set; }
public string FullName
{
get
{
string result = FirstName;
if (string.IsNullOrEmpty(result))
result = MiddleName;
else if(!string.IsNullOrEmpty(MiddleName))
result += string.Format(" {0}", MiddleName);
if (string.IsNullOrEmpty(result))
result = LastName;
else if (!string.IsNullOrEmpty(LastName))
result += string.Format(" {0}", LastName);
if (string.IsNullOrEmpty(result))
result = "";
return result;
}
}
}
And the following ViewModel:
public class ClientViewModel : ObservableObject
{
public Client Customer
{
get
{
return _customer;
}
set
{
_customer = value;
RaisePropertyChangedEvent("Customer");
}
}
public string FullName { get { return _customer.FullName; } }
public string PhoneNumber { get { return _customer.PhoneNumber; } }
public string Address1 { get { return _customer.Address1; } }
public string Address2 { get { return _customer.Address2; } }
public string City { get { return _customer.City; } }
public string State { get { return _customer.State; } }
public string ZipCode { get { return _customer.ZipCode; } }
Client _customer = new Client();
}
And the following View:
<UserControl x:Class="LawnCareManager.Views.ClientView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:LawnCareManager.ViewModels"
mc:Ignorable="d"
d:DesignHeight="180" d:DesignWidth="300">
<UserControl.DataContext>
<local:ClientViewModel/>
</UserControl.DataContext>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="1*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="1*"/>
<RowDefinition Height="1*"/>
<RowDefinition Height="1*"/>
<RowDefinition Height="1*"/>
<RowDefinition Height="1*"/>
<RowDefinition Height="1*"/>
<RowDefinition Height="1*"/>
</Grid.RowDefinitions>
<Label Grid.Row="0"
Grid.Column="0"
VerticalAlignment="Center"
HorizontalAlignment="Right"
Margin="10,0,0,0"
Content="Name: "/>
<Label Grid.Row="0"
Grid.Column="1"
VerticalAlignment="Center"
HorizontalAlignment="Left"
Margin="10,0,0,0"
Content="{Binding FullName}"/>
<Label Grid.Row="1"
Grid.Column="0"
VerticalAlignment="Center"
HorizontalAlignment="Right"
Margin="10,0,0,0"
Content="Phone Number: "/>
<Label Grid.Row="1"
Grid.Column="1"
VerticalAlignment="Center"
HorizontalAlignment="Left"
Margin="10,0,0,0"
Content="{Binding PhoneNumber}"/>
<Label Grid.Row="2"
Grid.Column="0"
VerticalAlignment="Center"
HorizontalAlignment="Right"
Margin="10,0,0,0"
Content="Address 1: "/>
<Label Grid.Row="2"
Grid.Column="1"
VerticalAlignment="Center"
HorizontalAlignment="Left"
Margin="10,0,0,0"
Content="{Binding Address1}"/>
<Label Grid.Row="3"
Grid.Column="0"
VerticalAlignment="Center"
HorizontalAlignment="Right"
Margin="10,0,0,0"
Content="Address 2: "/>
<Label Grid.Row="3"
Grid.Column="1"
VerticalAlignment="Center"
HorizontalAlignment="Left"
Margin="10,0,0,0"
Content="{Binding Address2}"/>
<Label Grid.Row="4"
Grid.Column="0"
VerticalAlignment="Center"
HorizontalAlignment="Right"
Margin="10,0,0,0"
Content="City: "/>
<Label Grid.Row="4"
Grid.Column="1"
VerticalAlignment="Center"
HorizontalAlignment="Left"
Margin="10,0,0,0"
Content="{Binding City}"/>
<Label Grid.Row="5"
Grid.Column="0"
VerticalAlignment="Center"
HorizontalAlignment="Right"
Margin="10,0,0,0"
Content="State: "/>
<Label Grid.Row="5"
Grid.Column="1"
VerticalAlignment="Center"
HorizontalAlignment="Left"
Margin="10,0,0,0"
Content="{Binding State}"/>
<Label Grid.Row="6"
Grid.Column="0"
VerticalAlignment="Center"
HorizontalAlignment="Right"
Margin="10,0,0,0"
Content="Zip Code: "/>
<Label Grid.Row="6"
Grid.Column="1"
VerticalAlignment="Center"
HorizontalAlignment="Left"
Margin="10,0,0,0"
Content="{Binding ZipCode}"/>
</Grid>
</UserControl>
Now, I want to create a user control that contains a list of contacts defined in the ViewModel below:
public class ClientsListViewModel : ObservableObject
{
public ObservableCollection<ClientViewModel> Clients
{
get { return _clients; }
set { _clients = value; }
}
ObservableCollection<ClientViewModel> _clients = new ObservableCollection<ClientViewModel>();
public ClientsListViewModel()
{
ClientViewModel client = new ClientViewModel();
client.Customer.FirstName = "John";
client.Customer.LastName = "Doe";
client.Customer.PhoneNumber = "555-555-5555";
client.Customer.Address1 = "1234 Fake Street";
client.Customer.City = "Springfield";
_clients.Add(client);
}
}
And the View below:
<UserControl x:Class="LawnCareManager.Views.ClientsListView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:LawnCareManager.ViewModels"
xmlns:views="clr-namespace:LawnCareManager.Views"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<UserControl.DataContext>
<local:ClientsListViewModel/>
</UserControl.DataContext>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="1*"/>
</Grid.RowDefinitions>
<Label Content="Contacts"
Grid.Row="0"
Grid.Column="0"/>
<ListView Grid.Column="1" Grid.Row="2" Grid.ColumnSpan="2" ItemsSource="{Binding Clients}" x:Name="listView">
<ListView.ItemTemplate>
<DataTemplate>
<views:ClientView DataContext="{Binding}"/>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</Grid>
</UserControl>
The problem is that the ClientView ListViewItems in the ClientsListView are not binding correctly to the ObservableCollection of ClientViewModels. The correct number of ClientViews shows up in the list if I add more ClientViewModels, but none of the labels in the ClientView are populating.
Could somebody tell me what I'm doing wrong? Any feedback is greatly appreciated!
The issue here is that you are constructing the data context for client view within the InitializeComponent method. That's due to the static declaration in your Xaml. You can prove this empirically by adding this line of code to the ClientView constructor...
var dc = this.DataContext;
and observe that it gets created with null values at the "Wrong time".
If you change these lines in your ClientView.xaml...
<UserControl.DataContext>
<genericMvvm1:ClientViewModel/>
</UserControl.DataContext>
to this...
<!--<UserControl.DataContext>
<genericMvvm1:ClientViewModel/>
</UserControl.DataContext>-->
You will see your clients getting populated and displayed the way you were expecting. You'll need to change your design strategy to take account of the way InitializeComponent behaves, but this answer gets you 'unstuck'.
I have a WPF application. It contains OrderBlock object which contains other objects, plesase see a brief view of the class.
public class OrderBlocks
{
private List<Order> _orders;
[XmlElement("tF_Transactions")]
public List<Order> Orders { get { return _orders; } set { _orders = value; OnPropertyChanged("Orders"); } }
}
public class Order : INotifyPropertyChanged
{
[XmlIgnore]
public List<Duplications> DuplicateHolder { get; set; }
}
public class Duplications
{
public string ID { get; set; }
public string Name { get; set; }
public Duplications(string newID, string newName)
{
ID = newID;
Name = newName;
}
}
I have a datagrid that is bound to my object Orders of type List Orders. My datagrid has a row detail so that when a user clicks on a row further details are displayed. I have added a listbox to this row detail. I want this row detail to show a listbox which displays my object DuplicateHolder of type List Duplications.
At the moment the listbox is empty. Please see my attempted XAML code below. Any help would be great as always.
<ListBox Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="3" Name="lbIdentifier" SelectionMode="Single" DataContext="{Binding OrderBlock}" HorizontalContentAlignment="Stretch">
<ListBox.ItemTemplate>
<DataTemplate>
<Grid Margin="0,2">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0" Text="{Binding Path=DuplicateHolder.ID}" FontSize="10" HorizontalAlignment="Left" Margin="5,0,0,0"/>
<TextBlock Grid.Column="1" Text="{Binding Path=DuplicateHolder.Name}" FontSize="10" HorizontalAlignment="Left" Margin="5,0,0,0"/>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
Try this
<Listbox ItemSource = {Binding DuplicateHolder}/>
and
<TextBlock Grid.Column="0" Text="{Binding Path=ID}".../>
t seems like you did not set the bindings correctly because the listbox Context should be a list of Duplications and the ItemTemplate should be for one Duplication instance from the list of duplicates. So if the global datacontext is an instance of OrderBlocks the listbox will be bound to the DuplicateHolder of an Order:
<ListBox Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="3" Name="lbIdentifier" SelectionMode="Single" DataContext="{Binding Path=DuplicateHolder}" HorizontalContentAlignment="Stretch">
<ListBox.ItemTemplate>
<DataTemplate>
<Grid Margin="0,2">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0" Text="{Binding Path=ID}" FontSize="10" HorizontalAlignment="Left" Margin="5,0,0,0"/>
<TextBlock Grid.Column="1" Text="{Binding Path=Name}" FontSize="10" HorizontalAlignment="Left" Margin="5,0,0,0"/>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
I have a problem in binding elements of my dictionnary.My dictionnary contains an object as a key and an integer as a value.I have to bind this dictionnary in a ListView.The problem is that I need to reach properties of my object to bind them in the listview.Properties type is string.I didn't find solution, it's all about wpf but I'm using Windows8 with MVVM Light.
There is my code:
My List :
<ListView ItemsSource="{Binding Path=MotDansTweet}"
HorizontalAlignment="Left"
Height="570"
Margin="64,28,0,0"
VerticalAlignment="Top"
Width="350"
Background="#FF009BB4"
Grid.Column="1">
<StackPanel Height="118"
Width="340">
<Grid Height="100">
<Grid HorizontalAlignment="Left"
Height="122"
VerticalAlignment="Top"
Width="330"
Margin="0,0,0,-22">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="137*" />
<ColumnDefinition Width="193*" />
</Grid.ColumnDefinitions>
<Image Source="{Binding Path=Key.ProfileImageUrl }"
HorizontalAlignment="Left"
Height="112"
VerticalAlignment="Top"
Width="127" />
<TextBlock Text="{Binding Path=Key.Username}"
Grid.Column="1"
HorizontalAlignment="Left"
Margin="10,10,0,0"
TextWrapping="Wrap"
VerticalAlignment="Top"
Height="46"
Width="173" />
<TextBlock Text="{Binding Path=Values}"
Grid.Column="1"
HorizontalAlignment="Left"
Margin="10,61,0,0"
TextWrapping="Wrap"
VerticalAlignment="Top"
Height="41"
Width="154" />
</Grid>
</Grid>
</StackPanel>
</ListView>
My Dictionnary :
private Dictionary<ObjetFollowingFollowerFinal,int> _motDansTweet ;
public Dictionary<ObjetFollowingFollowerFinal, int> MotDansTweet
{
get { return _motDansTweet; }
set
{
_motDansTweet = value;
RaisePropertyChanged("MotDansTweet");
}
}
My Object :
public class ObjetFollowingFollowerFinal
{
public string Username { get; set; } // I need it
public string Description { get; set; }
public string ProfileImageUrl { get; set; } //I need it
public int StatusesCount { get; set; }
public int FollowerCount { get; set; }
public int FriendsCount { get; set; }
public int ListedCount { get; set; }
public List<User> ListeFollower = new List<User>();
public ObjetFollowingFollowerFinal()
{
}
}
Thanks.
I coded something on Win7 WPF, but that should work for you, too:
C#:
public MainWindow()
{
_motDansTweet = new Dictionary<ObjetFollowingFollowerFinal, int>();
_motDansTweet.Add(new ObjetFollowingFollowerFinal { Username = "Karl1" }, 1);
_motDansTweet.Add(new ObjetFollowingFollowerFinal { Username = "Karl2" }, 2);
_motDansTweet.Add(new ObjetFollowingFollowerFinal { Username = "Karl3" }, 3);
_motDansTweet.Add(new ObjetFollowingFollowerFinal { Username = "Karl4" }, 4);
Resources["MotDansTweet"] = MotDansTweet;
InitializeComponent();
}
XAML:
<ListView ItemsSource="{DynamicResource MotDansTweet}">
<ListView.View>
<GridView>
<GridViewColumn Header="Value"
DisplayMemberBinding="{Binding Value}" />
<GridViewColumn Header="Key"
DisplayMemberBinding="{Binding Key.Username}" />
</GridView>
</ListView.View>
</ListView>
Try to specify the ItemTemplate instead of directly put the StackPanel in the ListView:
<ListView ItemsSource="{Binding Path=MotDansTweet}"
HorizontalAlignment="Left" Height="570" Margin="64,28,0,0" VerticalAlignment="Top" Width="350" Background="#FF009BB4" Grid.Column="1">
<ListView.ItemTemplate>
<DataTemplate>
<StackPanel Height="118" Width="340">
<Grid Height="100">
<Grid HorizontalAlignment="Left" Height="122" VerticalAlignment="Top" Width="330" Margin="0,0,0,-22">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="137*"/>
<ColumnDefinition Width="193*"/>
</Grid.ColumnDefinitions>
<Image Source="{Binding Path=Key.ProfileImageUrl }" HorizontalAlignment="Left" Height="112" VerticalAlignment="Top" Width="127"/>
<TextBlock Text="{Binding Path=Key.Username}" Grid.Column="1" HorizontalAlignment="Left" Margin="10,10,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Height="46" Width="173"/>
<TextBlock Text="{Binding Path=Values}" Grid.Column="1" HorizontalAlignment="Left" Margin="10,61,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Height="41" Width="154"/>
</Grid>
</Grid>
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>