Tag: 绑定

使用wpf将列表框中的字典键和值绑定

我试图将字典的键绑定到列表框中的一行网格,并将字典的值绑定到网格的另一行。 key的类型是Book,类是thati写的,值的类型是int。 我想在网格中写出类的元素和整数值。 你能帮帮我吗? 我对确定itemsSource和要绑定的数据类型感到很困惑。 谢谢你的帮助 编辑:我忘了说我正在使用c# – wpf。 =) 我将字典作为itemsSource发送,并且我将字典指定为objectdataprovider标记中的类型,并尝试通过以下代码发送值(int): 并且选择的项目显示为[myNameSpace.Book,4]而不是4。 BookListBox.ItemsSource = LibManager.Books; 这是我在Window.xaml.cs中写的,Books是BookList,其中BookList是一种字典。 和xaml文件: 我的代码还有一个问题 – 我无法在列表框中看到列出的项目。 我的意思是我可以通过ListBox.SelectedItem获取值但在列表框中看不到。 因此,我无法确定是否可以将整数值传递到我想要的位置。 所以我想我首先需要帮助解决这个问题…我写了一个手工编写的标签,另一个标签应该由同一行中的数据绑定填充,但我可以看到第一个标签,但我可以达到后面的代码值。

使用XAML将System.Drawing.Image绑定到System.Windows.Image控件

我正在将ListView绑定到对象列表,就像这样; 我绑定到一个声明两个属性的对象; string DisplayName { get; } System.Drawing.Image Image { get; set; } 我想填充DataTemplate但我无法弄清楚如何; 如果我在我的模板中这样做; 文本出现但图像没有。 我究竟做错了什么? 调试输出显示 System.Windows.Data Error: 1 : Cannot create default converter to perform ‘one-way’ conversions between types ‘System.Drawing.Image’ and ‘System.Windows.Media.ImageSource’. Consider using Converter property of Binding. BindingExpression:Path=Image; DataItem=’RealElement’ (HashCode=54308798); target element is ‘Image’ (Name=”); target property is ‘Source’ (type ‘ImageSource’)

绑定到窗口高度和宽度的问题

当我尝试将窗口的高度和宽度绑定到视图模型中的属性时,我遇到了一些问题。 这是一个小样本应用程序来说明问题。 这是app.xaml.xs中的代码 public partial class App : Application { protected override void OnStartup(StartupEventArgs e) { base.OnStartup(e); MainWindow mainWindow = new MainWindow(); MainWindowViewModel mainWindowViewModel = new MainWindowViewModel(); mainWindow.DataContext = mainWindowViewModel; mainWindow.Show(); } } 这是MainWindow.xaml: 这是视图模型: public class MainWindowViewModel { public int WindowWidth { get { return 100; } } public int WindowHeight { get { […]

将SolidColorBrush绑定到ControlTemplate背景

您好我试图将SolidColorBrush绑定到TabItem控件模板中的边框的Background属性。 但是当我改变SolidColorBrush资源的值时,它说“无法在对象上设置属性’#FF808080’因为它处于只读状态。” 与没有ControlTemplate的库存按钮一样,它可以很好地工作。 这是我的代码。 (XAML) Change Theme 这是我的C#代码 private void ChangeTheme_Click(object sender, RoutedEventArgs e) { SolidColorBrush brush2 = (SolidColorBrush)Resources[“SolidColorBrush2”]; SolidColorBrush brush3 = (SolidColorBrush)Resources[“SolidColorBrush3”]; brush2.Color = Color.FromArgb(255, 200, 200, 200); brush3.Color = Color.FromArgb(255, 251, 132, 61); } 而错误:

如何将命令绑定到DataTemplate中的ContextMenu

我有点迷失绑定。 我在最后一小时尝试了很多东西,我不能列举所有这些东西。 我在DataTemplate中遇到了contextMenu的问题。 解释一下:我有一个UserControl 。 它的dataContext本身就是。 在这个UserControl ,我有一个ItemsControl来表示超链接列表。 我的ItemsControl itemsSource被绑定(它由对象元素组成)。 我重新定义了ItemsControl.ItemTemplate 。 在里面,我创建了一个HyperLink, TextBlock作为子项使其工作,在这个TextBlock ,我通过执行以下操作设置了ContextMenu 。 所以我有 UserControl –> ItemsControl –> ItemTemplate –> HyperLink –> TextBlock –> ContextMenu –> ContextMenuItem 我知道我的第一个相对来源不起作用,我有一个绑定错误。 我想要的是绑定我的UserContorl datacontext,它具有这些命令。 我该怎么办? 谢谢

DataTable作为DataGrid.ItemsSource

您好我想将具有多个列的DataTable绑定到代码隐藏中的DataGrid var dt = new DataTable(); dt.Columns.Add(new DataColumn(“1”)); dt.Columns.Add(new DataColumn(“2”)); dt.Columns.Add(new DataColumn(“3”)); dt.Rows.Add(ff.Mo); dt.Rows.Add(ff.Di); dt.Rows.Add(ff.Mi); dt.Rows.Add(ff.Do); dt.Rows.Add(ff.Fr); dt.Rows.Add(ff.Sa); dt.Rows.Add(ff.So); // ff is a object that contains List DataGrid DGrid = new DataGrid(); for (int i = 0; i < 3; i++) { DataGridTemplateColumn templateColumn = new DataGridTemplateColumn(); templateColumn.HeaderTemplate = HeaderDt; templateColumn.CellTemplate = ItemDt; //specified DataTemplate […]

WPF绑定DataGrid中的SelectedItem

所以,我有一个TabControl绑定到一个项目列表(每个选项卡是一个项目) – 这很好。 每个选项卡的内容都是一个DataGrid,其中包含项目员工的列表 – 也可以正常工作。 现在,我想显示一些关于当前在DataGrid上选择的员工的信息。 这是一些代码:MainWindow.xaml文件: 后来,我想通过简单地在标签中编写来测试这个绑定: 和MainWindowViewModel: public Employee SelectedEmployee { get { return selectedEmployee; } set { if (selectedEmployee != value) { selectedEmployee = value; NotifyPropertyChanged(“SelectedEmployee”); } } } public event PropertyChangedEventHandler PropertyChanged; private void NotifyPropertyChanged(String info) { if (PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs(info)); } } 我是WPF的新手,我已经阅读了一些提示,但他们没有帮助。 标签’emp’没有显示任何内容。 我错过了什么?

为什么绑定到struct不起作用?

我最近遇到了一个问题,我有一个绑定到ListView的ObservableCollection。 人是我写的结构。 只要我在绑定之前设置People对象的值,一切似乎都可以正常工作。 但是,当我尝试在运行时从GUI设置值时,基础对象似乎不反映更改。 我最终通过简单地将People从一个结构改为一个类来克服了这个问题。 不需要进行其他更改。 有人可以向我解释为什么会这样吗?

从View到ViewModel的WPF事件绑定?

什么是将View中的WPF事件绑定到ViewModel的最佳方法? 我在我的视图中有一个drop事件,但我想将它替换为ViewModel到期绑定。 找到了几个解决方案,但没有一个做到我所预期的。 查看代码:

程序集绑定重定向不起作用

我正在尝试使用以下app.config设置程序集绑定重定向: 我在GAC中使用版本9.0.242.0的计算机上运行该程序,并使用指定的公钥令牌。 CLR似乎甚至没有尝试重定向绑定以使用该版本。 这是我在fuslogvw.exe中得到的: LOG: This bind starts in default load context. LOG: Using application configuration file: \Debug\AssemblyRedirectPOC.exe.Config LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v2.0.50727\config\machine.config. LOG: Post-policy reference: Microsoft.AnalysisServices, Version=10.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91 LOG: GAC Lookup was unsuccessful. LOG: Attempting download of new URL /Debug/Microsoft.AnalysisServices.DLL. LOG: Attempting download of new URL /Debug/Microsoft.AnalysisServices/Microsoft.AnalysisServices.DLL. LOG: Attempting download of […]