binding

WPF context menu whose items are defined as data templates

怎甘沉沦 提交于 2020-01-04 04:37:13
问题 I have a list view that displays a collection of items, each item has as its underlying data a view model (MVVM). What I would like to do is display different menu items within the context menu when the user right clicks one of these list view items. The menu items displayed is dependent on the type of the item selected (i.e. the type of the underlying view model). I would expect the below to work, but it does not (no items are displayed in the context menu). <ListView.ContextMenu>

How can I get the binding from method_missing?

回眸只為那壹抹淺笑 提交于 2020-01-04 04:16:27
问题 I am trying to find a way to get the binding from the caller within method_missing in Ruby (1.8), but I can't seem to find a way to do it. Hopefully the following code explains what I would like to do: class A def some_method x = 123 nonexistent_method end def method_missing(method, *args, &block) b = caller_binding # <---- Is this possible? eval "puts x", b end end A.new.some_method # expected output: # 123 So... is there a way to obtain the caller's binding, or is this just impossible in

OneWayToSource binding resetting target value

做~自己de王妃 提交于 2020-01-04 04:13:05
问题 Why is the OneWayToSource binding resetting my target value? Here is the binding code: SolidColorBrush brush = GetTemplateChild("PART_PreviewBrush") as SolidColorBrush; if (brush != null) { Binding binding = new Binding("Color"); binding.Source = brush; binding.Mode = BindingMode.OneWayToSource; this.SetBinding(ColorPicker.ColorProperty, binding); } I set the "Color" dependency property in xaml. But it gets overwritten by the binding. After that the binding works ok. So, essentially my

How can i change the default values of the Binding Option in WPF?

人盡茶涼 提交于 2020-01-04 03:59:07
问题 In my current project i'm using several textbox controls whose content is filled from objects which are coming from a database. The object uses validation to validate the correct insertion of the text. When i want to show a validation error (i.e. the text has to many characters) i have to add some binding options to the text property like in the following line: <TextBox Text="{Binding Mode=TwoWay, Path=Description, ValidatesOnDataErrors=True, NotifyOnValidationError=True, UpdateSourceTrigger

How can I tell my ViewModel that the user is changing text in the TextBox?

↘锁芯ラ 提交于 2020-01-04 02:05:09
问题 So let's say I have an MVVM application and I want the user to fill out a TextBox and while he is filling it out , I want to check to see if he has typed in the last name of a customer yet. Here is how I get my ViewModel to know when the user has changed the item in the ComboBox : <ComboBox ItemsSource="{Binding Customers}" ItemTemplate="{StaticResource CustomerComboBoxTemplate}" Margin="20" HorizontalAlignment="Left" SelectedItem="{Binding SelectedCustomer, Mode=TwoWay}"/> And here is how I

Manage the targetType of a Binding in a MultiBinding

匆匆过客 提交于 2020-01-04 01:20:10
问题 So, I have a multi-binding with a converter that takes in some values and finds the max of them. The problem is that one of the bindings utilises a converter that expects a double target type, while the binding has an object target type. I was wondering if there was any way to modify the target type of a binding in any way. Below is an approximation of my xaml: <TextBlock> <TextBlock.Width> <MultiBinding Converter="{StaticResource _maxValueConverter}"> <Binding Source="{StaticResource

Can I get the Type() of a bound object in C#/WPF (even if the bound value is null)?

自闭症网瘾萝莉.ら 提交于 2020-01-03 20:58:11
问题 I have a binding to an unknown source. All I have is the binding. I have no other way of looking at the bound object. I need to figure out the Type for the bound object, even if the value is null (this is where my problem is). I was evaluating the binding by binding to an object and then using the object as a way to get the Type, but I need to know the type even if the value is null. For instance, I have a class like so: public class Customer{ public string Name { get; set; } public int Age {

Posting Nested Collection to Web API

隐身守侯 提交于 2020-01-03 17:38:46
问题 I'm trying to post a complex type object to web api. On the web api side, when method recieves the object parameter, every property is set properly except a collection that is derived from ICollection. Here is my sample classes: public class MyClass { private int id; public int Id { get { return id; } set { id = value; } } private MyCollection<string> collection; public MyCollection<string> Collection { get { return collection; } set { collection = value; } } } public class MyCollection<T> :

How does one detect SetBinding success or failure in Silverlight?

跟風遠走 提交于 2020-01-03 17:23:46
问题 Simple binding from C#: Binding binding = new Binding(SourceName); binding.Mode = BindingMode.TwoWay; BindingExpressionBase beb = SetBinding(SourceDependencyProperty, binding); I would like to detect whether or not the SetBinding was successful. SetBinding obviously knows when it has an issue because it displays in the Output window tracing when the application is running: System.Windows.Data Error: BindingExpression path error: 'InterestRate' property not found on 'Tc.Views.TestAccount' ...

TextBlock: Binding of Text and StringFormat

坚强是说给别人听的谎言 提交于 2020-01-03 17:17:33
问题 Is it possible to bind Text and StringFormat too? <TextBlock Text="{Binding Path=Price, StringFormat={Binding Path=DecimalPoints}}" /> DecimalPoints is constantly changing from F0 to F15 . Unfortunatelly the code above doesn't compile. 回答1: I think your best bet is definitely a converter. Then your binding would look like this: <TextBlock.Text> <MultiBinding Converter="{StaticResource StringFormatConverter }"> <Binding Path="Price"/> <Binding Path="DecimalPoints"/> </MultiBinding> </TextBlock