小编MyK*_*SKI的帖子

暂停Kinect Camera - SDK调节事件处理程序可能出错

我正在将Microsoft SDK Beta代码转换为2012年2月发布的Microsoft SDK官方发行版.

我添加了一个通用PauseKinect()来暂停Kinect.我的暂停只会删除更新图像的事件处理程序

优点:

  • 无重新初始化(30秒等待时间)

缺点:

  • Kinect仍在处理图像

暂停方法(仅限颜色)

internal void PauseColorImage(bool isPaused)
{
    if (isPaused)
    {
        _Kinect.ColorFrameReady -= ColorFrameReadyEventHandler;
        //_Kinect.ColorStream.Disable();
    }

    else
    {
        _Kinect.ColorFrameReady += ColorFrameReadyEventHandler;
        //_Kinect.ColorStream.Enable(ColorImageFormat.RgbResolution640x480Fps30);
    }
}
Run Code Online (Sandbox Code Playgroud)

问题:

即使我正在删除事件,为什么它仍然被触发?

注意:

此外,当我暂停彩色图像时,我也会在其对象中暂停深度和骨骼.

边注:

如果我取消注释我的代码它可以正常工作,但是它将永远重新初始化,这不是我想要做的.

反射器中的MS

public void AddHandler(EventHandler<T> originalHandler)
{
    if (originalHandler != null)
    {
        this._actualHandlers.Add(new ContextHandlerPair<T, T>(originalHandler, SynchronizationContext.Current));
    }
}

public void RemoveHandler(EventHandler<T> originalHandler)
{
    SynchronizationContext current = SynchronizationContext.Current;
    ContextHandlerPair<T, T> item = null;
    foreach (ContextHandlerPair<T, T> pair2 …
Run Code Online (Sandbox Code Playgroud)

c# wpf kinect

9
推荐指数
1
解决办法
648
查看次数

隐式样式不适用于自定义控件

在我的App.xaml中,我有一些隐式样式

<Style TargetType="{x:Type Button}">
   ...Blah...
</Style>
Run Code Online (Sandbox Code Playgroud)

只要它们不在我创建的自定义控件中,这些样式就可以用于控制.

我的控制

 public class NavigationControl : Control
 {
     public static readonly DependencyProperty ButtonStyleProperty =
         DependencyProperty.Register("ButtonStyle", typeof(Style), typeof(NavigationControl));

     public Style ButtonStyle
     {
         get { return (Style)GetValue(ButtonStyleProperty); }
         set { SetValue(ButtonStyleProperty, value); }
     }
 }

 static NavigationControl()
 {
     DefaultStyleKeyProperty.OverrideMetadata(typeof(NavigationControl), new FrameworkPropertyMetadata(typeof(NavigationControl)));
 }

 public NavigationControl()
 {
 }
Run Code Online (Sandbox Code Playgroud)

我的控件样式和模板

<ControlTemplate x:Key="NavigationControlTemplate" TargetType="{x:Type controls:NavigationControl}">
   <Button Style="{TemplateBinding ButtonStyle}"
</ControlTemplate>

<Style x:Key="DefaultButtonStyle" TargetType="{x:Type Button}" BasedOn="{StaticResource {x:Type Button}}">
    <Setter Property="MinWidth" Value="75"/>
    <Setter Property="Height" Value="50"/>
    <Setter Property="FontSize" Value="12"/>
    <Setter Property="Margin" Value="-1"/>
</Style>

<Style …
Run Code Online (Sandbox Code Playgroud)

wpf resources xaml implicit-style

6
推荐指数
1
解决办法
1020
查看次数

“工具提示”不能有逻辑或视觉父级

我有以下问题。当我尝试为切换按钮设置工具提示样式时,我不断收到“工具提示”不能有逻辑或视觉父错误。什么地方出了错?当我取出 ToggleButton.ToolTip 下的工具提示控件时,它起作用了!

 <ToggleButton x:Name="toggle" OverridesDefaultStyle="True" Template="{StaticResource ExpanderToggleButton}" Margin="0,4,0,0" VerticalAlignment="Top" IsChecked="{Binding IsExpanded, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}">
     <ToggleButton.ToolTip>
         <ToolTip Style="{StaticResource tooltipstyle}">                        
             <TextBlock Background="Transparent"/>                                                                                                                      
         </ToolTip>
     </ToggleButton.ToolTip>
 </ToggleButton>
Run Code Online (Sandbox Code Playgroud)

wpf-controls

5
推荐指数
1
解决办法
3257
查看次数

在TextBlock中,是否可以通过触摸来选择特定单词?

在我的应用程序中,我有一个TextBlock包含一些单词(如20或25).我希望用户能够点击TextBlock中的单词并在应用程序中检索它以便在之后使用它.

有没有人有想法?

我试过只读TextBox.但我需要点击它3次来选择其中的一个单词,我对复制和粘贴功能无能为力.

提前致谢.

c# silverlight windows-phone-7 windows-phone-7.1

4
推荐指数
1
解决办法
1441
查看次数

从绑定的ListBox中获取所选项字符串

我在从列表框中的绑定文本块中获取字符串时遇到问题,当我使用下面的代码时,我可以绑定列表框,列表框中有项目显示,但是当列表中的项目被点击时我不会得到正确的字符串,我在消息框中打印一个带有对象名称的消息

"MyApp.Item"

而是显示出来.myApp是应用程序的名称,Item是我绑定到列表框的模型的名称.当列表框没有绑定时,所选项目中的正确文本显示出来.

private void listBoxtrend_Tap(object sender, GestureEventArgs e)
{
    selectedText = "";

    selectedText = listBox.SelectedValue.ToString();

    MessageBox.Show(selectedText);
}
Run Code Online (Sandbox Code Playgroud)

XML

<ListBox ItemsSource="{Binding Item}" Foreground="RoyalBlue" 
    Height="395" HorizontalAlignment="Center" 
    Margin="12,111,0,0" Name="listBox" 
    VerticalAlignment="Top" Width="438"
    TabIndex="10"  Tap="listBox_Tap" >
    <ListBox.ItemTemplate>
        <DataTemplate>
            <TextBlock TextWrapping="Wrap" FontSize="26" HorizontalAlignment="Left"
                Name="tblItem" Text="{Binding ItemString}"
                VerticalAlignment="Top" />
        </DataTemplate>
    </ListBox.ItemTemplate>
</ListBox>
Run Code Online (Sandbox Code Playgroud)

如果你能帮助我,我真的很感激

c# xaml windows-phone-7

3
推荐指数
1
解决办法
2万
查看次数

使用excel连接到远程sql数据库

我正在使用SQL Server 2008 R2和Microsoft Excel.

  • 我已将服务器设置为通过Windows用户数据库用户登录
  • 可以使用数据库用户登录数据库
  • 可以使用Silverlight应用程序连接到数据库
  • 无法弄清楚如何从Excel中的远程PC连接

我去了Excel - >数据 - >来自其他来源 - >来自SQL Server

我的服务器名称是WIN2K8-01\DATABASENAME,因此在Excel中我输入IP\WIN2K8-01\DATABASENAME了用户名和密码.

sql excel

3
推荐指数
1
解决办法
4万
查看次数

返回基类的方法返回子类调用?

我正在创建一个C#框架,其中(几乎)我的所有类都将基于单个抽象基类.该基类包含一些私有设置属性,其中一个属性是布尔垃圾.

在XNA的绘制循环中,如果基类的Garbage属性设置为true ,我不希望任何子类在它们各自的Draw()方法中执行代码.我尝试使用以下实现执行此操作:

抽象基类:

public virtual void Draw(GameTime GameTime, SpriteBatch SpriteBatch)
{
    if (Garbage) return;
}
Run Code Online (Sandbox Code Playgroud)

继承类:

public void Draw(GameTime GameTime, SpriteBatch SpriteBatch, Color OverlayColor, float Scale)
{
    base.Draw(GameTime, SpriteBatch);

    //Other code here...
}    
Run Code Online (Sandbox Code Playgroud)

因为基类的Draw方法是在我的子类中的实际代码之前调用的,所以它命中了返回语句,我希望将其贯穿到我的子类的Draw()调用中.但是,这种情况并没有发生.

有没有办法达到我想要的效果,而不添加"if(Garbage)return;" 限制到每个继承类的Draw()方法的顶部?

c# inheritance xna return base

2
推荐指数
1
解决办法
1686
查看次数

确定是否使用Microsoft SDK或ManagementObjectSearcher插入Kinect

我正在尝试使用ManagementObjectSearcher确定我的Kinect是否已插入PC.我不确定要查询什么,因为它没有列为USB设备.相反,它被列为"Microsoft Kinect"硬件设备.

在此输入图像描述

以下是我要烦恼的事情:

using (ManagementObjectSearcher searcher = new ManagementObjectSearcher(@"Select * from Win32_SOMETYPE"))
{
    foreach (ManagementObject managementObject in searcher.Get())
    {
        foreach (PropertyData propertyData in managementObject.Properties)
        {
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

c# wpf usb kinect

1
推荐指数
1
解决办法
645
查看次数

有没有办法检查参数是否在存储过程中?

我正在编写一个通用函数,用于将查询字符串直接输入到sproc中.该算法相当基本 - 循环查询键,将它们用作参数名称,而值用作参数值.所以它看起来像这样:

ArrayList pars = new ArrayList();
SqlParameter p;
int tryInt;
for (int i = 0; i < req.QueryString.Count; i++) 
{
    key = req.QueryString.AllKeys[i];

    if (int.TryParse(req[key], out tryInt)) 
    {
        p = new SqlParameter("@" + key, SqlDbType.Int);
        p.Value = tryInt;
        pars.Add(p);
    }
}
Run Code Online (Sandbox Code Playgroud)

到目前为止,这工作正常,除了当然所有查询键必须匹配sproc的参数,如果他们不这样做我得到一个SQL异常说类似的东西

@someParameter is not a parameter for procedure some_sproc
Run Code Online (Sandbox Code Playgroud)

但是我需要能够在查询字符串中传入不会传递给sproc的变量,所以我需要一种方法来"忽略"它们.

有没有办法测试给定的存储过程是否需要某个参数?这样我就能沿着这些方向做点什么

if (paramExists("@" + key, "some_sproc") && int.TryParse(req[key], out tryInt)) 
{
    p = new SqlParameter("@" + key, SqlDbType.Int);
    p.Value = tryInt;
    pars.Add(p);
}
Run Code Online (Sandbox Code Playgroud)

c# asp.net stored-procedures

0
推荐指数
1
解决办法
2315
查看次数

WP7 - 来自WPF/Silverlight的HLSL效果

我知道我在WP7(不是WP7.1)中做到了这一点,我无法弄清楚我做了什么.

我正在使用这个效果库
我正在使用这个效果构建任务和模板

所以基本上我在记事本中打开了我的WP7 csproj文件,添加了以下几行:

在项目根目录下

<UsingTask TaskName="ShaderBuildTask.PixelShaderCompile" AssemblyName="ShaderBuildTask, Version=1.0.3072.18169, Culture=neutral, PublicKeyToken=44e467d1687af125" />

<Target Name="EffectCompile" Condition="'@(Effect)' != '' ">
    <PixelShaderCompile Sources="@(Effect)">
        <Output TaskParameter="Outputs" ItemName="Resource" />
    </PixelShaderCompile>
</Target>
<PropertyGroup>
    <PrepareResourcesDependsOn>EffectCompile;$(PrepareResourcesDependsOn)</PrepareResourcesDependsOn>
</PropertyGroup>
Run Code Online (Sandbox Code Playgroud)

并且System.Windows.Media.Effects不包含

ShaderEffect
PixelShader
Run Code Online (Sandbox Code Playgroud)

如果有人知道我做错了什么或者有一个WP7模板,这将是非常棒的.谢谢.我不是要使用XNA着色器.

silverlight wpf windows-phone-7 windows-phone-7.1

0
推荐指数
1
解决办法
738
查看次数