Quantcast
Channel: Caliburn.Micro: Xaml Made Easy
Viewing all articles
Browse latest Browse all 1760

New Post: Binding dependency properties outside of the visual tree

$
0
0
Hi,

I am fairly new to Caliburn.micro, so I'd first like to apologize if what I ask ends up being too simple... but I have done my fair bit of research and can't seem to find an answer.

I have a view where I have created a dependency property in my code-behind. This property is a non-visual property, I use it to initialize the view in certain ways depending on the value of such property (details of these being not relevant). Here is the definition of the property in my code-behind class:
public partial class SelectionListView : UserControl
{
    public string ListType
    {
        get { return (string)GetValue(ListTypeProperty); }
        set { SetValue(ListTypeProperty, value); }
    }
    public static readonly DependencyProperty ListTypeProperty =
        DependencyProperty.Register("ListType", typeof(string), typeof(SelectionListView), null);
In my viewModel (called SelectionListViewModel), I have a corresponding property ListType and I'd like to bind both properties (the view's and the viewModel's). And this is where I have run into a dead-end. Although I have followed the naming conventions correctly, or at least I believe so, the automatic binding performed by the Caliburn.micro framework does not seem to bind both properties... however, on reading the documentation I have found that this is to be expected since the ViewModelBinder only searches the visual tree... and since this property is a non-visual element I imagine it cannot be a candidate for automatic binding through the framework. I believe I have "confirmed" this is actually what is going on because, if I happen to create a visual element in the view (for instance, a TextBox) and name it "ListType", it is then automatically binded to the property in the viewModel.

My question, however, is: how do I then bind this non-visual property in the view with the property in the viewModel (and avoiding, if possible, creating dependencies between them, etc)? Can I do it somehow taking advantage of Caliburn.micro? If not, how would it be done directly in code (I am also trying out creating a new Binding and doing a SetBinding but with no success either)?

Thanks in advance for all input.

Viewing all articles
Browse latest Browse all 1760

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>