WPF 폼이 있고 UI의 desagialized json 데이터를 DataGrid에 바인딩하려고합니다. 하지만 여기에 UI에서 데이터 그리드의 값을 볼 수 없습니다.데이터 바인딩이 작동하지 않습니다. XAML C# WPF
JSON response:
Firstly, my json response is in the below format:
{
"results":
[
{"type": "upload", "status": "new","data": {"uuid":"f7e98"},"device_id": "123"},
{"type": "upload", "status": "new","data": {"uuid":"f8fc1"},"device_id": "456"},
{"type": "upload", "status": "new","data": {"uuid":"fgff1"},"device_id": "678"},
{"type": "upload", "status": "new","data": {"uuid":"yuki1"},"device_id": "786"},
{"type": "upload", "status": "new","data": {"uuid":"rtyi1"},"device_id": "654"}
]
}
클래스 : 여기
public class UploadStatusList
{
public List<UploadStatus> results;
}
public class UploadStatus
{
public string type {get;set;}
public string status {get;set;}
public string device_id {get;set;}
public Data data {get;set;}
}
public class Data
{
public string uuid {get;set;}
}
내 홈페이지 window.xaml.cs
MainWindow.xaml.cs를하다 : 아래
public partial class MainWindow : Window
{
// Dependency Property
public static readonly DependencyProperty actionListProperty =
DependencyProperty.Register("actionList", typeof(ObservableCollection<UploadStatusList>),
typeof(MainWindow), new FrameworkPropertyMetadata(null));
// .NET Property wrapper
public ObservableCollection<UploadStatusList> actionList
{
get { return (ObservableCollection<UploadStatusList>)GetValue(actionListProperty); }
set { SetValue(actionListProperty, value); }
}
public MainWindow()
{
InitializeComponent();
//Code Block for httpwebRequest here
//JSON Response String
string json = stringbuilder.ToString();
//Newtonsoft.Json.JsonConvert.Deserialize<UploadStatusList>(json) returns null for me here,so using Javascript serializer. No idea why !?
UploadStatusList list = new System.Web.Script.Serialization.JavaScriptSerializer().Deserialize<UploadStatusList>(json);
foreach (var item in list.results)
{
Debug.Print("id: {0}, name: {1}", item.status, item.device_id);
}
}
}
내 기본 창입니다 .XAML ... xaml을 처음 접했을 때 내가 무엇이든 놓친다면 확신 할 수 없다.,210 MainWindow.xaml :
<TabItem x:Name="UploadList" Header="Upload List" HorizontalAlignment="Left" Width="77" Margin="-2,-2,0,2">
<Grid Margin="0,0,0,0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="124*"/>
<ColumnDefinition Width="107*"/>
</Grid.ColumnDefinitions>
<Button x:Name="Button" Content="Refresh" Margin="14,40,0,361" HorizontalAlignment="Left" Width="120" Click="Button_Click"/>
<DataGrid Margin="14,79,10,58" x:Name="Access_DataGrid" IsReadOnly="True" ItemsSource="{Binding actionList.results}" IsSynchronizedWithCurrentItem="True" AutoGenerateColumns="False">
<DataGrid.Columns>
<DataGridTextColumn Header="status" Binding="{Binding status}" />
<DataGridTextColumn Header="device id" Binding="{Binding device_id}" />
<DataGridTextColumn Header="type" Binding="{Binding type}" />
</DataGrid.Columns>
</DataGrid>
</Grid>
</TabItem>
DP 액션 목록을 설정하지 않았습니다. 또한 어디서나 바인딩하지 않으면 DP를 만들 필요가 없습니다. –
바인딩을 더 잘 이해하려면 다음 링크를 참조하십시오. https://docs.microsoft.com/en-us/dotnet/framework/wpf/data/how-to-implement-property-change-notification –