我試圖在我的Metro應用程序中使用C#和XAML SemanticZoom控件進行綁定,但老實說我對如何做到這一點不知所措。這裏是XAML代碼中,我通過問題,文章等一起拼湊至今得到:在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#多少經驗,並沒有約束力的經驗。我沒有收到任何錯誤,但我注意到如果我將ItemsGridView.DataContext = toSource;
替換爲ItemsGridView.ItemsSource = toSource;
,GridView中會出現一個空白的堆棧面板,我似乎無法找到一種方法來填充指定的標題和類別值。謝謝!
感謝您的答覆,我會嘗試一下明天早上,回到你身邊:) 一種脫離主題,但我可以問你爲什麼用{}而不是()?只是好奇,如果你不想回答,那麼不要:D – MatthewSot
我使用任何看起來很酷的符號,包括[] {}和()。我想這是因爲我編程太多了,很容易按{然後(。 –
啊,有道理:D – MatthewSot