GART增强现实问题

时间:2014-02-13 01:40:54

标签: c# windows-phone augmented-reality

我正在使用Windows Phone 8应用,想要添加增强现实功能,我正在使用GART,但我遇到了同样的issue 在那里甚至有Igor Ralic的解决方案,通过将canvas.zindex添加到1,我仍然遇到同样的问题(世界视图中的项目闪烁并消失),所以也许这里有任何人更好的解决方案?我正在使用mvvm patern来处理这个AR

这是我使用mvvm的方法

这是我的主视图模型

private ObservableCollection<ARItem> _ardisplayLocation = null;
public ObservableCollection<ARItem> ardisplayLocation
{
    get { return _ardisplayLocation; }
    set { this.SetProperty(ref this._ardisplayLocation, value); }
}

private void UpdateTransport()
    {
        try
        {
            myMessage = "Loading web server data...";
            WebClient client = new WebClient();
            Uri uri = new Uri(transportURL1 + latitude + "%2C" + longitude + transportURL2, UriKind.Absolute);
            client.DownloadStringCompleted += (s, e) =>
            {
                MainPage mainpage = new MainPage();
                mainpage.RefreshButton();
                if (e.Error == null)
                {
                    RootObject result = JsonConvert.DeserializeObject<RootObject>(e.Result);
                    hereRestProperty = new ObservableCollection<Item>(result.results.items);

                    for (int i = 0; i < hereRestProperty.Count; i++)
                    {
                        ardisplayLocation.Add(new CityPlace()
                        {
                             GeoLocation = new GeoCoordinate(hereRestProperty[i].coordinate.Latitude,hereRestProperty[i].coordinate.Longitude),
                             Content = hereRestProperty[i].title,
                             Description = hereRestProperty[i].vicinity
                        });
                    }
                }
                else
                {
                    isFailed = Visibility.Visible;
                    myMessage = "Failed to load web server data, please refresh";
                }
                isBusy = false;
            };
            client.DownloadStringAsync(uri);
        }
        catch (Exception)
        {
            isBusy = false;
            isFailed = Visibility.Visible;
            myMessage = "Something wrong happen, please refresh";
        }
    }

这是我的ArDisplay.xaml.cs

private MainViewModel mvm { get { return this.DataContext as MainViewModel; } }

public ArDisplay()
{
    InitializeComponent();
    DataContext = App.ViewModel;
}

protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
    ardisplay.StartServices();
    ardisplay.ARItems = mvm.ardisplayLocation;
    base.OnNavigatedTo(e);
}

protected override void OnNavigatedFrom(System.Windows.Navigation.NavigationEventArgs e)
{
    ardisplay.StopServices();
    base.OnNavigatedFrom(e);
}

和我的xaml

<gart:ARDisplay Name="ardisplay" AttitudeRefreshRate="50" MovementThreshold="10">
    <gart:VideoPreview x:Name="videoPreview" Canvas.ZIndex="1"/>
    <gart:WorldView x:Name="worldView" Canvas.ZIndex="1" ItemTemplate="{StaticResource CityItemTemplate}"  MinItemScale="0.1" MaxItemScale="1.0" FarClippingPlane="300.0" NearClippingPlane="1.0"/>
    <gart:HeadingIndicator x:Name="headingIndicator" Canvas.ZIndex="1" Width="300" Height="300" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</gart:ARDisplay>

和我的数据模板

<DataTemplate x:Key="CityItemTemplate">
    <Border BorderBrush="Black" BorderThickness="4" CornerRadius="8" Background="#FF003847" Width="320">
        <StackPanel Margin="4">
            <TextBlock x:Name="NameBlock" TextWrapping="NoWrap" Text="{Binding Content}" FontSize="38" VerticalAlignment="Center" Margin="0,0,4,0"  Grid.Column="1" TextTrimming="WordEllipsis"/>
            <TextBlock x:Name="DescriptionBlock" TextWrapping="Wrap" Text="{Binding Description}" FontSize="24" VerticalAlignment="Center" Margin="0,0,4,0" Grid.Column="1" TextTrimming="WordEllipsis" MaxHeight="168"/>
        </StackPanel>
    </Border>
</DataTemplate>

1 个答案:

答案 0 :(得分:1)

您的DataTemplate

中缺少Canvas.ZIndex
<DataTemplate x:Key="CityItemTemplate">
    <Border BorderBrush="Black" BorderThickness="4" CornerRadius="8" Background="#FF003847" Width="320" Canvas.ZIndex="2">
        <StackPanel Margin="4">
            <TextBlock x:Name="NameBlock" TextWrapping="NoWrap" Text="{Binding Content}" FontSize="38" VerticalAlignment="Center" Margin="0,0,4,0"  Grid.Column="1" TextTrimming="WordEllipsis"/>
            <TextBlock x:Name="DescriptionBlock" TextWrapping="Wrap" Text="{Binding Description}" FontSize="24" VerticalAlignment="Center" Margin="0,0,4,0" Grid.Column="1" TextTrimming="WordEllipsis" MaxHeight="168"/>
        </StackPanel>
    </Border>
</DataTemplate>