Tag: xaml

如何在代码中访问x:Name-property – 对于非FrameworkElement对象?

与另一个问题类似,我想通过代码访问对象的x:Name属性,在这种情况下,有问题的对象不是FrameworkElement ,因此没有Name属性。 我也无法访问成员变量。 在我的情况下,我有一个带有命名列的ListView ,并希望扩展ListView类,以便它保持列布局。 对于这个function,我需要命名列,因为其他原因重新使用我需要设置的x:Name属性是有意义的,而不是添加附加的“ColumnName”属性。 我目前的“解决方案”: 期望: 那么有可能以某种方式获得“x:Name”值吗?

Datagrid templatecolumn更新源触发器显式仅更新第一行

我的XAML: 我的学生管理课程: public class StudentManagement:INotifyPropertyChanged { private string StudId; public bool Check { get; set; } public int ID { get; set; } public string StudentID { get { return StudId; } set { StudId = value; PropertyChanged(this, new PropertyChangedEventArgs(“StudentID”)); } } public string FirstName { get; set; } public string LastName { get; set; […]

不允许在ListBox中取消选择/取消选择

有没有办法配置WPF ListBox ,以便取消选择/取消选择项目? 总是选择一个项目? 我的ListBox绑定到ObservableCollection 。

使用按钮单击事件清除/删除TextBox内容

我有以下XAML代码段: 当用户按下Button时,我想删除TextBox的内容。 当然,从Code Behind这样做是一项微不足道的任务,但我想通过使用XAML来完成它,所以使用Triggers。 我尝试在网上进行研究,但我要么找到了不正确的解决方案,要么是过于复杂的解决方案,所以我想听听一些简洁的解决方案。

OpenFilePicker无法在Windows Phone 8上运行(不支持指定的方法)

我试图使用以下方法选择一个文件: private async void Button_Click_1(object sender, RoutedEventArgs e) { try { FileOpenPicker openPicker = new FileOpenPicker(); openPicker.ViewMode = PickerViewMode.Thumbnail; openPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary; openPicker.FileTypeFilter.Add(“.jpg”); openPicker.FileTypeFilter.Add(“.jpeg”); openPicker.FileTypeFilter.Add(“.png”); StorageFile file = await openPicker.PickSingleFileAsync(); if (file != null) { // Application now has read/write access to the picked file txt.Text = “Picked file: ” + file.Name; } else { […]

具有行为的RadioButtons绑定到单个属性

我有几个RadioButtons,我不想将它们中的每一个的“IsChecked”属性绑定到代码中的唯一属性。 我希望有一个像“CurrentSelected”这样的属性,并根据它来设置“IsChecked”。 另外我不想使用转换器。 我试图使用行为“ChangePropertyAction”,但看起来它只是以一种方式工作。 这是我的代码: 我的视图模型非常简单:MainViewModel.cs public class MainViewModel : ViewModelBase { private DirectionEnum _selectedDirection; public DirectionEnum SelectedDirection { get { return _selectedDirection; } set { if (_selectedDirection != value) { _selectedDirection = value; RaisePropertyChanged(); } } } public MainViewModel() { SelectedDirection = DirectionEnum.Up; } } 从代码中可以看出,应该已经检查了“Up”RadioButton ……我错过了什么?

并行生成UI

我们有一个WPF应用程序,它有一个带有缓存的VirtualizingStackPanel的ListBox。 不是因为它有大量的元素(在极端情况下通常小于20但可能高达100或更多),但因为元素需要时间来生成。 这些元素实际上是UIElement对象。 因此应用程序动态地需要生成UIElements。 问题在于,即使虚拟化似乎有效,但应用程序仍然很难做出响应,这是一个概念validation解决方案,具有最小的“噪音”。 所以我们认为,由于主要问题是我们动态生成复杂的UIElement对象,我们需要并行执行,即离线。 但是我们得到一个代码需要在STA线程上运行的错误: 调用线程必须是STA,因为许多UI组件都需要这个。 这是否意味着我们无法在WPF主UI线程以外的线程上生成UI(UIElement对象)? 这是我们的概念validation解决方案中的相关代码片段: public class Person : ObservableBase { // … UIElement _UI; public UIElement UI { get { if (_UI == null) { ParallelGenerateUI(); } return _UI; } } private void ParallelGenerateUI() { var scheduler = TaskScheduler.FromCurrentSynchronizationContext(); Task.Factory.StartNew(() => GenerateUI()) .ContinueWith(t => { _UI = t.Result; RaisePropertyChanged(“UI”); […]

将ContentControl绑定到UserControl,并重用相同的实例

我正在尝试将ContentControl的内容绑定到我在ViewModel中实例化的UserControl。 我不能使用绑定到ViewModel的方法,然后让UserControl成为ViewModel的DataTemplate,因为我需要ContentControl的内容能够使用UserControls / Views的相同实例频繁更改,而不是实例化每次重新绑定时的视图。 但是,当将UserControl属性设置为UserControl实例时,然后当呈现视图/数据绑定时,我得到: 必须在连接到新的父Visual之前断开指定的子视图与当前父Visual。 即使我以前没有将此UserControl添加到任何地方,我只是更早地创建了这个实例并将其保存在内存中。 有没有更好的方法来实现我的目标? 在ViewModel中 public class MyViewModel : INotifyPropertyChanged { //… private void LoadApps() { var instances = new List { new Instance1View(), new Instance2View(), new Instance3View(), }; SwitchInstances(instances); } private void SwitchInstances(List instances) { CenterApp = instances[0]; } //… private UserControl _centerApp; public UserControl CenterApp { get { return […]

Storyboard.SetTarget与Storyboard.SetTargetName

为什么Storyboard.SetTargetName有效,但Storyboard.SetTarget却没有? 在这里xaml – 在这里C# private void smartContent_ContentChanging(object sender, RoutedEventArgs e) { Storyboard storyBoard = new Storyboard(); DoubleAnimation doubleAnimation1 = new DoubleAnimation(0.0, -smartContent.RenderSize.Width, new Duration(new TimeSpan(0, 0, 0, 0, 500))); DoubleAnimation doubleAnimation2 = new DoubleAnimation(smartContent.RenderSize.Width, 0.0, new Duration(new TimeSpan(0, 0, 0, 0, 500))); doubleAnimation1.AccelerationRatio = 0.5; doubleAnimation2.DecelerationRatio = 0.5; storyBoard.Children.Add(doubleAnimation1); storyBoard.Children.Add(doubleAnimation2); Storyboard.SetTarget(doubleAnimation1, this.translateTransformLast); //— this does […]

在应用程序配置文件中找不到名为“x”的连接字符串…但它有效吗?

我已经看到了几个与这个错误有关的不同问题,但似乎没有一个我正在经历的。 我刚刚在CodeProject.com上关注了一个简单的项目教程,以便更好地理解使用MVVM模式和entity framework( http://www.codeproject.com/Articles/873592/Tutorial-for-a-Basic-WPF -MVVM-Project-Using-Entity )。 我直接跟着它,一切似乎都很完美。 但是我有点好奇并开始改变一些事情。 我想了解更多关于命名空间如何在XAML中工作的内容,因此我将MainWindowViewModel移动到一个名为ViewModels的新文件夹中。 然后我在我的XAML中添加了一个名为“vms”的新命名空间,其中包含适当的位置,并为窗口设置了我的数据上下文: 但是当我这样做时,我在Visual Studio中得到一个浅蓝色下划线警告,显示“在应用程序配置文件中找不到名为[myEntities]的连接字符串。” 但是App.config文件中存在连接字符串,当我构建并运行程序时,它按预期工作。 有关为什么会发生这种情况的任何想法?