我有一个静态类(Evp),位于Models文件夹中。它有一个Name字符串,带有 getter 和 setter 以及 aPropertyChangedEventHandler及其代码:
public static event PropertyChangedEventHandler StaticPropertyChanged;
private static string _name
public static string Name{
get => _name;
set{
_name = value;
OnStaticPropertyChanged("Name"); } }
private static void OnStaticPropertyChanged(string propertyName)
{
StaticPropertyChanged?.Invoke(null, new PropertyChangedEventArgs(propertyName));
}
Run Code Online (Sandbox Code Playgroud)
在我的 XAML 文件中,这就是我尝试绑定的方式(如果我没记错的话,它在 WPF 4.5 中有效):
<Label Grid.Row="0" Grid.Column="1" TextColor="Beige" Text="{Binding Source={x:Static Models:Evp.Name}}" HorizontalTextAlignment="Center" VerticalTextAlignment="Center" FontSize="30"></Label>
Run Code Online (Sandbox Code Playgroud)
我Models在 XAML 中指定了文件夹ContentPage:
xmlns:Models="clr-namespace:Rdb.Models;assembly=Rdb"
Run Code Online (Sandbox Code Playgroud)
由于某种原因,它不起作用。我究竟做错了什么?另外,如何在代码隐藏中设置此绑定?
我正在开发一个uwp平台,该平台允许使用imgur api将图像上传到imgur。我正在这样做:
var picker = new Windows.Storage.Pickers.FileOpenPicker();
picker.ViewMode = Windows.Storage.Pickers.PickerViewMode.Thumbnail;
picker.SuggestedStartLocation =
Windows.Storage.Pickers.PickerLocationId.PicturesLibrary;
picker.FileTypeFilter.Add(".jpg");
picker.FileTypeFilter.Add(".jpeg");
picker.FileTypeFilter.Add(".png");
String path;
Windows.Storage.StorageFile file = await picker.PickSingleFileAsync();
if (file != null)
{
path = file.Path;
}
else
{
path = "Operation cancelled.";
}
try
{
var client = new ImgurClient("id", "secret");
var endpoint = new ImageEndpoint(client);
IImage img;
await Task.Run(async () =>
{
await Task.Yield();
Debug.Write("crash at FileStream\n");
using (var fs = new FileStream(@path, FileMode.Open, FileAccess.Read, FileShare.Read))
{
Debug.Write("crash at Upload\n");
img = await …Run Code Online (Sandbox Code Playgroud) 我最近收到了UWP应用程序的真正头痛问题.基本上我想根据动作更改我的应用程序的主图标.假设某个用户登录我的应用程序,以便在关闭应用程序后看不到默认的应用程序图标,我想更改应用程序图标.
我找到了不同的链接,这些链接指的是瓷砖上的工作,它完美地运行.但我没有提出改变应用程序图标的解决方案.
有没有像在iOS中使用AlternateIcons或在Android中调用的方式Alias?
我在课堂上有一个房产
public class User {
public string FiscalCode {get; set;}
}
Run Code Online (Sandbox Code Playgroud)
我想用两个条件测试属性财务代码.如果财务代码为空或财务代码由方法验证,则测试正常
public bool FiscalCodeIsCorrect(string fiscalcode)
{
....
}
Run Code Online (Sandbox Code Playgroud)
如果验证了两个条件中的一个,我该如何在一条线上进行测试?
我想在测试项目中使用这个条件,所以代码行可以
user.FiscalCode.ShouldBeOneOf()
Run Code Online (Sandbox Code Playgroud)
但我不能因为null而且string是两种不同的类型.
我有个约会.我想将所有日期部分读出到单独的字符串中,并在适用的情况下使用前导0,然后将它们连接起来创建一个日期字符串,它只是没有任何分隔符的数字.
例如:
DateTime dt = DateTime.Now;
string year = dt.Year.ToString();
string month = dt.Month.ToString();
string day = dt.Day.ToString();
string hour = dt.Hour.ToString();
string minutes = dt.Minute.ToString();
string seconds = dt.Second.ToString();
string finalDt = string.Concat(year, month, day, hour, minutes, seconds);
Run Code Online (Sandbox Code Playgroud)
如果是1月,我想月是01,如果是第3天则是03,并且同样以小时,年,秒.有没有办法实现这一点,而无需检查每个日期部分的计数,并用前导0填充它?
如果有更好的方法来完成我想要做的整体,那么我想建议.
我目前正在使用c#6,但是需要回到VS2013进行项目,所以想知道以下表达式身体功能成员是否具有与之前版本的C#中相同的"糖":
public string FullAddress => $"{Title} {FirstName} {LastName}, {Street}, {City} {ZIP}";
Run Code Online (Sandbox Code Playgroud)
Title,FirstName,Lastname等是在调用FullAddress之前在类中初始化的所有其他属性.
我有一个 DateTime 数据类型变量,它绑定到一个日期选择器。
日期选择器 XAML:
<CalendarDatePicker Name="dpDate" VerticalAlignment="Center"
Date="{Binding dpDateTime, ElementName=this, Mode=TwoWay}"
DateChanged="dp_DateChanged">
</CalendarDatePicker>
Run Code Online (Sandbox Code Playgroud)
后面的代码,它设置值:
dpDatetime = DateTime.Now;
Run Code Online (Sandbox Code Playgroud)
但是 datepicker 没有选择当前日期,而是将日期选择为 1/1/1917
我尝试使用UWP的平板扫描仪。检查的文件,它看上去简单明了。
但是我肯定会错过一些东西,因为我无法构建(ImageScanner在编辑器中强调):
找不到类型或名称空间名称“ ImageScanner”
显然,我有使用Windows.Devices.Scanners;在文件中。甚至那也很奇怪,因为IntelliSense找不到该名称空间,但是using行不会引起任何错误。我尝试使用垃圾名称空间,并且按预期方式使用失败。
我的项目是一个新的Windows Universal Blank App。刚刚开始写我的课还没什么改变。
Visual Studio 2017 v4.7.03056
目标平台版本:10.0.17134.0
我应该更改一些项目属性或应用清单吗?我读过的唯一一本书是,此扫描程序API仅在台式机UWP上有效,而在移动设备上无效。我试图改变TargetDeviceFamily在appxmanifest从Windows.Universal到Windows.Desktop,但没有帮助。
我之前曾在一篇关于如何动态添加按钮的帖子上询问过.现在,我已经添加额外image旁边的button指示连接状态的的客户机.我有2个buttons一个增加,另一个删除的button和image.点击后,将有一个menuflyout选择要删除的相应按钮.我的问题是我设法添加状态,image但是当点击删除时 button,menuflyout运行exception说明System.InvalidCastException.
我的代码如下; 请帮忙.谢谢.
public Uri connectedUri = new Uri("ms-appx:///Assets/icon-connected.png");
public Uri disconnectedUri = new Uri("ms-appx:///Assets/icon-disconnected.png");
private void AddMenuFlyoutItem_Click(object sender, RoutedEventArgs e)
{
var item = sender as MenuFlyoutItem;
var deviceName = item.Text;
var deviceIP = item.Tag;
Button b = new Button();
b.Height = 30;
b.Width = 100; …Run Code Online (Sandbox Code Playgroud) 我正在开发一个Android / iOS / UWP Xamarin.Forms应用程序。最近几周,我主要研究Android / iOS应用程序。现在,我想再次在UWP中启动我的应用程序并得到错误消息:
System.TypeLoadException
HResult=0x80131522
Message=Could not find Windows Runtime type 'Microsoft.Graphics.Canvas.UI.Xaml.CanvasImageSource'.
Source=Xamarin.Forms.Platform.UAP
StackTrace:
at Xamarin.Forms.Platform.UWP.ImageRenderer.GetDesiredSize(Double widthConstraint, Double heightConstraint)
at Xamarin.Forms.Platform.UWP.Platform.GetNativeSize(VisualElement element, Double widthConstraint, Double heightConstraint)
at Xamarin.Forms.Platform.UWP.WindowsBasePlatformServices.GetNativeSize(VisualElement view, Double widthConstraint, Double heightConstraint)
at Xamarin.Forms.VisualElement.OnSizeRequest(Double widthConstraint, Double heightConstraint)
at Xamarin.Forms.Image.OnSizeRequest(Double widthConstraint, Double heightConstraint)
at Xamarin.Forms.VisualElement.OnMeasure(Double widthConstraint, Double heightConstraint)
at Xamarin.Forms.VisualElement.GetSizeRequest(Double widthConstraint, Double heightConstraint)
at Xamarin.Forms.VisualElement.Measure(Double widthConstraint, Double heightConstraint, MeasureFlags flags)
at Xamarin.Forms.StackLayout.CalculateNaiveLayout(LayoutInformation layout, StackOrientation orientation, Double x, Double y, Double widthConstraint, Double heightConstraint)
at Xamarin.Forms.StackLayout.CalculateLayout(LayoutInformation …Run Code Online (Sandbox Code Playgroud)