这是我的XAML视图(为了便于阅读,省略了一些代码):
<Window ... xmlns:c="http://www.caliburnproject.org">
<Button Content="Close without saving" c:Message.Attach="Close(false)" />
<Button Content="Save and Close" c:Message.Attach="Close(true)" />
</Window>
Run Code Online (Sandbox Code Playgroud)这是ViewModel中的代码:
public void Close(bool save)
{
if (save)
{
// save the data
}
TryClose();
}
Run Code Online (Sandbox Code Playgroud)这当然不起作用 - 因为动作参数"true"和"false"不是XAML中的对象或对象属性.如何使这项工作,并在Caliburn Micro中将一个布尔值作为Action参数发送? 我需要对16位整数(ushort/UInt16)执行按位左移,但C#中的按位运算符似乎只适用于int(32位).我如何使用<< on ushort,或者至少通过简单的解决方法获得相同的结果?
我正在尝试录制音频并立即将其发送给IBM Watson Speech-To-Text进行转录.我已经用从磁盘加载的WAV文件测试了Watson,这很有用.另一方面,我还测试了从麦克风录制并将其存储到磁盘,也很好用.
但是当我尝试用NAudio WaveIn录制音频时,Watson的结果是空的,好像没有音频.
任何能够对此有所了解,或有人有想法的人?
private async void StartHere()
{
var ws = new ClientWebSocket();
ws.Options.Credentials = new NetworkCredential("*****", "*****");
await ws.ConnectAsync(new Uri("wss://stream.watsonplatform.net/speech-to-text/api/v1/recognize?model=en-US_NarrowbandModel"), CancellationToken.None);
Task.WaitAll(ws.SendAsync(openingMessage, WebSocketMessageType.Text, true, CancellationToken.None), HandleResults(ws));
Record();
}
public void Record()
{
var waveIn = new WaveInEvent
{
BufferMilliseconds = 50,
DeviceNumber = 0,
WaveFormat = format
};
waveIn.DataAvailable += new EventHandler(WaveIn_DataAvailable);
waveIn.RecordingStopped += new EventHandler(WaveIn_RecordingStopped);
waveIn.StartRecording();
}
public void Stop()
{
await ws.SendAsync(closingMessage, WebSocketMessageType.Text, true, CancellationToken.None);
}
public void Close()
{
ws.CloseAsync(WebSocketCloseStatus.NormalClosure, "Close", CancellationToken.None).Wait();
} …Run Code Online (Sandbox Code Playgroud) 在WPF窗口中,我有一个绘制实时数据的折线图(WPF的Quinn-Curtis实时图表).简而言之,对于每个新值,我调用SetCurrentValue(x,y)方法,然后使用UpdateDraw()方法更新图表.
数据通过另一个线程中的TCP连接进入.每个新值都会导致DataReceived事件,其处理程序应将值绘制到图表中,然后更新它.从逻辑上讲,我无法直接调用UpdateDraw(),因为我的图表位于UI线程中,该线程与数据进入的线程不同.
所以我调用Dispatcher.Invoke(new Action(UpdateDraw())) - 这很好,只要我更新max.30次/秒.更频繁地更新时,Dispatcher无法跟上并且图表更新的速度比数据的速度慢.我使用模拟数据的单线程情况对此进行了测试,没有Dispatcher就没有问题.
所以,我的结论是Dispatcher对于这种情况来说太慢了.我实际上需要更新100-200次/秒!
有没有办法在Dispatcher上放置涡轮增压器,还是有其他方法可以解决这个问题?欢迎任何建议.
我需要为Windows创建一个桌面应用程序,我对选择哪种技术存有疑问.事实是,应用程序必须与本地资源进行交互:
我最好选择Silverlight 4,并允许应用程序在完全信任的桌面上运行.但我预见到有关这两个要求的问题.SL4有什么解决方案,如果没有,我应该选择哪种替代方案?我不仅限于WPF或WinForms,但由于它应该在.NET上运行,我或多或少地限于这3个选项(或者我?)
我正在尝试从我的视频数据库中获取视频,选择基于external_id和language_id(两个整数)的独特组合.我尝试了以下代码,但它看起来findFirst()只是拿起第一个标准
$video = Video::findFirst("language_id=" . $language->id . " and external_id=" . $external->id);
Run Code Online (Sandbox Code Playgroud)
任何人都可以帮助我如何正确使用具有多个标准的findFirst?
看看下面的XAML.
当我用鼠标悬停在它上面时,我希望«HelloText»TextBlock"发光"(因此故事板而不是IsMouseOver上的触发器).由于两个TextBlock具有相同的名称,因此下面的代码不起作用.如何编辑此代码以便我可以将«MyStackPanelStyle»应用于多个StackPanel?
<Window.Resources>
<Style TargetType="StackPanel" x:Key="MyStackPanelStyle">
<Style.Triggers>
<EventTrigger RoutedEvent="StackPanel.MouseEnter">
<BeginStoryboard>
<Storyboard>
<ColorAnimation Duration="0:0:0.5" Storeboard.TargetName="HelloText" Storyboard.TargetProperty="(Foreground).(SolidColorBrush.Color)" To="LightGray" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
<EventTrigger RoutedEvent="StackPanel.MouseLeave">
<BeginStoryboard>
<Storyboard>
<ColorAnimation Duration="0:0:0.5" Storeboard.TargetName="HelloText" Storyboard.Target="TextBlock" Storyboard.TargetProperty="(Foreground).(SolidColorBrush.Color)" To="#505050" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Style.Triggers>
</Style>
</Window.Resources>
<StackPanel style="MyStackPanelStyle">
<TextBlock Name="HelloText" Text="Hello" />
<TextBlock Text="World" />
</StackPanel>
<StackPanel style="MyStackPanelStyle">
<TextBlock Name="HelloText" Text="Hello" />
<TextBlock Text="World" />
</StackPanel>
Run Code Online (Sandbox Code Playgroud)
编辑:
我读过Sergio Loscialo的一篇文章,看起来很有前途.不幸的是,这个解决方案适用于从AnimationPlaceholder继承的所有目标元素,这意味着当我在我的页面上有多个StackPanel时它将无法工作.
Traceback (most recent call last):
File "C:\Users\Pradeep Tejwani\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\ext\commands\bot.py", line 892, in invoke
await ctx.command.invoke(ctx)
File "C:\Users\Pradeep Tejwani\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\ext\commands\core.py", line 797, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "C:\Users\Pradeep Tejwani\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\ext\commands\core.py", line 92, in wrapped
raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: RuntimeError: PyNaCl library needed in order to use voice
Run Code Online (Sandbox Code Playgroud)
这是我的错误,即使我已经安装了 pythonpynacl库discord.py[voice]。我尝试了很多次但仍然遇到同样的错误。我什至将我的库更新到了新版本,但没有任何改变。
代码:
@bot.command()
async def join(ctx):
channel = ctx.message.author.voice.channel
voice = get(bot.voice_clients, guild=ctx.guild)
if voice and voice.is_connected():
await voice.move_to(channel)
else:
voice = await channel.connect()
await voice.disconnect() …Run Code Online (Sandbox Code Playgroud)