我的问题非常简单,我想通过一个简单的例子得到一个明确的答案.
API,工具包,框架和库之间的主要区别是什么?
我想请你帮忙解决一下WebCamera问题.我使用过Nuget的图书馆; WebEye.Controls.Wpf.WebCameraControl(版本1.0.0).该URL为https://www.nuget.org/packages/WebEye.Controls.Wpf.WebCameraControl/
文章和说明可在以下网址获得:http://www.codeproject.com/Articles/330177/Yet-another-Web-Camera-control
由于项目限制,我为Linx平板电脑(Windows 10)开发了WPF应用程序,而不是通用Windows应用程序.我使用WebEye库连接到平板电脑上的网络摄像头并用它拍照.当我在平板电脑中握住平板电脑时,它可以正常工作,但是当我在平板电脑模式下握住平板 在纵向模式下,CameraPreview/VideoWindow会自动旋转-90度.
我尝试解决问题无济于事.
无论我做什么,相机预览总是-90度.
该库很简单,它没有很多属性来操作视频窗口.
webcontrol在XAML中.
<wpf:WebCameraControl x:Name="webCameraControl"
MouseDoubleClick="webCameraControl_MouseDoubleClick"
StylusButtonUp="webCameraControl_StylusButtonUp"
MouseUp="webCameraControl_MouseUp"
TouchUp="webCameraControl_TouchUp"
GotMouseCapture="webCameraControl_GotMouseCapture"
/>
Run Code Online (Sandbox Code Playgroud)
这就是我初始化WebCamera的方式.加载UserControl后,它将自动连接到平板电脑上的网络摄像头.请参见startViewing()函数.
private WebCameraId _cameraID = null;
private void UserControl_Loaded(object sender, RoutedEventArgs e)
{
startViewing();
}
private void startViewing()
{
List<WebCameraId> cams = (List<WebCameraId>)webCameraControl.GetVideoCaptureDevices();
if (cams.Count > 0)
{
_cameraID = (WebCameraId)cams[0];
webCameraControl.StartCapture(_cameraID);
}
}
Run Code Online (Sandbox Code Playgroud)
当应用程序检测到显示屏幕中的更改时,我试图强制控件正确旋转它.请参见DisplaySettingsChanged事件.
public ucWebCam()
{
InitializeComponent();
Microsoft.Win32.SystemEvents.DisplaySettingsChanged += SystemEvents_DisplaySettingsChanged;
}
private void SystemEvents_DisplaySettingsChanged(object sender, EventArgs …
Run Code Online (Sandbox Code Playgroud) 我的问题很简单,但遗憾的是我找不到任何答案.
使用MEF,我可以在类库程序集中指定一些内部导出和导入,如下所示:
[Export]
internal class SomeExport
{ }
[ModuleExport(typeof(SomeModule))]
internal class SomeModule : IModule
{
[ImportingConstructor]
internal SomeModule(SomeExport instance)
{ }
}
Run Code Online (Sandbox Code Playgroud)
我的CompositionContainer位于主EXE程序集中,但不知何故它设法SomeExport
在类库程序集中实例化对象,以便我可以使用它.通常,我的内部类库类型不应该从EXE程序集中访问,但不知何故我创建了我的实例.
它是如何工作的?
我出于好奇创建了一个简单的基准,但无法解释结果.
作为基准数据,我准备了一些带有一些随机值的结构数组.准备阶段没有基准:
struct Val
{
public float val;
public float min;
public float max;
public float padding;
}
const int iterations = 1000;
Val[] values = new Val[iterations];
// fill the array with randoms
Run Code Online (Sandbox Code Playgroud)
基本上,我想比较这两个钳位实现:
static class Clamps
{
public static float ClampSimple(float val, float min, float max)
{
if (val < min) return min;
if (val > max) return max;
return val;
}
public static T ClampExt<T>(this T val, T min, T max) where T : IComparable<T>
{
if …
Run Code Online (Sandbox Code Playgroud) 我需要获得运行测试的桌面的分辨率。以前我是这样抓取分辨率的:
Screen screen = Screen.PrimaryScreen;
int screenWidth = screen.Bounds.Width;
int screenHeight = screen.Bounds.Height;
Run Code Online (Sandbox Code Playgroud)
不幸的是,System.Windows.Forms
不能再使用了。我的项目是 .NET Core,所以我最好为此需要一个 NuGet 包。
如果有人有任何建议,我将不胜感激。
如何在C#代码中使用wpflocalizeextension?在xaml中,为了获取本地化字符串,我可以使用它,如下所示:
<Window x:Class="SomeClass"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:lex="http://wpflocalizeextension.codeplex.com"
lex:LocalizeDictionary.DesignCulture="uk-UA"
lex:ResxLocalizationProvider.DefaultAssembly="DesktopApp"
lex:ResxLocalizationProvider.DefaultDictionary="Resources">
<Button Content="{lex:Loc SignInBtn}"/>
Run Code Online (Sandbox Code Playgroud)
例如,如何在代码中获取本地化字符串MessageBox.Show("SignInBtn");
?
I have an in-memory assembly MyAssembly
(class library) that is used in my main assembly MyApp.exe
:
byte[] assemblyData = GetAssemblyDataFromSomewhere();
Run Code Online (Sandbox Code Playgroud)
(For testing, the GetAssemblyDataFromSomewhere
method can just do File.ReadAllBytes
for an existing assembly file, but in my real app there is no file.)
MyAssembly
has only .NET Framework references and has no dependencies to any other user code.
I can load this assembly into the current (default) AppDomain
:
Assembly.Load(assemblyData);
// this works
var obj = Activator.CreateInstance("MyAssembly", "MyNamespace.MyType").Unwrap();
Run Code Online (Sandbox Code Playgroud)
Now, …
我想要的是
每当Windows中的时区更改时,我都想做些事情。
到目前为止我有什么
为此,我实现了事件SystemEvents.TimeChanged,如下所示:
在构造函数中:
SystemEvents.TimeChanged += SystemEvents_TimeChanged;
Run Code Online (Sandbox Code Playgroud)
事件主体:
void SystemEvents_TimeChanged(object sender, EventArgs e)
{
MessageBox.Show("Test1");}
Run Code Online (Sandbox Code Playgroud)
问题是什么
在Windows中更改时间或时区时,不会触发该事件。
我尝试过的
当我在干净的WinForms应用程序中编写以上代码时,一切都按预期工作。但是在我的应用程序中却没有,原因是包含许多其他代码。我看不到我还有其他任何事件,应该阻止上述事件的触发。
我的问题是
有谁知道什么可能导致上述代码无法在我的应用程序中触发,但是在创建仅包含上述代码的新项目/应用程序时按预期工作?
更新1
这是因为我在调用之前在单独的线程中显示了启动屏幕
Application.Run(new FormMain());
Run Code Online (Sandbox Code Playgroud)
然后,SystemEvents会坚持启动屏幕创建的线程,即使在加载应用程序后该线程也会终止。
现在的问题是,是否有一种方法可以告诉SystemEvents,当应用程序加载后,现在应该使用“正确的” UI线程吗?
我正在从MVC中的回发进行实体更新:
ControlChartPeriod period = _controlChartPeriodService.Get(request.PeriodId);
if (period != null)
{
SerializableStringDictionary dict = new SerializableStringDictionary();
dict.Add("lambda", request.Lambda.ToString());
dict.Add("h", request.h.ToString());
dict.Add("k", request.k.ToString());
period.Parameters = dict.ToXmlString();
// ToDo : fails on save every now and then when one of the values changes; fails on Foreign Key being null
try
{
_controlChartPeriodService.Update(period, request.PeriodId);
return Ok(request);
}
Run Code Online (Sandbox Code Playgroud)
更新方法如下所示:
public TObject Update(TObject updated, TKey key)
{
if (updated == null)
return null;
TObject existing = _context.Set<TObject>().Find(key);
if (existing != null)
{
_context.Entry(existing).CurrentValues.SetValues(updated);
_context.SaveChanges();
}
return …
Run Code Online (Sandbox Code Playgroud) 我的viewmodel中有一组变量:
public ObservableCollection<ObservableVariable> Variables { get; }= new ObservableCollection<ObservableVariable>();
Run Code Online (Sandbox Code Playgroud)
ObservableVariable类有两个属性:string Name和bool Selected; 该类实现了INotifyPropertyChanged,
我的目标是将此集合绑定到WPF视图中的清单,并使用MultiBinding实现绑定到该列表的"全选"复选框.下图说明了所需的视图.
观察下面的XAML:
<CheckBox Content="Select All" Name="SelectAllCheckbox"></CheckBox>
...
<ListBox ItemsSource="{Binding Variables}">
<ListBox.ItemTemplate>
<DataTemplate>
<CheckBox Content="{Binding Name}">
<CheckBox.IsChecked>
<MultiBinding Converter="{StaticResource LogicalOrConverter}" Mode="TwoWay">
<Binding Path="Selected"></Binding>
<Binding ElementName="SelectAllCheckbox" Path="IsChecked"></Binding>
</MultiBinding>
</CheckBox.IsChecked>
</CheckBox>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
Run Code Online (Sandbox Code Playgroud)
LogicalOrConverter可以使用任意数量的bool; 如果有的话,返回true.
如您所见,每个复选框都绑定到viewmodel中的变量和'select all'复选框的状态.目前,一切都按预期工作除了以下内容:如果单击"全选",复选框将在视图中更新,但更改不会传播回视图模型.
注意,我的实现中的大多数事情都能正常工作 例如,如果单击某个复选框,则视图模型会正确更新.
问题更详细:
当我单击一个单独的复选框时,OnPropertyChanged事件将在其框刚刚更改的变量中触发; 转换器中的ConvertBack函数被触发; viewmodel已更新,一切正常.
但是,当我单击"全选"复选框时,视图中会更新各个复选框,但不会在任何变量中调用OnPropertyChanged,并且不会调用转换器中的ConvertBack函数.
同样相关,如果我取消选中"全选",个别支票会回到之前的状态.
更新viewmodel的唯一方法是单击各个复选框.但是,多绑定适用于视图.
我的问题是:
为什么不对复选框中的更改传播到viewmodel中的源集合
转换器:
public class LogicalOrConverter : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
foreach (object arg …
Run Code Online (Sandbox Code Playgroud) c# ×9
wpf ×3
.net ×2
.net-core ×1
api ×1
appdomain ×1
benchmarking ×1
composition ×1
directshow ×1
events ×1
frameworks ×1
localization ×1
mef ×1
mono ×1
multibinding ×1
mvvm ×1
ryujit ×1
terminology ×1
toolkit ×1
webcam ×1
winforms ×1