簡體   English   中英

MVVM WPF空用戶控件

[英]MVVM WPF empty user control

我在嘗試從此處實施加載微調器時遇到一些問題: https : //github.com/blackspikeltd/Xaml-Spinners-WPF

我的MainWindow只是一個包裝器,在其中我加載由按鈕控制的不同用戶控件:

<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的新手。

謝謝。

我相信我找到了一個解決方案,我需要為自己的用戶控件定義一個數據上下文:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM