'WPF Listview JSON Data Binding?
Hello i have a json file that contains "Name,FileName,ImageLink" etc. so i tried bind that json file to WPF ListView but it didn't work, it dosent adds a item in to listview, i tried everything that i found on web but its still dosent adds a item in to listview so i dont know what to do, im doing something wrong ?
C#
public void OutputJson()
{
try
{
WebClient webClient = new WebClient();
string input = webClient.DownloadString("https://SITESITE/json.json");
//string json = System.IO.File.ReadAllText(input);
testlistview.ItemsSource = JsonConvert.DeserializeObject<List<Models>>(input);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
public class Models
{
public string Name { get; set; }
public string FileName { get; set; }
public string FileLink { get; set; }
public DateTime dateTime { get; set; }
public string Status { get; set; }
public string ImageLink { get; set; }
public string Type { get; set; }
}
XAML Style
</Border.Style>
<Grid>
<TextBlock Text="Loading" Foreground="#FFB0B0B0"
FontSize="14"
Margin="45,20,0,0"/>
<StackPanel Margin="-660,5,0,0">
<Border CornerRadius="4" Height="50" Width="100">
<!--<Border.Background>
<ImageBrush ImageSource="{Binding ImageLink.Url}" />
</Border.Background>-->
</Border>
</StackPanel>
<Border Background="#404040" HorizontalAlignment="Center" Height="20" Width="80" CornerRadius="3" Margin="700,0,0,0">
<TextBlock HorizontalAlignment="Center" Text="{Binding Status}" Foreground="#FFB0B0B0" Margin="0,2,0,0"/>
</Border>
<Image Source="/DarkSpy;component/icons/NameIcon.png" Width="18" Height="18" Margin="-523,-25,0,0"/>
<Image Source="/DarkSpy;component/icons/Info.png" Width="20" Height="20" Margin="-523,25,0,0"/>
<Image Source="/DarkSpy;component/icons/calendar.png" Width="16" Height="16" HorizontalAlignment="Center" Margin="70,0,0,0"/>
<TextBlock Text="{Binding Name}" Foreground="#FFB0B0B0"
FontSize="14"
FontWeight="Medium"
Margin="155,8,0,0"/>
<TextBlock Text="{Binding Type}" Foreground="#FFB0B0B0"
FontSize="13"
Margin="155,33,0,0"/>
<TextBlock Text="{Binding dateTime}" Foreground="#FFB0B0B0"
FontSize="13"
Margin="155,21,0,0" HorizontalAlignment="Center"/>
<TextBlock Text="{Binding FileName}" Visibility="Hidden"/>
<TextBlock Text="{Binding FileLink}" Visibility="Hidden"/>
</Grid>
</Border>
</DataTemplate>
</Setter.Value>
</Setter>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
