What is the best way to bind dynamically created control to a property in reactiveui? - reactiveui

I'm using ReactiveUI for Winforms 6.5. I'm trying to bind dynamically created textbox to a ViewModel property. Bind method doesnt allow to create such a binding.Is there any way to create binding in runtime?

If you need one-way binding (view model to view) only, you can use BindTo method:
TextBox textBox = new TextBox();
ViewModel.WhenAnyValue(model => model.PropertyToBind)
.BindTo(textBox, t => t.Text);

Related

VSTO Outlook: programmatically add a custom column of type PR_ICON_INDEX to an existing view

Is it possible to add the PR_ICON_INDEX property programmatically as a custom field (column) to an existing view using the Add method of the ViewFields object? If so how?
UPDATED 10/11/2022:
Okay, it looks like body properties are not supported in table object (I guess it is applied to TableView as well): https://github.com/MicrosoftDocs/VBA-Docs/blob/main/outlook/How-to/Search-and-Filter/unsupported-properties-in-a-table-object-or-table-filter.md

Caliburn.Micro - pass readonly properties to view model

in my Windows Phone 8.1 application I'm working with images (cropping, applying filters etc.) thus I need controls' readonly values such as ScrollViewer.HorizontalOffset or Canvas.ActualWidth in my view model.
How can I pass such values to the view model with Caliburn.Micro? When they are readonly, I can't access them in the xaml.
Thanks
this is example with Loaded event, you can use better event for your use
micro:Message.Attach=[Event Loaded] = [Action LoadCanvasProperties($this.ActualWidth, $this.ActualHeight)]"

Setting a data binding on a UI control created programmatically in a Windows 8 C++/Xaml app

As per this page and several other references, the way to create a data binding with Xaml/C++ in Windows 8 is to do the following:
In C++:
Create a bindable class,
Set the DataContext property to an instance of that class.
In Xaml:
<Object AnyProperty="{Binding Path=AnotherProperty, Mode=TwoWay}" />
How would I achieve that binding if I constructed Object through C++?
Would this page be of any help to you?
How to: Create a Binding in Code
The example on the page seems to use a SetBinding instance method on a textblock to bind a property to the text property of the textblock. Maybe there is a similar method in C++?

Sharing viewmodel to multiple views using Caliburn.Micro in WP7

I am currently working on a project which requires multiple views of the same viewmodel. Let me describe this way:
ViewModel: CustomerDetailsViewModel.cs (inherited from Screen class)
View: CustomerDetails.cs (this view has CustomerDetailsViewModel as datacontext and this set automatically by Caliburn.Micro)
View: CustomerInfo.cs (now this is the view where I want to share CustomerDetailsViewModel, which could have some data already modifed via CustomerDetails view)
I am currently using NavigationService to navigate to CustomerInfo view. Is there any way to pass the reference of current viewmodel to the view which user is navigating to in caliburn.micro?
Thanks in advance
idev
Use the attached property cal:Bind.Model="{Binding}" to bind the view to the view model.
See http://caliburnmicro.codeplex.com/wikipage?title=All%20About%20Actions "View First" section.
Alternatively you can also look into the cal:View.Context="MyContext" attached property as described here: http://caliburnmicro.codeplex.com/wikipage?title=Screens%2c%20Conductors%20and%20Composition "Multiple Views over the Same ViewModel" section.
Add a property or two to your App.xaml.cs. What ever you put in here will persist throughout the lifetime of the application (keep in mind that tombstoning will cause this property's value to be lost though). If you want to pass a ViewModel then setyour associated property in App.xaml.cs to the view model and then when the new page loads have it read from that same property.

Giving a Boolean property to a controller object in Interface Builder

After I drag a controller object to the document window, how do I give it a Boolean property?
Assuming you want the ability to expose and edit the property values of your custom controller as attributes showing up in IB's inspector, you'll need to write your own plugin which tells IB what the inspector should look like. This really can't be answered briefly.
Here's Apple's reference on IB Plugins:
http://developer.apple.com/mac/library/documentation/DeveloperTools/Conceptual/IBPlugInGuide/Introduction/Introduction.html#//apple_ref/doc/uid/TP40004323-CH1-SW1
And here's the inspector portion:
http://developer.apple.com/mac/library/documentation/DeveloperTools/Conceptual/IBPlugInGuide/CreatingInspectors/CreatingInspectors.html#//apple_ref/doc/uid/TP40004323-CH6-SW1
If you truly just want to add a property to the controller's interface, you do this in Xcode (modifying the interface and implementation accordingly) and IB will pick up the changes automagically.
In the case of a checkbox, the checkbox itself is either checked or not. That state stores the boolean value instead of the controller (unless you wish it.)
To have the app undertake an action upon clicking it, think of it as a button instead of a data display and link it to an action method in the view controller. That's the simplest and old school way of doing it.
To use binding, you need to bind the checkbox's value attribute to a controller. Usually for binary values its an object controller. So, in IB, drag an Object controller to your nib window and bind it to your data source. Then, drag a checkmark button to the interface. In the checkmarks binding inspector. Set "value" binding to the name of the object controller, controller key to selection, keypath to the name of the data source attribute and provide a value transformer if needed.

Resources