Binding comand for Button
I have carousel view and bindings properties:
<ContentView>
<controls:CarouselViewControl x:Name="CarouselData" ItemsSource="{Binding StartDisplay}"
ShowIndicators="True"
ShowArrows="False"
IndicatorsTintColor="BurlyWood" CurrentPageIndicatorTintColor="DarkGoldenrod">
<controls:CarouselViewControl.ItemTemplate>
<DataTemplate >
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="100" />
<RowDefinition Height="100" />
</Grid.RowDefinitions>
<Image Grid.RowSpan="3" Aspect="AspectFill" Source="{Binding Image}"/>
<ContentView Grid.Row="0" Padding="60,30,60,0">
</ContentView>
<ContentView Grid.Row="1" Padding="20,10,20,50">
<Label Text="{Binding Message}"
TextColor="Black"
FontSize="20"
HorizontalTextAlignment="Center" />
</ContentView>
<ContentView Grid.Row="2" Padding="20,10,20,50">
<Button Text="Getted start" IsVisible="{Binding VisibleStartButton}"/>
</ContentView>
</Grid>
</DataTemplate>
</controls:CarouselViewControl.ItemTemplate>
</controls:CarouselViewControl>
</ContentView>
I pointed ItemsSource for CarouselView.
Class ModelView:
public class StartPageViewModel: BaseViewModel // ViewModel
{
private ObservableCollection<DataCarouselView> startDisplay;
public ObservableCollection<DataCarouselView> StartDisplay
{
get => startDisplay; set => SetProperty(ref startDisplay, value);
}
public StartPageViewModel()
{
StartDisplay = new ObservableCollection<DataCarouselView>(new
{
new DataCarouselView("back_1.png", "test1"),
new DataCarouselView("back_2.png", "test2"),
new DataCarouselView("back_3.png", "test3"),
new DataCarouselView("back_4.png", "test4", true)
});
OpenMenuPageCommand = new OpenMenuPageCommand(this);
}
}
class Model:
public class DataCarouselView // Model
{
public string Image { get; set; }
public string Message { get; set; }
public bool VisibleStartButton { get; set; }
public DataCarouselView(string image, string message, bool vis = false)
{
Image = image;
Message = message;
VisibleStartButton = vis;
}
}
Everything is working.
I want to add command for to the button. I create command class:
public class OpenMenuPageCommand : ICommand
{
public event EventHandler CanExecuteChanged;
private StartPageViewModel viewModel;
public OpenMenuPageCommand(StartPageViewModel vm)
{
viewModel = vm;
}
public bool CanExecute(object parameter)
{
return viewModel != null;
}
public void Execute(object parameter)
{
if (CanExecute(parameter))
viewModel.OpenMenuPage();
}
}
and property in class ViewModel:
public ICommand OpenMenuPageCommand { get; }
and method command in class ViewModel:
public async void OpenMenuPage()
{
await navigation.PushAsync(new MenuPage());
}
How binding command for button? Thanks.
c# xaml xamarin
add a comment |
I have carousel view and bindings properties:
<ContentView>
<controls:CarouselViewControl x:Name="CarouselData" ItemsSource="{Binding StartDisplay}"
ShowIndicators="True"
ShowArrows="False"
IndicatorsTintColor="BurlyWood" CurrentPageIndicatorTintColor="DarkGoldenrod">
<controls:CarouselViewControl.ItemTemplate>
<DataTemplate >
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="100" />
<RowDefinition Height="100" />
</Grid.RowDefinitions>
<Image Grid.RowSpan="3" Aspect="AspectFill" Source="{Binding Image}"/>
<ContentView Grid.Row="0" Padding="60,30,60,0">
</ContentView>
<ContentView Grid.Row="1" Padding="20,10,20,50">
<Label Text="{Binding Message}"
TextColor="Black"
FontSize="20"
HorizontalTextAlignment="Center" />
</ContentView>
<ContentView Grid.Row="2" Padding="20,10,20,50">
<Button Text="Getted start" IsVisible="{Binding VisibleStartButton}"/>
</ContentView>
</Grid>
</DataTemplate>
</controls:CarouselViewControl.ItemTemplate>
</controls:CarouselViewControl>
</ContentView>
I pointed ItemsSource for CarouselView.
Class ModelView:
public class StartPageViewModel: BaseViewModel // ViewModel
{
private ObservableCollection<DataCarouselView> startDisplay;
public ObservableCollection<DataCarouselView> StartDisplay
{
get => startDisplay; set => SetProperty(ref startDisplay, value);
}
public StartPageViewModel()
{
StartDisplay = new ObservableCollection<DataCarouselView>(new
{
new DataCarouselView("back_1.png", "test1"),
new DataCarouselView("back_2.png", "test2"),
new DataCarouselView("back_3.png", "test3"),
new DataCarouselView("back_4.png", "test4", true)
});
OpenMenuPageCommand = new OpenMenuPageCommand(this);
}
}
class Model:
public class DataCarouselView // Model
{
public string Image { get; set; }
public string Message { get; set; }
public bool VisibleStartButton { get; set; }
public DataCarouselView(string image, string message, bool vis = false)
{
Image = image;
Message = message;
VisibleStartButton = vis;
}
}
Everything is working.
I want to add command for to the button. I create command class:
public class OpenMenuPageCommand : ICommand
{
public event EventHandler CanExecuteChanged;
private StartPageViewModel viewModel;
public OpenMenuPageCommand(StartPageViewModel vm)
{
viewModel = vm;
}
public bool CanExecute(object parameter)
{
return viewModel != null;
}
public void Execute(object parameter)
{
if (CanExecute(parameter))
viewModel.OpenMenuPage();
}
}
and property in class ViewModel:
public ICommand OpenMenuPageCommand { get; }
and method command in class ViewModel:
public async void OpenMenuPage()
{
await navigation.PushAsync(new MenuPage());
}
How binding command for button? Thanks.
c# xaml xamarin
add a comment |
I have carousel view and bindings properties:
<ContentView>
<controls:CarouselViewControl x:Name="CarouselData" ItemsSource="{Binding StartDisplay}"
ShowIndicators="True"
ShowArrows="False"
IndicatorsTintColor="BurlyWood" CurrentPageIndicatorTintColor="DarkGoldenrod">
<controls:CarouselViewControl.ItemTemplate>
<DataTemplate >
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="100" />
<RowDefinition Height="100" />
</Grid.RowDefinitions>
<Image Grid.RowSpan="3" Aspect="AspectFill" Source="{Binding Image}"/>
<ContentView Grid.Row="0" Padding="60,30,60,0">
</ContentView>
<ContentView Grid.Row="1" Padding="20,10,20,50">
<Label Text="{Binding Message}"
TextColor="Black"
FontSize="20"
HorizontalTextAlignment="Center" />
</ContentView>
<ContentView Grid.Row="2" Padding="20,10,20,50">
<Button Text="Getted start" IsVisible="{Binding VisibleStartButton}"/>
</ContentView>
</Grid>
</DataTemplate>
</controls:CarouselViewControl.ItemTemplate>
</controls:CarouselViewControl>
</ContentView>
I pointed ItemsSource for CarouselView.
Class ModelView:
public class StartPageViewModel: BaseViewModel // ViewModel
{
private ObservableCollection<DataCarouselView> startDisplay;
public ObservableCollection<DataCarouselView> StartDisplay
{
get => startDisplay; set => SetProperty(ref startDisplay, value);
}
public StartPageViewModel()
{
StartDisplay = new ObservableCollection<DataCarouselView>(new
{
new DataCarouselView("back_1.png", "test1"),
new DataCarouselView("back_2.png", "test2"),
new DataCarouselView("back_3.png", "test3"),
new DataCarouselView("back_4.png", "test4", true)
});
OpenMenuPageCommand = new OpenMenuPageCommand(this);
}
}
class Model:
public class DataCarouselView // Model
{
public string Image { get; set; }
public string Message { get; set; }
public bool VisibleStartButton { get; set; }
public DataCarouselView(string image, string message, bool vis = false)
{
Image = image;
Message = message;
VisibleStartButton = vis;
}
}
Everything is working.
I want to add command for to the button. I create command class:
public class OpenMenuPageCommand : ICommand
{
public event EventHandler CanExecuteChanged;
private StartPageViewModel viewModel;
public OpenMenuPageCommand(StartPageViewModel vm)
{
viewModel = vm;
}
public bool CanExecute(object parameter)
{
return viewModel != null;
}
public void Execute(object parameter)
{
if (CanExecute(parameter))
viewModel.OpenMenuPage();
}
}
and property in class ViewModel:
public ICommand OpenMenuPageCommand { get; }
and method command in class ViewModel:
public async void OpenMenuPage()
{
await navigation.PushAsync(new MenuPage());
}
How binding command for button? Thanks.
c# xaml xamarin
I have carousel view and bindings properties:
<ContentView>
<controls:CarouselViewControl x:Name="CarouselData" ItemsSource="{Binding StartDisplay}"
ShowIndicators="True"
ShowArrows="False"
IndicatorsTintColor="BurlyWood" CurrentPageIndicatorTintColor="DarkGoldenrod">
<controls:CarouselViewControl.ItemTemplate>
<DataTemplate >
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="100" />
<RowDefinition Height="100" />
</Grid.RowDefinitions>
<Image Grid.RowSpan="3" Aspect="AspectFill" Source="{Binding Image}"/>
<ContentView Grid.Row="0" Padding="60,30,60,0">
</ContentView>
<ContentView Grid.Row="1" Padding="20,10,20,50">
<Label Text="{Binding Message}"
TextColor="Black"
FontSize="20"
HorizontalTextAlignment="Center" />
</ContentView>
<ContentView Grid.Row="2" Padding="20,10,20,50">
<Button Text="Getted start" IsVisible="{Binding VisibleStartButton}"/>
</ContentView>
</Grid>
</DataTemplate>
</controls:CarouselViewControl.ItemTemplate>
</controls:CarouselViewControl>
</ContentView>
I pointed ItemsSource for CarouselView.
Class ModelView:
public class StartPageViewModel: BaseViewModel // ViewModel
{
private ObservableCollection<DataCarouselView> startDisplay;
public ObservableCollection<DataCarouselView> StartDisplay
{
get => startDisplay; set => SetProperty(ref startDisplay, value);
}
public StartPageViewModel()
{
StartDisplay = new ObservableCollection<DataCarouselView>(new
{
new DataCarouselView("back_1.png", "test1"),
new DataCarouselView("back_2.png", "test2"),
new DataCarouselView("back_3.png", "test3"),
new DataCarouselView("back_4.png", "test4", true)
});
OpenMenuPageCommand = new OpenMenuPageCommand(this);
}
}
class Model:
public class DataCarouselView // Model
{
public string Image { get; set; }
public string Message { get; set; }
public bool VisibleStartButton { get; set; }
public DataCarouselView(string image, string message, bool vis = false)
{
Image = image;
Message = message;
VisibleStartButton = vis;
}
}
Everything is working.
I want to add command for to the button. I create command class:
public class OpenMenuPageCommand : ICommand
{
public event EventHandler CanExecuteChanged;
private StartPageViewModel viewModel;
public OpenMenuPageCommand(StartPageViewModel vm)
{
viewModel = vm;
}
public bool CanExecute(object parameter)
{
return viewModel != null;
}
public void Execute(object parameter)
{
if (CanExecute(parameter))
viewModel.OpenMenuPage();
}
}
and property in class ViewModel:
public ICommand OpenMenuPageCommand { get; }
and method command in class ViewModel:
public async void OpenMenuPage()
{
await navigation.PushAsync(new MenuPage());
}
How binding command for button? Thanks.
c# xaml xamarin
c# xaml xamarin
asked Nov 22 at 22:23
Range
1126
1126
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
You need to use relative source binding to make it work
First set the name of your root control as below:
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Name="InfoView"
x:Class="InfoSeries.Views.InfoView">
Then you can reference InfoView
in order to bind Button
Command
with your ViewModel:
<Button Text="Getted start" IsVisible="{Binding VisibleStartButton}" Command="{Binding Source={x:Reference InfoView}, Path=BindingContext.OpenMenuPageCommand}"/>
Thank you so much! It worked :)
– Range
Nov 23 at 10:37
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53438616%2fbinding-comand-for-button%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You need to use relative source binding to make it work
First set the name of your root control as below:
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Name="InfoView"
x:Class="InfoSeries.Views.InfoView">
Then you can reference InfoView
in order to bind Button
Command
with your ViewModel:
<Button Text="Getted start" IsVisible="{Binding VisibleStartButton}" Command="{Binding Source={x:Reference InfoView}, Path=BindingContext.OpenMenuPageCommand}"/>
Thank you so much! It worked :)
– Range
Nov 23 at 10:37
add a comment |
You need to use relative source binding to make it work
First set the name of your root control as below:
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Name="InfoView"
x:Class="InfoSeries.Views.InfoView">
Then you can reference InfoView
in order to bind Button
Command
with your ViewModel:
<Button Text="Getted start" IsVisible="{Binding VisibleStartButton}" Command="{Binding Source={x:Reference InfoView}, Path=BindingContext.OpenMenuPageCommand}"/>
Thank you so much! It worked :)
– Range
Nov 23 at 10:37
add a comment |
You need to use relative source binding to make it work
First set the name of your root control as below:
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Name="InfoView"
x:Class="InfoSeries.Views.InfoView">
Then you can reference InfoView
in order to bind Button
Command
with your ViewModel:
<Button Text="Getted start" IsVisible="{Binding VisibleStartButton}" Command="{Binding Source={x:Reference InfoView}, Path=BindingContext.OpenMenuPageCommand}"/>
You need to use relative source binding to make it work
First set the name of your root control as below:
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Name="InfoView"
x:Class="InfoSeries.Views.InfoView">
Then you can reference InfoView
in order to bind Button
Command
with your ViewModel:
<Button Text="Getted start" IsVisible="{Binding VisibleStartButton}" Command="{Binding Source={x:Reference InfoView}, Path=BindingContext.OpenMenuPageCommand}"/>
answered Nov 23 at 1:55
Dishant
872512
872512
Thank you so much! It worked :)
– Range
Nov 23 at 10:37
add a comment |
Thank you so much! It worked :)
– Range
Nov 23 at 10:37
Thank you so much! It worked :)
– Range
Nov 23 at 10:37
Thank you so much! It worked :)
– Range
Nov 23 at 10:37
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53438616%2fbinding-comand-for-button%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown