avatar

点滴记忆


点滴记忆

Windows10 删除虚拟摄像头

0 条评论 Windows 无标签 帅木

Windows10 删除虚拟摄像头

有一些带有虚拟摄像头的软件,有的卸载后虚拟摄像头还在,干扰正常使用,如图:

1.如果是OBS的虚拟摄像头,在命令提示符(win+r输入 cmd)运行。

注意:C:\Program Files\obs-studio为你当前obs安装路径,按需修改。
regsvr32 /u "C:\Program Files\obs-studio\bin\32bit\obs-virtualsource.dll"
regsvr32 /u "C:\Program Files\obs-studio\bin\64bit\obs-virtualsource.dll"

2.如果是其它软件的,打开注册表编辑器(win+r输入 regedit)并搜索(ctrl+f)以下键,并删除对应的摄像头。

注意:只删除带摄像头名称的那一表项,不要删除父级节点。
计算机\HKEY_CLASSES_ROOT\CLSID\{860BB310-5D01-11d0-BD3B-00A0C911CE86}
计算机\HKEY_CLASSES_ROOT\CLSID\{A3FCE0F5-3493-419F-958A-ABA1250EC20B}
计算机\HKEY_CLASSES_ROOT\CLSID\{860BB310-5D01-11d0-BD3B-00A0C911CE86}
计算机\HKEY_CLASSES_ROOT\CLSID\{A3FCE0F5-3493-419F-958A-ABA1250EC20B}

3.或者在注册表搜摄像头名称,将对应的表项删除也行。
4.有的可能装有驱动,去已安装应用或者设备管理器中找一下。

Unity Vuforia在运行时动态创建图像目标

0 条评论 Unity AR 帅木

Vuforia在运行时动态加载图片作为识别对象 官方文档:https://developer.vuforia.com/library/objects/instant-image-targets using System.IO; using UnityEngine; using Vuforia; public class SideLoadImageTarget...

FFmpeg 常用命令

0 条评论 未分类 无标签 帅木
1. 命令生成页面:https://alfg.dev/ffmpeg-commander

2. 将mov格式视频转为unity可播放的webm透明视频
ffmpeg -i 1.mov -c:v libvpx -pix_fmt yuva420p -b:v 1M -auto-alt-ref 0 -metadata:s:v:0 alpha_mode="1" -c:a libvorbis 1.webm
3. 将序列帧转为unity可播放的webm透明视频

从第一张图片开始合成,5d中5代表图片序号长度为5位数

ffmpeg -i D:\Desktop\Video\xiaocui_%5d.png -auto-alt-ref 0 -c:v libvpx xiaocui.webm

从第61张图片开始合成

ffmpeg -start_number 61 -i D:\Desktop\Video\xiaocui_%5d.png -auto-alt-ref 0 -c:v libvpx xiaocui2.webm

Unity RuntimeInitializeOnLoadMethod

0 条评论 Unity 无标签 帅木
使用[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.AfterSceneLoad)]属性,可以在不挂载到任何游戏对象上的情况下在程序运行时执行此方法,方便在在程序初始化前做一些额外的初始化工作。

类似功能的有InitializeOnLoad(最先执行)、InitializeOnLoadMethod(第二执行)、RuntimeInitializeOnLoadMethod,前两个用在编辑器,第三个用在运行时,用法如下:

[InitializeOnLoad]
public class InitializeOnLoadTest
{
    /// <summary>
    /// 第一次打开 Unity 编辑器运行一次,脚本编译完成后运行一次,每次进入 Play 模式都运行一次。
    /// </summary>
    static InitializeOnLoadTest()
    {
        Debug.Log("InitializeOnLoad");
    }
}

 /// <summary>
 /// 第一次打开 Unity 编辑器运行一次,脚本编译完成后运行一次,每次进入 Play 模式都运行一次。
 /// </summary>
 [InitializeOnLoadMethod]
 private static void InitOnLoad1()
 {
     Debug.Log("InitializeOnLoadMethod");
 }

 /// <summary>
 /// 在每次进入 Play 模式时运行一次,还可以通过参数确定在加载场景之前还是之后调用方法。
 /// </summary>
 [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.AfterSceneLoad)]
 public static void Init()
 {
     Instantiate(Resources.Load<GameObject>("AppQuit")); 
 }
RuntimeInitializeLoadType更多参数如下所示:

AfterSceneLoad:在场景加载之后执行。
BeforeSceneLoad:在场景加载之前执行。
AfterAssembliesLoaded:所有程序集加载完成并且预加载的资源初始化后执行。
BeforeSplashScreen:在启动画面显示之前执行。
SubsystemRegistration:用于子系统(如图形、音频等)注册的回调。

关于ListBox的一些绑定

0 条评论 WPF ListBox 帅木

关于ListBox的一些绑定

  1. IsSelected
            <ListBox Grid.Column="1"  ItemsSource="{Binding MediaList}" SelectedIndex="0" >
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <Grid Margin="5">
                            <Image Source="{Binding Thumbnail}" Width="Auto" Height="50"/>
                            <Border x:Name="selectedBorder" IsHitTestVisible="False" BorderBrush="{DynamicResource PrimaryBrush}" BorderThickness="5"/>
                        </Grid>
                        <DataTemplate.Triggers>
                            <DataTrigger Binding="{Binding IsSelected, RelativeSource={RelativeSource AncestorType=ListBoxItem}}" Value="True">
                                <Setter TargetName="selectedBorder" Property="Visibility" Value="Visible" />
                            </DataTrigger>
                            <DataTrigger Binding="{Binding IsSelected, RelativeSource={RelativeSource AncestorType=ListBoxItem}}" Value="False">
                                <Setter TargetName="selectedBorder" Property="Visibility" Value="Collapsed" />
                            </DataTrigger>
                        </DataTemplate.Triggers>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>

    通过绑定IsSelected,来显示或者隐藏当前子项的边框。


INotifyPropertyChanged 属性

0 条评论 WPF MVVM 帅木

INotifyPropertyChanged 属性

由于 C# 不允许多个继承,如果你的类已经有了其它实现,不能再继承 ObservableObject 时,可以使用 INotifyPropertyChanged,同样需要分部类,示例:

/// <summary>
/// OtherSetting.xaml 的交互逻辑
/// </summary>
[INotifyPropertyChanged]
public partial class OtherSetting : UserControl
{
    public OtherSetting()
    {
        InitializeComponent();
    }

    [ObservableProperty]
    private string? title;
    [RelayCommand]
    private void SaveSetting()
    {

    }
}

官方解释:
该 INotifyPropertyChanged 类型是一个属性,允许将 MVVM 支持代码插入现有类型。 除了其他相关属性(ObservableObject 以及 ObservableRecipient),其用途是支持开发人员,在这种情况下,需要这些类型的相同功能,但目标类型已经从另一种类型实现。 由于 C# 不允许多个继承,因此这些属性可用于让 MVVM 工具包生成器将这些代码直接添加到这些类型中,从而避开此限制。
链接:https://learn.microsoft.com/zh-cn/dotnet/communitytoolkit/mvvm/generators/inotifypropertychanged

WPF EventToCommand 将事件转化为命令

0 条评论 WPF 无标签 帅木

WPF EventToCommand 将事件转化为命令

1.前台XAML

<ListBox Style="{DynamicResource ListBoxTransparent}" HorizontalContentAlignment="Center" ItemsSource="{Binding Datas}">
    <ListBox.ItemTemplate>
        <DataTemplate>
            <StackPanel Orientation="Vertical" Margin="0,10,0,10">
                <Image Width="40" Height="40" Source="{Binding ImgPath}"/>
                <TextBlock Margin="6,0,0,0" Text="{Binding Name}" HorizontalAlignment="Center"/>
                <i:Interaction.Triggers>
                    <i:EventTrigger EventName="MouseLeftButtonUp">
                        <i:InvokeCommandAction Command="{Binding DataContext.LeftBarMenuSelectionChangedCommand, RelativeSource={RelativeSource AncestorType=ListBox}}"
                                   CommandParameter="{Binding}" />
                    </i:EventTrigger>
                </i:Interaction.Triggers>
            </StackPanel>
        </DataTemplate>
    </ListBox.ItemTemplate>
    <i:Interaction.Triggers>
        <i:EventTrigger EventName="SelectionChanged">
            <i:InvokeCommandAction Command="{Binding LeftBarMenuSelectionChangedCommand}"
                                   CommandParameter="{Binding SelectedItem, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ListBox}}}" />
        </i:EventTrigger>
    </i:Interaction.Triggers>
</ListBox>


ListBox.Item中使用 {Binding DataContext.LeftBarMenuSelectionChangedCommand, RelativeSource={RelativeSource AncestorType=ListBox}} 来绑定ListBox的DataContext中的Command,如果不指定绑定源的话绑定的会是LstBox.Item中的Command。

ListBox使用 {Binding SelectedItem, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ListBox}}} 来绑定当前选中的项。
需要引用命名空间: xmlns:i="http://schemas.microsoft.com/xaml/behaviors"。

2.后台C#代码

 [RelayCommand]
 private void LeftBarMenuSelectionChanged(object obj)
 {
     if (obj is LeftBarDataModel data)
     {
         ShowMsg(data.Name);
     }
 }

C#代码中使用了CommunityToolkit.Mvvm。

WPF常见问题

0 条评论 WPF 无标签 帅木

1.Visual Studio 2022 报错: 当前上下文中不存在名称 ‘InitializeComponent’

如果错误存在但不影响正常运行,找到错误提示的那个文件,将 xxx.xaml 文件的属性更改为:,自定义工具会默认选中:MSBuild: Compile,如果已经是了,就切成其它,再改回来。


2.MVVM中,NotifyCanExecuteChangedFor无效

如果是这样写的:
[ObservableProperty]
[NotifyCanExecuteChangedFor(nameof(MyCommand))]
public string username;

NotifyCanExecuteChangedFor不会调用你的命令,它只会导致命令发出其CanExecuteChanged事件信号,如果你想在username发生变化时运行代码,只需执行以下操作:
[ObservableProperty]
public string username;

partial void OnUsernameChanged(string value)
{
// TODO: do stuff here
}
注意:分部函数的名称规则是 On-变量名称首字母大写-Changed
参考:
https://stackoverflow.com/questions/73234760/notifycanexecutechangedfor-doesnt-execute-command-given-mvvm-community-toolkit
https://www.answeroverflow.com/m/1039952267069096006


3.Unable to cast object of type 'Microsoft.VisualStudio.XSurface.Wpf.WpfSurfaceApp' to type 'xxx.App'

因为 XAML 设计器在其自己的进程(WpfSurface.exe) 中运行,因此具有其自己的 Application 对象。
比如标记了:d: DataContext = "{d:DesignInstance vm:xxxViewModel,IsDesignTimeCreatable=True}" 且在xxxViewModel的无参构造函数里使用了App.Current就会有这个错误。
简单粗暴的解决方案就是不要在设计器进程使用Application,或者通过判断当前是否处在设计模式下,参考如下:
https://developercommunity.visualstudio.com/t/error-xdg0062-unable-to-cast-object-of-type-micros/1485738
https://stackoverflow.com/questions/425760/is-there-a-designmode-property-in-wpf


WPF知识点记录

0 条评论 WPF 无标签 帅木

1. WPF-隐藏窗体标题栏和边框

https://blog.csdn.net/Maybe_ch/article/details/121853170
https://blog.csdn.net/weixin_43676950/article/details/123726667

2. WPF中控制窗口显示位置的三种方式

https://blog.csdn.net/BeanGo/article/details/126278080

3.MVVM模式解析和在WPF中的实现

https://www.cnblogs.com/durow/p/4853729.html

4.ObservableCollection.CollectionChanged

FileDatas.CollectionChanged += (s, e) =>
 {
     if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Add)
     {
         //e.NewItems为当前添加的,e.OldItems==null
     }
     if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Remove)
     {
         //e.NewItems==null,e.OldItems为当前删除的
     }
 };

4.Xaml 设计时数据(Design-Time Data)绑定

class="prettyprint lang-cs linenums">xmlns:vm="clr-namespace:MyApp.ViewModel"
d:DataContext="{d:DesignInstance vm:xxxViewModel,IsDesignTimeCreatable=True}"

在XAML中设置数据上下文(DataContext)的一种方式,用于在设计时为视图提供一个模型实例。
这里的 d:DesignInstance 属性用于指定一个设计时的数据上下文实例,而 vm:xxxViewModel 则是指定该实例的类型。
IsDesignTimeCreatable=True 表示该实例在设计时可以被创建,这对于设计时的数据绑定和预览非常有用。
在设计时,这种方法可以帮助开发者在不运行应用程序的情况下,就能在设计视图中看到数据绑定的效果。
这对于开发者来说是非常方便的,因为它可以提前预览和调整界面布局和数据绑定,而不需要每次都运行应用程序来查看效果。
这些数据仅由XAML设计器使用,并且不会被编译到应用程序中。
注意:不要在xxxViewModel的无参构造函数里写Application相关的,不然会引发错误:Unable to cast object of type 'Microsoft.VisualStudio.XSurface.Wpf.WpfSurfaceApp' to type 'xxx.App'

常见中文乱码原因

0 条评论 未分类 无标签 帅木