Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/261.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何将用户控件与悬停按钮关联?_C#_Xaml_Kinect - Fatal编程技术网

C# 如何将用户控件与悬停按钮关联?

C# 如何将用户控件与悬停按钮关联?,c#,xaml,kinect,C#,Xaml,Kinect,我有以下用户控件 <UserControl x:Class="Kimect.Controls.ElementControl" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas

我有以下用户控件

<UserControl x:Class="Kimect.Controls.ElementControl"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:local="clr-namespace:Kimect"
             mc:Ignorable="d" Width="50" Height="50" SizeChanged="UserControl_SizeChanged">
    <Grid Name="mainGrid" MouseLeftButtonUp="element_MouseLeftButtonUp" Style="{StaticResource elementGrid}" >                
        <TextBlock Name="Number" Text="1" FontSize="15"  Margin="0 0 2 0" 
                   HorizontalAlignment="Right" VerticalAlignment="Top" />
        <TextBlock Name="symbol" Text="H"  FontSize="20"
                   HorizontalAlignment="Center" VerticalAlignment="Center" />
    </Grid>
</UserControl>


现在我想用Kinect单击它。我已经研究并找到了KinectHoverButton.cs,但我不知道如何将用户控件与HoverButton关联。我使用的是Kinect SDK 1.7。

首先需要注意的是,Kinect SDK 1.8是最新版本,并且支持许多新功能。如果您有可能更新到最新的SDK,我建议您研究一下。其中一个变化是你如何与按钮交互——用更直观的“按下”动作取代“悬停”

对于您的
KinectHoverButton
,我假设您使用的是“ControlBasics WPF”示例中的按钮

KinectHoverButton
KinectButtonBase
的子类,它又是常规
ButtonBase
类的子类。以下是MSDN上的
按钮库
类的链接:

最后,从上面的链接中,您会注意到
ButtonBase
ContentControl
的一个子类:

public abstract class ButtonBase : ContentControl
。。。您可以(几乎)将任何内容放入
ContentControl

您不想将
UserControl
随机存取到
KinectHoverButton
中。相反,您希望创建一个
KinectHoverButton
,它看起来像您的
UserControl
,并且在使用手势环境时表现出应有的行为。如果要重用,可以创建一个只包含一个
kinecthover按钮的
UserControl

举个简单的例子:

<KinectHoverButton>
  <Grid>                
    <TextBlock Name="Number" Text="1" FontSize="15"  Margin="0 0 2 0" 
               HorizontalAlignment="Right" VerticalAlignment="Top" />
    <TextBlock Name="symbol" Text="H"  FontSize="20"
               HorizontalAlignment="Center" VerticalAlignment="Center" />
  </Grid>
</KinectHoverButton>


。。。将创建一个启用Kinect的按钮,该按钮看起来与您现有的
UserControl

非常接近(您需要稍微调整一下样式)
,非常感谢,它帮了我很多忙!。