WPF控件和窗口问题 [英] WPF Control and Window issue

查看:83
本文介绍了WPF控件和窗口问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,这里有一个关于WPF和控件的菜鸟问题。



我下载名为 FluidKit
附带了一整套 3D图像效果的示例,只需
图片 效果一般。



我遇到的问题是我只想要 1类型效果超出所有这些但我不确定如何制作新项目并将
FluidKit 代码复制/粘贴到我的新项目中需要的效果。我需要能够在我的窗口中重现这几次,而不是像我现在一样重现一次。



代码如下:



TransitionTester.xaml



其中有一些设置如下:



立方体(从左到右)

立方体(从右到左>

立方体(从上到下)

立方体(从下到上)

幻灯片(从左到右)

幻灯片(从右到左)

翻转(从左到右)

翻转(从右到左)



TransitionTester.xaml  看起来是 UserControl



所以我创建了一个新的WPF项目,现在我有以下几种形式:



MainWindow.xaml

TransitionTester.xaml



当然我将引用替换为 fluidkit.dll



从fluidKit项目复制/粘贴代码后鞠躬在我的新项目中,我最终只有两个错误,这对我来说是惊人的!
$


错误是:



'MainWindow'不包含'SwitchImage'的定义,并且没有扩展方法'SwitchImage'可以找到接受类型'MainWindow'的第一个参数(你是否缺少using指令或汇编引用?)



资源"SlideTransition"无法解决。



我的MainWindow.xaml代码如下所示:

Hey all here is a noob question regarding WPF and controls.

I download the project called FluidKit which comes with a hand full of examples for 3D image effects and just image effects in general.

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. 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

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.

So I create a new WPF project and now I have the following forms:

MainWindow.xaml
TransitionTester.xaml

and of course I replace a reference to the 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!

The errors are:

'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?)

The resource "SlideTransition" could not be resolved.

My MainWindow.xaml code looks like this:

<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);
            }
        }
    }


布局如下所示:







我的 MainWindow.xaml设计 看起来也不错:







将其与原始FluidKit窗口进行比较时:





所以帮助我解决这些错误的任何帮助都会很棒!






Layout looks like this:



And my MainWindow.xaml Design looks fine as well:



When comparing it with the original FluidKit window:


So any help to help me fix these errors would be great!



推荐答案

您已在XAML中为MouseLeftDown定义了一个处理程序,但您的代码中没有处理程序。

You have defined a handler for the MouseLeftDown in your XAML but you have no handler in your code.

您可以右键单击处理程序名称SwitchImage,VS将创建一个你的空处理程序。

You can right click the handler name SwitchImage and VS will create an empty handler for you.


这篇关于WPF控件和窗口问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆