2011-03-28 7 views
1

저는 comboxbox에 항목을 추가하려고했지만 xaml에 추가 된 콤보 상자를 인식하기 위해 파일 뒤에 코드를 가져올 수 없습니다. 나는 꽤 간단한 것을 놓치고 있다고 확신한다. 기본적으로 여기서 xaml은 빈 콤보 박스를 보여줍니다. 코드 숨김은 서비스를 실행하고 json이 다시 돌아와서 그것을 역 직렬화 할 때까지 기다립니다. 불행하게도, 난 얻을 수Combobox가 Silverlight의 코드 숨김 뒤에 표시되지 않습니다.

XAML :

<navigation:Page x:Class="Growing.Views.Room" 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
     xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
     mc:Ignorable="d" 
     xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation" 
     d:DesignWidth="950" d:DesignHeight="480" 
     Title="Home" Style="{StaticResource PageStyle}" DataContext="{Binding}" xmlns:toolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit" xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"> 
<Grid x:Name="LayoutRoot" ShowGridLines="True" Background="#FF631C00"> 
    <Grid.ColumnDefinitions> 
    </Grid.ColumnDefinitions> 
    <Rectangle Height="298" HorizontalAlignment="Left" Margin="195,94,0,0" Name="rect" Stroke="Black" StrokeThickness="2" VerticalAlignment="Top" Width="582" Fill="#FFAAAAAA" RadiusY="0.25" RadiusX="0.25" /> 
    <sdk:Label Height="38" HorizontalAlignment="Left" Margin="387,160,0,0" Name="label1" VerticalAlignment="Top" Width="203" Content="Select a Room" FontSize="24" FontWeight="Bold" /> 
    <sdk:Label Height="18" HorizontalAlignment="Left" Margin="312,240,0,0" Name="label2" VerticalAlignment="Top" Width="69" Content="Area:" FontSize="14" /> 
    <ComboBox x:Name="RoomAreas" Height="23" HorizontalAlignment="Left" Margin="418,235,0,0" VerticalAlignment="Top" Width="209" /> 
</Grid> 

뒤에 코드 :

이 힘들 때 내가 An object reference is required for the non-static field, method, or property 'Growing.Views.Room.RoomAreas'

죄송합니다 오류가 RoomAreas.ItemSource에서

using System; 
using System.Collections.Generic; 
using System.IO; 
using System.Linq; 
using System.Net; 
using System.Text; 
using System.Windows; 
using System.Windows.Controls; 
using System.Windows.Documents; 
using System.Runtime.Serialization.Json; 
using System.ServiceModel.Web; 
using System.Windows.Input; 
using System.Windows.Media; 
using System.Windows.Media.Animation; 
using System.Windows.Shapes; 
using System.Windows.Navigation; 
using Growing.DataConnectionRef; 

namespace Growing.Views 
{ 
    public partial class Room : Page 
    { 
     public Room() 
     { 
      InitializeComponent(); 
      //Asynchronously call the EndReceive Web Service to change the status of an existing open lot record 
      WebClient GRService = new WebClient(); 
      GRService.DownloadStringCompleted += new DownloadStringCompletedEventHandler(GRService_DownloadStringCompleted); 
      GRService.DownloadStringAsync(new Uri("/servicestack/GetAreas", UriKind.Relative)); 
     } 

     static void GRService_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e) 
     { 
      List<Area> dataList = new List<Area>(); 
      MemoryStream memoryStream = new MemoryStream(Encoding.UTF8.GetBytes(e.Result)); 
      DataContractJsonSerializer ser = new DataContractJsonSerializer(dataList.GetType()); 
      dataList = ser.ReadObject(memoryStream) as List<Area>; 
      memoryStream.Close(); 
      RoomAreas.ItemSource = dataList; 

     } 

    } 
} 

따라와. 누구든지 여기에 무슨 일이 일어날 지 아이디어가 있습니까?

미리 감사드립니다. ItemsSource가 = XAML

답변

3

내에서 콤보 상자 속성에 "{바인딩이}"GRService_DownloadStringCompleted 방법을 비 정적을 확인 추가

+0

나는 이것을 시도하고 일했다. 답변 해 주셔서 감사합니다. – kereberos

0

시도 :

void GRService_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e) 
     { 
      List<Area> dataList = new List<Area>(); 
      MemoryStream memoryStream = new MemoryStream(Encoding.UTF8.GetBytes(e.Result)); 
      DataContractJsonSerializer ser = new DataContractJsonSerializer(dataList.GetType()); 
      dataList = ser.ReadObject(memoryStream) as List<Area>; 
      memoryStream.Close(); 
      RoomAreas.ItemSource = dataList; 

     } 
관련 문제