Tag: wpf

在stackpanel WPF中排序元素

我有一个stackpanel,其中包含一些在运行时添加或删除的用户控件。 这些元素有一个索引,当我新建它时,我需要保留这些索引,我需要保持这些元素按索引排序,所以我做了一个quicksort函数,根据索引对它们进行排序,但是在交换的行上 y = items[i]; //y is a temp variable items[i] = items[j]; 我明白了 “指定的索引已在使用中。首先断开指定索引处的Visual子节点” 我尝试将它们复制到临时变量,从集合中删除它们然后使用UIElementCollection中的Insert函数将它们分配到它们的右侧索引,但后来我得到了 “指定的Visual已经是另一个Visual的子项或CompositionTarget的根” 是否有我需要的克隆元素或某些东西在某处丢失?

有没有办法将可观察的集合转换为常规集合?

我有一个测试集合设置为: ObservableCollection MyselectedPeople = new ObservableCollection(); public MainWindow() { InitializeComponent(); FillData(); } public void FillData() { Person p1 = new Person(); p1.NameFirst = “John”; p1.NameLast = “Doe”; p1.Address = “123 Main Street”; p1.City = “Wilmington”; p1.DOBTimeStamp = DateTime.Parse(“04/12/1968”).Date; p1.EyeColor = “Blue”; p1.Height = “601”; p1.HairColor = “BRN”; MyselectedPeople.Add(p1); } 一旦我构建了这个集合,我希望能够将Observable Collection转换为List类型。 这背后的原因是我的主要项目是接收带有数据的通用列表,我必须将其转换为Observable集合,以便在gridview,列表框等中使用。在UI中选择数据,然后将其发送回原始程序集以供进一步使用。

如何将ConfigurationManager.AppSettings与自定义部分一起使用?

我需要使用App.config文件获取“ http://example.com ”。 但目前我正在使用: string peopleXMLPath = ConfigurationManager.AppSettings[“server”]; 我无法获得价值。 你能指出我做错了什么吗?

如何将Wpf窗口设置为Winforms表单的所有者

如何将System.Windows.Window设置为System.Windows.Forms.Form的所有者? 在我搜索了一段时间后才意识到我已经在我的一个utils类中得到了答案,我决定将答案放在stackoverflow上。 希望有人发现这很有用。

DataGrid和数组之间的双向绑定

我有一个名为的数组: string[,] TableData; 我可以使用绑定将其内容与DataGrid控件链接吗? 如果可能,我希望用户能够编辑网格并反映数组中的更改。

在Windows XP下通过远程桌面渲染WPF有问题吗?

我听说Windows XP上的远程桌面不支持WPF原语。 这意味着,如果您在Vista机器上运行WPF应用程序并将其显示在XP机器上(通过远程桌面),则显示将作为压缩位图发送。 通过DirectX 11(?)在Vista-Vista通信中解决了这个问题,但这不会在XP上提供。 显然这里有性能影响,我想在开始向WPF开发应用程序之前了解它。 有关此主题的一些信息可在此处找到: http://blogs.msdn.com/tims/archive/2007/01/05/comparing-wpf-on-windows-vista-v-windows-xp.aspx 请参阅以上链接中的评论(引用): 对于SpongeJim的问题,这是由MIL(媒体集成层)完成的,它是处理组合的WPF的底层核心。 在Vista / Vista远程桌面连接上,MIL原语被远程处理,然后重新构建。 在其他组合(例如2003 / XP)上,远程处理的是位图,这显然是带宽密集的。 关于这个主题的更多深度可以在Greg Schechter的博客上找到,特别是在这个条目中: http : //blogs.msdn.com/greg_schechter/archive/2006/06/09/623566.aspx 有没有人对此问题有任何经验或更新的信息?

绑定转换器作为内部类?

我有一个使用绑定转换器的UserControl。 我把转换器变成了一个内部类 public partial class MyPanel : UserControl { public class CornerRadiusConverter : IValueConverter { 如何从XAML引用Converter类? 以下不起作用: 它给出了这个错误: XML命名空间’clr-namespace:MyApp.Windows.Controls’中不存在标签’LensPanel.CornerRadiusConverter’

WPF过滤ListBox

我在ListBox加载了一个字符串ListBox ,现在我想在TextBox输入文本时对其进行过滤。 我该怎么做? public void ListLoad() { ElementList = new List(); // creation a list of strings ElementList.Add(“1”); // add a item of string ElementList.Add(“2”); // add a item of string DataContext = this; // set the data context } 我在XAML中绑定它: ItemsSource =“{Binding ElementList}”

MainWindow构造函数被调用两次

我正在尝试将MainWindow的DataContext设置为App.OnStartup ViewModel。 我注意到,当这样做时, MainWindow()构造函数被调用两次,我看到打开了2个窗口。 有什么想法导致这种行为吗? 我的代码如下: public partial class App : Application { protected override void OnStartup(StartupEventArgs e) { base.OnStartup(e); MainWindow mainWindow = new MainWindow(); // Create the ViewModel to which the main window binds. MainWindowViewModel mainWindowViewModel = new MainWindowViewModel(); // Register handle such that when the mainWindowViewModel asks to be closed, close the window. […]

反序列化Json对象 – DateTime

我的web-api返回一个用户对象。 在该对象中有一个DateTime属性。 当我在我的应用程序中读取它时,我得到一个错误,因为代表DateTime的字符串无效,它缺少\Date … {System.Runtime.Serialization.SerializationException:反序列化User类型的对象时出错。 DateTime内容’1984-10-02T01:00:00’不以’/ Date(’和以’)/’开头,如JSON所需。 —> public static async Task GetUser(string email) { try { using (HttpClient client = new HttpClient()) { HttpResponseMessage response = await client.GetAsync(url + “?email=”+email); if (response.IsSuccessStatusCode) { string content = await response.Content.ReadAsStringAsync(); User user = DataService.Deserialize(content); return user; } return null; } } catch (Exception ex) { return […]