binding

MVVM - hiding a control when bound property is not present

半世苍凉 提交于 2019-12-17 20:04:43
问题 I was wondering if it is possible to hide a control on a view if the property to which the control is bound does not exist in the view model. For example, if I have the following: <CheckBox Content="Quote" IsChecked="{Binding Path=IsQuoted}" /> Can I detect in XAML that the IsQuoted property does not exist on the view model, and simply hide the control in that instance. I am essentially creating a wizard dialog that moves through a collection of view models, displaying the associated view for

Binding between my usercontrol and ViewModel

假装没事ソ 提交于 2019-12-17 19:56:38
问题 Can not do Binding Random (MyViewModel) -> VMTestValue (MyViewModel) -> TestUserControl (MainWindow) "MyViewModel" is ViewModel for "MainWindow" All project: http://rusfolder.com/32608140 TestUserControl.xaml <UserControl x:Class="TestBinding.TestUserControl" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com

how to bind a boolean to combobox in wpf

白昼怎懂夜的黑 提交于 2019-12-17 19:35:06
问题 Well I was wondering how to bind a boolean property to a combobox.Combobox will be a yes/no combobox. 回答1: You could use a ValueConverter to convert the boolean value to a ComboBox index and back. Like this: public class BoolToIndexConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { return ((bool)value == true) ? 0 : 1; } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) {

WPF DataGridTemplateColumn with ComboBox Binding (MVVM pattern)

坚强是说给别人听的谎言 提交于 2019-12-17 19:09:26
问题 I'm going bonkers with the following WPF DataGrid+ComboBox scenario. I have a set of classes which look like; class Owner { int ID { get; } string Name { get; } public override ToString() { return this.Name; } } class House { int ID { get; } Owner HouseOwner { get; set; } } class ViewModel { ObservableCollection<Owner> Owners; ObservableCollection<House> Houses } Now my desired outcome is a DataGrid which shows a list of rows of type House , and in one of the columns, is a ComboBox which

Binding a Dictionary's key and value in a listbox with wpf

杀马特。学长 韩版系。学妹 提交于 2019-12-17 18:53:12
问题 I am trying to bind a dictionary's key to a row of the grid in a listbox, and bind the dictionary's value to another row of the grid. key's type is Book, a class thati wrote and the value's type is int. i want to write the elements of the class and the integer value in grid. Can you help me on this? I'm quite confused on determining the itemsSource and the data type to bind. thanks for helping Edit: i forgot to say that i am using c# - wpf. =) I sent the dictionary as the itemsSource, and i

How perform calculation on a XAML Binding value: reverse it, multiply it, subtract from it or add to it?

泪湿孤枕 提交于 2019-12-17 18:33:14
问题 First; the question is rhetorical, I have an answer! I have gotten so much help from looking here that I wanted to give this neat trick back. Imagine that you have a value that you want to bind to, but it is somehow or somewhat wrong. I had a situation where I wanted to bind to a value, but when the value was 1, I needed 0, and vice-versa. There was a time when I wanted to bind the width of an element to the width of a parent - 68px. 回答1: Enter the FirstDegreeFunctionConverter : using System;

Binding in WPF style causes inexplicable “Cannot find governing FrameworkElement” error

落花浮王杯 提交于 2019-12-17 18:28:29
问题 I have an ItemsControl that displays a bunch of rectangles. Each rectangle needs to be offset upward and to the left. So, I created a RectangleStyle that uses bindings to set the width, height, X translation, and Y translation for a rectangle. The width and height bindings are working fine, but I'm getting the following error for the TranslateTransform bindings: System.Windows.Data Error: 2 : Cannot find governing FrameworkElement or FrameworkContentElement for target element.

C# WPF IsEnabled using multiple bindings?

流过昼夜 提交于 2019-12-17 18:14:45
问题 I have a WPF xaml file describing a section of a GUI and I'd like the enabling/disabling of a particular control to be dependent on two others. The code looks something like this at the moment: <ComboBox Name="MyComboBox" IsEnabled="{Binding ElementName=SomeCheckBox, Path=IsChecked}"/> But I'd like it to be dependant on another checkbox as well so something like: <ComboBox Name="MyComboBox" IsEnabled="{Binding ElementName=SomeCheckBox&AnotherCheckbox, Path=IsChecked}"/> What's the best way to

How to bind command into ContextMenu in DataTemplate

[亡魂溺海] 提交于 2019-12-17 17:04:41
问题 I'm a little bit lost with bindings. I tried so many things in the last hour, I cannot enumerate all of them. I have an issue with a contextMenu inside a DataTemplate. To explain: I have a UserControl . Its dataContext is itself. Inside this UserControl , I have an ItemsControl to represent a list of Hyperlink. My ItemsControl itemsSource is bound (it is composed of objects elements). I redefined ItemsControl.ItemTemplate . Inside, I create a HyperLink, with TextBlock as child to make it work

Binding errors not showing on output window

五迷三道 提交于 2019-12-17 16:56:52
问题 My output window does not show binding errors for my project. However on a colleagues machine, binding errors are displayed in the output window. Any ideas on how to switch this on on my machine (the source code is identical on both machines so I'm guessing it is an IDE setting). 回答1: Try Tools -> Options -> Debugging -> Output Window -> WPF Trace Settings -> Data Binding 回答2: I had the same problem and making the appropriate changes (Tools -> Options -> Debugging -> Output Window -> WPF