So far I have read a lot about binding and I have looked up my question. Unfortunately the questions I stumbled upon, were questions regarding the CONTENT of a button.
My question rather is:
How can I bind a C# generated button ( new Button (//CONTENT)
) to my XAML, rather then just binding content to my already generated button?
in my MVVM code I have property which holds a button as value called RequestedButton
, but I have no idea as to what kind of tag I should use in my XAML to bind this property to.
I do know how to bind this if it were to be a ObservableCollection
, but no idea on how to bind it if it's a single attribute.
So my question (to the point) is: What kind of element should I use in my XAML, to use the binding on for the property RequestedButton
, to use {Binding RequestedButton}
on?
In my class I have a property named RequestedButton
, which holds a Button as a value. Like this:
Class Foo
{
public Button RequestedButton {get; set;}
public Foo()
{
RequestedButton = new Button()//GENERATE BUTTON WITH PROPERTIES IN IT
}
}
What tag should I now use, to correctly display (use Binding
) the button ABOVE in my XAML?
View Model
private Button requestedButton = new Button();
public Button RequestedButton
{
get
{
return requestedButton;
}
set
{
requestedButton = value;
NotifyPropertyChanged(nameof(RequestedButton));
}
}
...
Xaml
<ContentView Content="{Binding RequestedButton}"/>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.