Tag: xaml

MvvmCross MvxWindowsPage 编译错误

我正在使用MvvmCross框架编写Xamarin.iOS , Xamarin.Android和UWP跨平台应用程序。 我正在创建一个具有LoginViewModel的LoginPage。 在Xamarin.iOS , Xamarin.Android项目中,ViewModel和View的绑定与下面的工作正常 public class LoginActivity : MvxAppCompatActivity public partial class LoginViewController : MvxViewController 尝试在UWP项目上执行与上面相同的操作,我收到一些错误。 在XAML中: 我的C#代码是 public sealed partial class LoginView : MvxWindowsPage 但我得到编译错误。 我该如何解决? 元素’MvxWindowsPage’上的’未知成员’TypeArguments’ 名称“LoginViewModel”在命名空间“using:MyApp.PresentationCore.ViewModels”中不存在。 ‘MvvmCross.WindowsUWP.Views.MvxWindowsPage`1 [TViewModel]’上的GenericArguments [0],’System.Object’违反了’TViewModel’类型的约束。 我认为错误有点模棱两可,因为在第一个错误中没有模板化版本,但第三个错误是关于模板约束违规。 我知道有一个选项将ViewModel和View绑定到命名约定或属性,但我想使用这种强类型解决方案。

无法为Nullable Int32分配空值? 通过绑定

无法通过TextBox绑定到Int32?分配空值。 如果TextBox为空,则不调用Int32Null Set。 TexBox周围有一个红色边框,表示validationexception。 这只是Int32没有意义吗? 是可以为空的。 如果用户从TextBox中删除整数值,我希望调用Set,以便将属性赋值为null。 当它启动int32Null = null并且TextBox不是红色时。 我尝试实现validation,如果TextBox为空,则设置validation = true。 但仍未调用Set,TextBox为红色,表示validation错误。 看起来我应该能够通过绑定为空值分配空值。 public partial class MainWindow : Window { private Int32? int32Null = null; private string stringNull = “stringNull”; public MainWindow() { InitializeComponent(); } public Int32? Int32Null { get { return int32Null; } set { int32Null = value; } } public string […]

绑定到工具提示的wpf自定义控件依赖项属性?

我有一个我在WPF中编写的自定义控件,它有一个布尔依赖属性: public static readonly DependencyProperty IsAlertProperty = DependencyProperty.Register(“IsAlert”, typeof(bool), typeof(AlertControl), new FrameworkPropertyMetadata(default(bool), FrameworkPropertyMetadataOptions.None, OnIsAlertChanged, null, false, UpdateSourceTrigger.PropertyChanged)); public bool IsAlert { get { return (bool)GetValue(IsAlertProperty); } set { SetValue(IsAlertProperty, value); } } 在我的Generic.xaml中,我有以下xaml代码: … 问题是这似乎不起作用。 我使用Snoop监视我的xaml,并且IsAlert属性正在适当地改变,但是如果我深入研究我的AlertControl.ToolTip ,我看到Visiblity DependencyProperty有一个绑定错误。 我也尝试使用RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:AlertControl}} ,但这也给出了绑定问题。 我不知道如何诊断这个,因为我的输出窗口也没有吐出任何绑定表达式错误。

如何制作可与默认WCF服务应用程序一起使用的UWP

如果您创建一个新项目WCF Service Application C#,它将创建一个Web服务并启动它。 但是没有关于如何从客户端实际与之通信的信息,或者如何编写它。 UWP客户端与该服务通信的外观如何?

如何从C#中的资源字典(XAML)中获取值

我正在开发一个WPF应用程序,用户可以在运行时更改语言(而不是当前的文化!)。 所以我有多个XAML类型的资源词典,我添加了文本来制作我的WPF-app多语言: First name Last name Validation with DataAnnotations German English The first name has to be inserted WPF窗口和控件受窗口资源的约束。 但我正在使用DataAnnotations进行validation。 我的第一个想法是在我的viewmodel中validation时将文本传递给键“insert_first_name”。 所以我试图通过使用它来获得它: System.Windows.Application.Current.Resources.FindName(“insert_first_name”) 但是当我使用FindName方法时,我得到null。 当我尝试 System.Windows.Application.Current.Resources.Contains(“insert_first_name”) 我得到“真实”,这意味着密钥存在。 我怎样才能获得钥匙的价值? protected void ValidateModel() { validationErrors.Clear(); ICollection validationResults = new List(); ValidationContext validationContext = new ValidationContext(personmodel, null, null); if (!Validator.TryValidateObject(personmodel, validationContext, validationResults, true)) { foreach (ValidationResult validationResult in […]

从屏幕上的鼠标光标位置获取图像坐标(WPF图像控件)

我正在寻找一个透明地为WPF图像控件添加平移和缩放function的解决方案,我找到了由WiesławŠoltés和Konrad Viltersten开发的解决方案https://stackoverflow.com/a/6782715/584180 ,这是非常出色的。 现在我想在控件中添加一个“鼠标点击”事件,以便我可以在原始图像坐标系中点击点击的坐标,这样我就可以使用它们来检索像素颜色。 我知道会有一些舍入,如果图像缩小,颜色将与屏幕上显示的实际颜色不对应。 我也明白,用户可能会在图像边框外单击,在这种情况下,我希望返回空点或负坐标。 我不是C#进行转换的方法的专家,目前我仍然坚持这一点(要在ZoomBorder.cs类中添加): public Point GetImageCoordsAt(MouseButtonEventArgs e) { if (child != null) { var tt = GetTranslateTransform(child); var mousePos = e.GetPosition(this); var transformOrigin = new Point(tt.X, tt.Y); return mousePos; // Wrong: how do I transform this? } return null; }

在代码而不是XAML中呈现UserControl

我想使用RenderTargetBitmap将UserControl呈现为位图,而不必为其编写XAML。 当我这样做时,我得到一张空白图片,我错过了关键一步吗? ValTool.Controls.VideoFisheyeOverlayControl vfoc = new Controls.VideoFisheyeOverlayControl(); vfoc.Width = (int)this.VideoContainer.ActualWidth; vfoc.Height = (int)this.VideoContainer.ActualHeight; vfoc.FieldsOfView=this.FieldsOfView; vfoc.CountLines = this.CountLines; vfoc.UpdateLayout(); vfoc.InvalidateVisual(); RenderTargetBitmap visual = new RenderTargetBitmap((int)this.VideoContainer.ActualWidth, (int)this.VideoContainer.ActualHeight, 96, 96, PixelFormats.Pbgra32); visual.Render(vfoc); var finalImage = BitmapFrame.Create(visual); // Encoding the RenderBitmapTarget as a PNG file. PngBitmapEncoder png = new PngBitmapEncoder(); png.Frames.Add(BitmapFrame.Create(finalImage)); using (Stream stm = File.Create(@”new.png”)) { png.Save(stm); }

Metro Application如何读取XML API?

好的,我正在尝试学习如何使用XAML以及如何使用Visual Studio 11 Developer Preview构建新的windows metro应用程序。 我有一个问题,虽然我不知道如何读取XML文件,就像我使用C#一样。 例如,这是我过去的做法。 private void Button_Click(object sender, RoutedEventArgs e) { string UrlString = “http://v1.sidebuy.com/api/get/73d296a50d3b824ca08a8b27168f3b85/?city=nashville&format=xml”; XmlTextReader reader = new XmlTextReader(UrlString); XmlNodeType type; while (reader.Read()) { type = reader.NodeType; if ((type == XmlNodeType.Element) && (reader.Name == “highlights”)) { reader.Read(); if (reader.Value != “” && reader.Value != null) { listBox1.Items.Add(reader.Value); } } } […]

WPF更改ListView滚动速度

我有一个带有自定义单元格(项目)的ListView 。 此ListView表示两个人与我的应用程序交换消息之间的对话。 每次添加消息时,对话都会自动滚动到最后一个项目。 我面临一些“奇怪”的问题: 当用户写一个相当长的消息(比如10行)时,它几乎可以占据整个屏幕(意味着分配给ListView的空间),这当然是正常的,但滚动有点破坏 。 首先,当列表自动滚动到此消息时,项目下方会出现一个大的空白区域,一直到我的ListView底部。 见图: 当消息很短(单行)时: 其次,在所有情况下,滚动速度都是快速的。 单个mous-wheel“笔划”(滚动时手指的感觉)会使滚动条移动太快:滚动最多4条小信息! 这太多了 ! 所以问题是:如何控制滚动速度? 如何放慢速度? 为什么会有这么大的白色空间? 谢谢您的帮助 ! [更新1] 请求@CurtisHx我的ListView XAML如下: http://pastebin.com/FFZGhi6w 我希望它有助于理解我的问题!

删除按钮wpf上的蓝色突出显示

我正在制作一个WPF项目。 在运行应用程序时,当我将光标移动到一个按钮时,它会被填充在其中的蓝色突出显示。 现在,我想删除这个亮点……我该怎么办?