Tag: wpf

图像编辑例外

我正在使用MVVM在WPF应用程序中工作。 在imageSlider中加载和编辑图像会给我错误和exception。 加载图像: Insufficient memory to handle编辑图像: Sharing violation 视图模型: public class ImageList : INotifyPropertyChanged { #region Fields private ObservableCollection images = new ObservableCollection(); private int selectedIndex; private ImageItem currentImage; #endregion Fields #region Properties public ObservableCollection Images { get { return images; } set { images = value; } } public int SelectedIndex { get […]

使用ViewModel基于ViewModel属性更改视图

据我所知,在WPF中你可以这样做: 我的问题:有没有办法根据ViewModel中的属性选择View? 像这样的东西: //If property Selector==1 // If property Selector==2

System.Windows.Media.Animation警告:6

当我使用故事板在wpf中运行动画时,我在输出窗口中出现以下错误。 System.Windows.Media.Animation警告:6:无法执行操作,因为指定的Storyboard从未应用于此对象以进行交互式控制。 行动=“停止”; 故事板= ‘System.Windows.Media.Animation.Storyboard’; Storyboard.HashCode = ‘57850459’; Storyboard.Type = ‘System.Windows.Media.Animation.Storyboard’; TargetElement = ‘System.Windows.Media.Animation.Storyboard’; TargetElement.HashCode = ‘57850459’; TargetElement.Type = ‘System.Windows.Media.Animation.Storyboard’ 谁能告诉我它将如何影响我的程序以及如何删除它? 我没有在.xaml文件中定义storyboard。 但是当设计文件(.xaml)背后的代码我在类中创建了私有stoaryboard时,我使用代码中的以下语法将其分配给framework元素。 this.storyboard1.Begin(this.viewbox1, true); storyboard1是我在类中创建的对象,viewbox1是我要应用此动画的元素。 有谁能够帮我? 提前致谢。

程序占用太多内存

我正在使用WPF来开发康威生命游戏的模拟器。 出于某种原因,有时程序需要高达400,000K的内存(当我快速绘制很多单元格时)。 如何减少内存使用量和/或减少由此引起的滞后。 编辑1:主窗口代码: http : //pastebin.com/mz0z7tBu 网格类: http : //pastebin.com/ZHX1WBuK 细胞结构: struct Cell { public int Neighbors {get; set;} public bool Alive { get; set; } } 编辑2:我将尝试解释程序结构:单元格是一个结构,包含类型为int的AutoProperty邻居,以及类型为bool的AutoProperty IsAlive。 CellGrid是一个包装2D数组Cell的类。 每次迭代时,每个Cell的Neighbors属性都会更新为包含Neighbors活动的数量,然后每个Cell的IsALive设置为true或false,取决于邻居的数量和之前的IsAlive状态。 MainWindow类有一个CellGrid类型的对象。 它将网格呈现在屏幕上。 编辑3: XAML: http : //pastebin.com/Zp3dr8zc resources.xaml:

如何替换静态ObservableCollection,以便它可以在MVVM方式的所有窗口上访问

Atm我得到了一个带有静态ObservableCollection的类(somerandomclasss): public static ObservableCollection thepeoplelist = new ObservableCollection(); 但是,我正在将我的项目转换为MVVM,当然这不是填充所有项目控件的好方法(主要是listviews)我有多个窗口以这种方式使用此源。 private void UserControl_Loaded(object sender, RoutedEventArgs e) { lsvallthepeople.ItemSource = somerandomclasss.thepeoplelist; } 列表视图然后显示具有该信息的所有人。 然而,这不是我打赌的MVVM方式,我没有找到一个没有公共静态ObservableCollection的好方法,但是有一个窗口,你有一个listview,你可以编辑人员,他们在SQL中更新数据库和PersonViewModel(获得INotifyPropertyChanged)。 如果您需要更多信息,请随时询问ofc :)。

SetTarget vs RegisterName / SetTargetName

这是一个简单的程序,可以为Line的Y2属性设置动画。 请注意,我使用SetTarget方法来定位Line 。 这个程序工作正常。 using System; using System.Windows; using System.Windows.Controls; using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Shapes; namespace SoGeneratingAnimatedLine { public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); var canvas = new Canvas(); Content = canvas; var sb = new Storyboard(); var line = new Line() { X1 = 10, Y1 = 10, […]

出现wpf windows窗体后运行程序

您好我有wpf(c#)项目的问题。 这是我的来源 namespace WpfApplication1 { /// /// Interaction logic for MainWindow.xaml /// public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); MessageBox.Show(“Test”); } } } 我想运行我的程序 MessageBox.Show(“Test”); 在Windows窗体出现之后……但是在我启动程序的代码中,只需先在消息框中显示Test,然后出现该窗体! 我应该怎么做第一个窗体窗体,然后打开一个消息框来显示(测试)? 我正在使用visual studio 2015(WPF)项目

从menuitem更新WPF窗口图像,但在while循环中更新

好的,这是一个真正令人头疼的问题: 如果我选择一个导致图像的菜单项,构成整个窗口(一个writeableBitmap)以在其上绘制一些像素,它就会这样做并正确显示。 但是,如果我向同一个方法添加一个while循环(假设为5个循环),则位图上的绘图不会显示,直到循环完成,然后正确显示第5个重绘位图。 那么,当选择了一个菜单项但是在while循环中被跳过时,窗口中是否会出现某种“自动刷新”? 更多细节。 这很好用(带来一个’干净’的图像,在它上面绘制一些东西,显示它): // This brings in a ‘clean’ image writeableBitmap = new WriteableBitmap(CleanVegMap); image.Source = writeableBitmap; // This makes a bunch of draws on the bitmap DrawDinos2d(); 然而,这会“消失”10秒,然后只显示最后一个(即第5个)图像: int z = 0; while (z < 5){ z++; // This brings in a 'clean' image writeableBitmap = new WriteableBitmap(CleanVegMap); image.Source = writeableBitmap; […]

BindingExpression路径错误

有很多类似的问题,我从这些问题中尝试了很多答案,但到目前为止没有任何帮助。 我不明白错误信息实际意味着什么。 错误信息是; System.Windows.Data Error: 40 : BindingExpression path error: ‘CategoryModel’ property not found on ‘object’ ”String’ (HashCode=-57655201)’. BindingExpression:Path=CategoryModel.CategoryList; DataItem=’String’ (HashCode=-57655201); target element is ‘TextBlock’ (Name=”); target property is ‘Text’ (type ‘String’) CategoryList包含已填充的类别的字符串列表(从调试中检查)。 我的xaml在下面, xaml设计看起来不错,应用程序运行正常,但没有任何东西被填满。 应该在初始化时填充categoryList。 它实际填充但listView没有显示任何内容。 编辑: CategoryModel; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; namespace RecorderApp.Model […]

在单独的线程中启动WPF窗口

我正在使用以下代码在单独的线程中打开一个窗口 public partial class App : Application { protected override void OnStartup(StartupEventArgs e) { base.OnStartup(e); } private void button1_Click(object sender, RoutedEventArgs e) { Thread newWindowThread = new Thread(new ThreadStart(() => { // Create and show the Window Config tempWindow = new Config(); tempWindow.Show(); // Start the Dispatcher Processing System.Windows.Threading.Dispatcher.Run(); })); // Set the apartment state […]