2012-08-25 3 views
0

C# 및 XAML SemanticZoom 컨트롤을 Metro 앱에서 바인딩을 사용하려하지만 정직하게 처리 방법이 잘못되었습니다.C# 및 XAML에서 데이터 바인딩?

<SemanticZoom x:Name="boardZoom" Height="626" Margin="10,132,10,0" VerticalAlignment="Top"> 
     <SemanticZoom.ZoomedInView> 

      <GridView IsSwipeEnabled="True" x:Name="ItemsGridView"> 

        <GridView.ItemTemplate> 

         <DataTemplate> 
          <StackPanel Orientation="Horizontal" Margin="10,10,0,0" 
         HorizontalAlignment="Left" Background="White"> 
           <TextBlock Text="{Binding Title}" TextWrapping="Wrap" Width="200" Height="300" 
            FontFamily="Global User Interface" FontSize="40" Foreground="Black" 
          VerticalAlignment="Center" HorizontalAlignment="Left"/> 

           <Image Source="{Binding Image}" Height="60" Width="60" 
         VerticalAlignment="Center" Margin="0,0,10,0" Visibility="{Binding isImage}" /> 

           <TextBlock Text="{Binding Category}" TextWrapping="Wrap" Width="200" 
            FontFamily="Global User Interface" Foreground="Black" 
          VerticalAlignment="Center" HorizontalAlignment="Left"/> 
          </StackPanel> 
         </DataTemplate> 

        </GridView.ItemTemplate> 

       </GridView> 
      </SemanticZoom.ZoomedInView> 

<!--Didn't include SemanticZoom.ZoomedOutView since I'm still trying to get the ZoomedIn one working first--> 

     </SemanticZoom> 

그리고 내 C# 코드는 :

 List<PinStore.pin> pins = PinStore.CopyFromStream(response.GetResponseStream()); //returns a list of PinStore.pin objects, which have name, type, Image, isImage, and Category objects 
     System.Collections.ObjectModel.ObservableCollection<SemanticZoomed.zoomedIn> toSource = new System.Collections.ObjectModel.ObservableCollection<SemanticZoomed.zoomedIn>(); //should I be using ObservableCollection or something like List<> here? 
     foreach (PinStore.pin pin in pins) 
     { 
      SemanticZoomed.ZoomedIn toAdd = new SemanticZoomed.ZoomedIn(); //class with Title, Image, isImage, and Category objects 
      if (pin.type == "text") 
      { 
       toAdd.Title = pin.name; 
       toAdd.Image = null; 
       toAdd.isImage = Visibility.Collapsed; 
       toAdd.Category = pin.category; 
      } 
      toSource.Add(toAdd); 
     } 
     ItemsGridView.DataContext = toSource; 

내가 XAML/C#에서 많은 경험을 한 적이 없다 여기에 내가 질문에, 기사 등에서 조립할에 의해 지금까지받은 한 XAML 코드입니다 , 제로 바인딩 경험. 오류가 발생하지는 않지만 ItemsGridView.DataContext = toSource;ItemsGridView.ItemsSource = toSource;으로 바꾸면 빈 Stackpanel이 GridView에 나타나며 지정한 제목 및 카테고리 값을 채울 수있는 방법을 찾지 못하는 것으로 나타났습니다. . 감사!

답변

1

먼저 항목 스타일을 저장할 수 있도록 ResourceDictionary 만들기를 고려해야합니다. 그런 다음 ItemStyle을 리소스 사전에 설정할 수 있습니다.

상관없이 수행해야 할 작업 : ItemsGridView.ItemsSource = toSource; GridView xaml에서 toSource를 바인딩하도록 선택하지 않은 경우.

또한 SemanticZoomed.zoomedIn 개체가 INotifyPropertyChanged 인터페이스를 구현하고 이벤트를 제대로 호출하는지 확인하십시오. 그리고 제목, 이미지, 범주 등이 편집 할 때 이벤트를 호출하는 public 속성인지 확인하십시오. 또한 pin.Text가 실제 값인지 확인해야합니다. {확신}.

당신은 그들이 윈도우 8과 함께 C# & XAML에 그것을 할 방법을 확인 데이터 바인딩에 대한 자세한 내용을 원한다면 {이어야한다 같은 일} 답장을 http://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh464965.aspx

+0

덕분에, 나는 그것을 밖으로 시도 할 것이다 내일 아침에 당신에게 돌아 가라 :) 종류의 오프 주제이지만() 대신 {}을 사용하는 이유를 물을 수 있습니까? 단지 궁금해서 대답하고 싶지 않다면 : D – MatthewSot

+0

[] {}과()를 포함하여 멋지게 보이는 기호를 사용합니다. 나는 그것이 너무 많은 프로그램을 일으킨다 고 생각합니다. {then (. –

+0

아, 의미가 있습니다. : D – MatthewSot

관련 문제