简体   繁体   English

WPF控件和窗口问题

[英]WPF Control and Window issue

Hey all here is a noob question regarding WPF and controls. 嘿,这里是有关WPF和控件的菜鸟问题。

I download the project called FluidKit which comes with a hand full of examples for 3D image effects and just image effects in general. 我下载名为项目FluidKit它配备了满手的3D图像效果和一般只是图像效果的例子。

Problem I am having is that I just want 1 type of effect out of all of those but I am unsure how to go about making a new project and copy/paste the FluidKit code to my new project just for that needed effect. 我遇到的问题是,我只想从所有这些效果中选择一种效果,但是我不确定如何去制作一个新项目,然后将FluidKit代码复制/粘贴到我的新项目中,以达到所需的效果。 I am needing to be able to reproduce this a couple of times in my window and not just once as I currently have. 我需要能够在我的窗口中复制两次,而不仅仅是像现在这样复制一次。

The code is for the following: 该代码适用于以下内容:

TransitionTester.xaml TransitionTester.xaml

Which within that has a few settings like: 其中有一些设置,例如:

Cube (Left to Right) 多维数据集(从左到右)

Cube (Right to Left> 多维数据集(从右到左>

Cube (Top to Bottom) 多维数据集(从上到下)

Cube (Bottom to Top) 多维数据集(从下到上)

Slide (Left to Right) 滑动(从左到右)

Slide (Right to Left) 滑动(从右到左)

Flip (Left to Right) 翻转(从左到右)

Flip (Right to Left) 翻转(从右到左)

This TransitionTester.xaml looks to be a UserControl . 这个TransitionTester.xaml看起来像是UserControl

So I create a new WPF project and now I have the following forms: 因此,我创建了一个新的WPF项目,现在具有以下形式:

MainWindow.xaml MainWindow.xaml

TransitionTester.xaml TransitionTester.xaml

and of course I replace a reference to the fluidkit.dll . 当然,我替换了 fluidkit.dll引用

Bow after copy/pasting the code from the fluidKit project to my new project I end up just having 2 errors which is astonishing to me! 将代码从fluidKit项目复制/粘贴到我的新项目后鞠躬,我最终仅遇到2个错误,这对我来说真是令人惊讶!

The errors are: 错误是:

Error CS1061 'MainWindow' does not contain a definition for 'SwitchImage' and no extension method 'SwitchImage' accepting a first argument of type 'MainWindow' could be found (are you missing a using directive or an assembly reference?) 错误CS1061'MainWindow'不包含'SwitchImage'的定义,并且找不到扩展方法'SwitchImage'接受类型为'MainWindow'的第一个参数(您是否缺少using指令或程序集引用?)

Error The resource "SlideTransition" could not be resolved. 错误无法解析资源“ SlideTransition”。

My MainWindow.xaml code looks like this: 我的MainWindow.xaml代码如下所示:

<Window x:Class="flipwindow.MainWindow"
        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"
        xmlns:local="clr-namespace:flipwindow"        
        xmlns:Controls="clr-namespace:FluidKit.Controls;assembly=FluidKit"
        mc:Ignorable="d"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <Controls:TransitionPresenter x:Name="_transContainer"
                                      MouseLeftButtonDown="SwitchImage"
                                      RestDuration="0:0:3"
                                      IsLooped="True"
                                      Transition="{StaticResource SlideTransition}">
            <Image x:Name="_image1"
                   Source="Images/img1.png"
                   Stretch="Fill" />
            <Image x:Name="_image2"
                   Source="Images/img2.png"
                   Stretch="Fill" />
            <Image x:Name="_image3"
                   Source="Images/img3.png"
                   Stretch="Fill" />
        </Controls:TransitionPresenter>
    </Grid>
</Window>

And the code behind that page looks like this: 该页面后面的代码如下所示:

namespace flipwindow
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        private string _backItem = "_image1";
        private string _frontItem = "_image2";

        public MainWindow()
        {
            InitializeComponent();
            Loaded += TransitionTester_Loaded;
            //PlayCube();
        }

        private void TransitionTester_Loaded(object sender, RoutedEventArgs e)
        {
            _transContainer.TransitionCompleted += _transContainer_TransitionCompleted;
        }

        private void _transContainer_TransitionCompleted(object sender, EventArgs e)
        {
            SwapFrontAndBack();
        }

        private void SwapFrontAndBack()
        {
            string temp = _frontItem;
            _frontItem = _backItem;
            _backItem = temp;
        }

        private void PlayCube()
        {
            CubeTransition transition = Resources["CubeTransition"] as CubeTransition;
            //transition.Rotation = Direction.LeftToRight;
            //transition.Rotation = Direction.RightToLeft;
            //transition.Rotation = Direction.TopToBottom;
            transition.Rotation = Direction.BottomToTop;

            _transContainer.Transition = transition;
            _transContainer.ApplyTransition(_frontItem, _backItem);
        }
    }
}

The second error listed above show up on this line: 上面列出的第二个错误显示在此行上:

Transition="{StaticResource SlideTransition}"> Transition =“ {StaticResource SlideTransition}”>

While I am not sure about the first error and what it's looking for in order for that to be corrected. 虽然我不确定第一个错误以及它要查找的内容才能纠正该错误。 It seems to maybe be related to the UserControl.Resources that I can not seem to add to my Window: 它似乎与UserControl.Resources有关 ,我似乎无法将其添加到Window中:

<UserControl.Resources>
    <Controls:SlideTransition x:Key="SlideTransition" />
    <Controls:CubeTransition x:Key="CubeTransition" Rotation="BottomToTop" />
    <Controls:FlipTransition x:Key="FlipTransition" />
</UserControl.Resources>

Layout looks like this: 布局看起来像这样:

在此处输入图片说明

And my MainWindow.xaml Design looks fine as well: 我的MainWindow.xaml设计也不错:

在此处输入图片说明

When comparing it with the original FluidKit window : 原始FluidKit窗口进行比较时:

在此处输入图片说明

So any help to help me fix those 2 errors would be great! 因此,任何能帮助我解决这2个错误的帮助都将非常有用!

UPDATE 1 更新1 在此处输入图片说明

First: the MouseLeftButtonDown tag refers to a callback function in your code behind which of course can not be found. 首先:MouseLeftButtonDown标记引用代码中的回调函数,在该回调函数中当然找不到。 So just insert the SwitchImage function as it is in the FluidKit original code in TransitionTester.xaml.cs to the MainWindow class code in the MainWindow.xaml.cs file which should have be created next to your MainWindow.xaml file. 因此,只要插入SwitchImage功能,因为它是在原FluidKit代码TransitionTester.xaml.csMainWindow中的类代码MainWindow.xaml.cs本应被旁边创建文件MainWindow.xaml文件。 (Maybe keep it empty for testing purposes) (也许将其留空以进行测试)

Second: Yes, you have to copy the <UserControl.Resources> xml code from the original xaml-File to your file. 第二:是的,您必须将<UserControl.Resources> xml代码从原始xaml-File复制到您的文件中。 But you have to replace the tag <UserControl.Resources> by <MainWindow.Resources> as your surrounding tag is <MainWindow> . 但是您必须将标记<UserControl.Resources>替换为<MainWindow.Resources>因为周围的标记是<MainWindow> (The resource named SliceTransition which is referred to later in the code is defined inside this block) (在此代码块中定义了稍后在代码中引用的名为SliceTransition的资源)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM