我刚刚开始看看xamarin,现在我想扫描蓝牙设备.因此我使用以下代码:
BluetoothAdapter bluetoothAdapter = BluetoothAdapter.DefaultAdapter;
bluetoothAdapter.StartDiscovery();
Run Code Online (Sandbox Code Playgroud)
我得到以下class结果:
[BroadcastReceiver]
[IntentFilter(new [] {BluetoothAdapter.ActionDiscoveryFinished})]
public class BluetoothReceiver : BroadcastReceiver
{
public BluetoothReceiver()
{
}
public override void OnReceive(Context context, Intent intent)
{
if (BluetoothAdapter.ActionDiscoveryFinished.Equals(intent.Action))
{
}
}
}
Run Code Online (Sandbox Code Playgroud)
我还将我的应用程序的权限设置为BLUETOOTH和BLUETOOTH_ADMIN.一切正常,OnReceive-Method被正确调用.我现在的问题是:如何从OnReceive-Method的参数中获取找到的设备?
我有一个具有以下属性的类:
public Action<bool> Action { get; private set; }
Run Code Online (Sandbox Code Playgroud)
我有一个构造函数Action<bool> 作为参数.
现在我想添加另一个接受类型对象的构造函数Action.我怎样才能转换Action成Action<bool>?在这种情况下,bool参数应该为true.
我在winforms-application中遇到数据绑定问题.在下面的代码中,我有一个数据绑定到文本框的enabled属性.启用状态取决于复选框的值.
tbAmount.DataBindings.Add("Enabled", checkBox, "Checked",
false, DataSourceUpdateMode.OnPropertyChanged);
Run Code Online (Sandbox Code Playgroud)
如果选中该复选框,则在此代码中启用文本框.但我需要它倒置.如果取消选中该复选框,我希望启用文本框.我怎样才能实现这一目标?
我想将所有文件部署在单元测试目录中的文件夹中.通过DeploymentItem-Attribut部署eacht项目太多了.
我试过类似的东西
[DeploymentItem(".\\")]
Run Code Online (Sandbox Code Playgroud)
要么
[DeploymentItem("*.*")]
Run Code Online (Sandbox Code Playgroud)
但两者都不起作用.
有没有人知道如何通过Deployment-Attribut部署所有子文件夹的所有文件?
最近我读到了一个IValueConverter也继承自的东西MarkupExtension.它是这样的:
internal class BoolToVisibilityConverter : MarkupExtension, IValueConverter
{
private static BoolToVisibilityConverter converter;
public BoolToVisibilityConverter()
{
}
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is bool)
{
if ((bool)value)
{
return Visibility.Visible;
}
}
return Visibility.Collapsed;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is Visibility)
{
Visibility visibility = (Visibility)value;
if (visibility == Visibility.Collapsed)
{
return false;
}
}
return true;
}
public override …Run Code Online (Sandbox Code Playgroud) 我有一个功能,我可以对出现的窗口做出反应.现在我想知道出现的窗口是否是Messagebox.如果它是一个,我想阅读它的文本.
我已经能够提取Window-Title,Class-Name和Process-Id了
[DllImport("user32.dll", CharSet = CharSet.Unicode)]
internal static extern int GetWindowText(IntPtr hWnd, StringBuilder text, int count);
[DllImport("user32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
internal static extern int GetClassName(IntPtr hWnd, StringBuilder lpClassName, int nMaxCount);
[DllImport("user32.dll")]
internal static extern int GetWindowThreadProcessId(IntPtr hWnd, out int lpdwProcessId);
Run Code Online (Sandbox Code Playgroud)
但是我怎样才能找到消息框的文本?
为了得到所有窗口我使用这个:
internal static class WindowFinder
{
private static readonly List<IntPtr> listWindows = new List<IntPtr>();
private static bool IsWindowOrDialog(IntPtr hwnd, int lParam)
{
if (NativeMethods.IsHungAppWindow(hwnd) || !NativeMethods.IsWindowVisible(hwnd))
return true;
listWindows.Add(hwnd);
return true;
}
internal static IEnumerable<IntPtr> GetAllWindows() …Run Code Online (Sandbox Code Playgroud) 我需要从某个位置而不是从GAC加载程序集.我无法从GAC中删除程序集,因为我的程序必须在不同的计算机上运行,我无法控制程序集是否在GAC中.
我在我的项目中添加了对DLL-File的引用.不幸的是,汇编是从GAC加载的.
我App.xaml.cs在Startup-Event中尝试了以下代码
var directory = Thread.GetDomain().BaseDirectory;
var dllPath = Path.Combine(directory, "MyAssembly.dll");
var assembly = Assembly.LoadFrom(dllPath);
Run Code Online (Sandbox Code Playgroud)
不幸的是,程序集仍然是从GAC加载的.
即使程序集在GAC中,我还能从指定位置加载它?
I have a DataGrid where the ItemsSource is bound to an ObservableCollection<LogEntry>. On a click on a Button the user can scroll to a specific LogEntry. Therefor I use the following code:
private void BringSelectedItemIntoView(LogEntry logEntry)
{
if (logEntry != null)
{
ContentDataGrid.ScrollIntoView(logEntry);
}
}
Run Code Online (Sandbox Code Playgroud)
This just works fine. But what I don't like is: If the LogEntry already is in view then the DataGrid flickers shortly.
My question now is:
是否有可能检查DataGrid给定的 LogEntry 是否已经在视图中?
在互联网上搜索了一段时间后,没有成功,我会在这里询问。
互联网上的一些帖子说,不可能在Excel应用程序中将数字签名应用于VBA-Macro。但是我发现的所有文章都很老,所以我希望现在可以通过代码来完成。
我的目标是打开Excel文档,并假设存在宏,将数字签名应用于该文档的vba-macros。
我有以下代码来检测excel文档中是否存在VBMacros:
string filePath = @"E:\OfficeDocuments\Sample1.xlsm";
object isReadonly = true;
object missing = Missing.Value;
_Application application = new Microsoft.Office.Interop.Excel.Application();
workbook = application.Workbooks.Open(
filePath, missing, isReadonly, missing, missing, missing,
missing, missing, missing, missing, missing, missing,
missing, missing, missing);
bool workbookHasVbProject = workbook.HasVBProject;
Run Code Online (Sandbox Code Playgroud)
那很好。
现在,我获取要用于签署宏的证书:
X509Store store = new X509Store(StoreLocation.CurrentUser);
store.Open(OpenFlags.ReadOnly);
X509Certificate2Collection x509Certificate2Collection = store.Certificates;
X509Certificate2Collection certificate2Collection = x509Certificate2Collection.Find(X509FindType.FindBySubjectName, "MyCertificate 01", true);
if (certificate2Collection.Count > 0)
{
X509Certificate2 certificate = certificate2Collection[0];
}
Run Code Online (Sandbox Code Playgroud)
现在我不知道如何继续...
我试过了:
VBE vbe = application.VBE;
VBProject vbProject …Run Code Online (Sandbox Code Playgroud) 我创建了一个UserControl用于在我的应用程序中显示超链接。
这个标记UserControl看起来像:
<UserControl x:Class="MVVMExample.View.UserControls.ActionLink"
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"
mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="300"
DataContext="{Binding RelativeSource={RelativeSource Self}}">
<Grid>
<TextBlock Margin="5">
<Hyperlink Command="{Binding LinkCommand}" CommandParameter="{Binding LinkCommandParameter}">
<TextBlock Text="{Binding LinkText, UpdateSourceTrigger=PropertyChanged}"/>
</Hyperlink>
</TextBlock>
</Grid>
</UserControl>
Run Code Online (Sandbox Code Playgroud)
这在代码隐藏中DataContext,UserControl如下所示:
public partial class ActionLink : UserControl, INotifyPropertyChanged
{
public static readonly DependencyProperty LinkTextProperty = DependencyProperty.Register(
"LinkText", typeof (string), typeof (ActionLink), new PropertyMetadata(LinkTextChanged));
public static readonly DependencyProperty LinkCommandParameterProperty = DependencyProperty.Register(
"LinkCommandParameter", typeof (object), typeof (ActionLink),
new PropertyMetadata(LinkCommandParameterChanged));
public static readonly DependencyProperty LinkCommandProperty …Run Code Online (Sandbox Code Playgroud)