2015-10-05 54 views
0

我面臨着一些問題,試圖實現從這裏裝載微調:https://github.com/blackspikeltd/Xaml-Spinners-WPFMVVM WPF空的用戶控制

我的主窗口僅僅是我在那裏裝載由一個按鈕控制不同的用戶控件的包裝:

<Window x:Class="Project.Desktop.Views.MainWindow" 
    xmlns:animations="clr-namespace:Project.Desktop.Helpers.Animations" 
    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:views="clr-namespace:Project.Desktop.Views" 
    xmlns:viewModels="clr-namespace:Project.Desktop.ViewModels" 
    Title="Project" Height="580" Width="1024" WindowStartupLocation="CenterScreen" ResizeMode="NoResize" WindowStyle="None" MouseLeftButtonDown="OnMouseLeftButtonDownMove"> 

    <Window.Resources> 
     <DataTemplate DataType="{x:Type viewModels:WelcomeVM}"> 
      <views:Welcome /> 
     </DataTemplate> 
     <DataTemplate DataType="{x:Type viewModels:GameSelectVM}"> 
      <views:GameSelect /> 
     </DataTemplate> 
    </Window.Resources> 


    <Grid> 
     <ContentControl Content="{Binding CurrentPageViewModel}" /> 
    </Grid> 
</Window> 

我複製了XML到我在我的項目創建這樣的引用的用戶控制視圖:

xmlns:animations="clr-namespace:Project.Desktop.Helpers.Animations" 

,然後我試圖訪問用戶控件與

<animations:LoadingAnimation HorizontalAlignment="Center" VerticalAlignment="Center" /> 

的問題是,我不能看到正在加載的旋轉,就好像不存在,我相信還有其他的用戶控制之間的衝突,但我不能夠解決這個問題,主要是因爲我新的wpf和xml。

謝謝。

回答

0

我相信我發現了一個解決方案,我需要定義一個DataContext爲自己的用戶控件:

<animations:LoadingAnimation DataContext="{Binding RelativeSource={RelativeSource Self}}" HorizontalAlignment="Center" VerticalAlignment="Center" />