-
- picpic2006
- Posts: 71
- Joined:
button binding command with parameter
Hi i tried to make a custom command that can throw a parameter " a string".
Your tutorial don't throw a parameter, i actually search on google i found some documentation, i try but
i really don't see how make relation with your code.
i must admit it is a really new concept for me !
Thanks you very much
Your tutorial don't throw a parameter, i actually search on google i found some documentation, i try but
i really don't see how make relation with your code.
i must admit it is a really new concept for me !
Thanks you very much
Re: button binding command with parameter
In addition to the Command property, there is also a CommandParameter property that you can bind.
-
- picpic2006
- Posts: 71
- Joined:
Re: button binding command with parameter
thanks for the reply.
I saw that parameter, my question is about the code behind this in c# with unity.
i don't know how to expose this parameter in my command.
I actually read somes exemples on the web, but i tryed some configs, but none works.
Thanks
I saw that parameter, my question is about the code behind this in c# with unity.
i don't know how to expose this parameter in my command.
I actually read somes exemples on the web, but i tryed some configs, but none works.
Thanks
Re: button binding command with parameter
Exactly what do you want? How are you exposing the command? Are you binding in code or in the XAML? The parameter is just another object property, you can bind it to just about anything.
-
- picpic2006
- Posts: 71
- Joined:
Re: button binding command with parameter
Sorry my project with my code is at my work but i can explain what i wan't to acheive more precisely.
I have made a command with no parameter. and bind it and expose it outside my usercontrol.
"SelectBoutonCommand"
in my ui code i made this.
CustomButton btn = new CustomButton();
btn.selectBoutonCommand = new SelectedBoutonCommand(selectbouton);
public void selectBouton()
{
Here i wan't to get my clicked bouton name to throw a task by context.
}
I have read some exemple. but in noesis command, the parameter is a base component.
All exemples i read from xaml the parameter is an object.
I really misunderstand some thing, i have to read more !
I have made a command with no parameter. and bind it and expose it outside my usercontrol.
"SelectBoutonCommand"
in my ui code i made this.
CustomButton btn = new CustomButton();
btn.selectBoutonCommand = new SelectedBoutonCommand(selectbouton);
public void selectBouton()
{
Here i wan't to get my clicked bouton name to throw a task by context.
}
I have read some exemple. but in noesis command, the parameter is a base component.
All exemples i read from xaml the parameter is an object.
I really misunderstand some thing, i have to read more !
-
-
sfernandez
Site Admin
- Posts: 3222
- Joined:
Re: button binding command with parameter
Hi,
As wckdspn indicated, you should be able to bind the CommandParameter property to almost anything in your UI design.
The parameter is not used by our DelegateCommand class, but you can create your own command class that handles this parameter. For example:
Your View Model would expose the command the same as in our Commands example:
And you specify the command parameter the way you want, for example by binding to a TextBox.Text:
As wckdspn indicated, you should be able to bind the CommandParameter property to almost anything in your UI design.
The parameter is not used by our DelegateCommand class, but you can create your own command class that handles this parameter. For example:
Code: Select all
[Noesis.Extended]
public class MyCommand : Noesis.BaseCommand
{
private readonly Action<Noesis.BaseComponent> action;
public MyCommand(Action<Noesis.BaseComponent> action)
{
this.action = action;
}
public bool CanExecuteCommand(Noesis.BaseComponent parameter)
{
return parameter != null;
}
public void ExecuteCommand(Noesis.BaseComponent parameter)
{
action(parameter);
}
}
Code: Select all
[Noesis.Extended]
public class ViewModel : Noesis.SerializableComponent
{
string _input = string.Empty;
public string Input
{
get
{
return _input;
}
set
{
_input = value;
}
}
private string _output = string.Empty;
public string Output
{
get
{
return _output;
}
set
{
if (_output != value)
{
_output = value;
NotifyPropertyChanged("Output");
}
}
}
public MyCommand SayHelloCommand
{
get;
private set;
}
public ViewModel()
{
SayHelloCommand = new MyCommand(SayHello);
}
private void SayHello(Noesis.BaseComponent parameter)
{
Output = System.String.Format("[{0}] Hello, {1}", parameter.AsString(), Input);
}
}
Code: Select all
<Grid
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:noesis="clr-namespace:Noesis.Samples">
<Grid.Resources>
<noesis:ViewModel x:Key="ViewModel"/>
</Grid.Resources>
<Viewbox>
<Border x:Name="myBorder" DataContext="{StaticResource ViewModel}" Width="400" Margin="50"
Background="#801C1F21" BorderThickness="1" CornerRadius="5" BorderBrush="#D0101611" Padding="5"
HorizontalAlignment="Center" VerticalAlignment="Center">
<StackPanel Orientation="Vertical">
<TextBox MinWidth="300" Margin="3" Text="{Binding Input, Mode=TwoWay}" FontSize="28"/>
<TextBox x:Name="Param" MinWidth="300" Margin="3" Text="1" FontSize="24"/>
<Button Content="Say Hello" Margin="3" Command="{Binding SayHelloCommand}" CommandParameter="{Binding Text, ElementName=Param}" FontSize="28" />
<Viewbox Margin="5" Height="50">
<TextBlock Margin="5" Padding="0" TextAlignment="Center" Text="{Binding Output}" FontSize="28" Foreground="White"/>
</Viewbox>
</StackPanel>
</Border>
</Viewbox>
</Grid>
-
- picpic2006
- Posts: 71
- Joined:
Re: button binding command with parameter
Thanks you very much,
I will try to reproduce it. I think it is a good idee to make this in the showcase exemples in forums.
You just save to me a lot of times, i tryed yesterday with this exemple and it was not working. I was close in off but i writed not correctly my command.
http://stackoverflow.com/questions/1728 ... er-in-xaml
I will try to reproduce it. I think it is a good idee to make this in the showcase exemples in forums.
You just save to me a lot of times, i tryed yesterday with this exemple and it was not working. I was close in off but i writed not correctly my command.
http://stackoverflow.com/questions/1728 ... er-in-xaml
-
- picpic2006
- Posts: 71
- Joined:
Re: button binding command with parameter
Thanks it work very well, my problem is clearly my understood of c# part and xaml.
I have a long learning curve with noesis but i really love this plugin, it is clearly a great addition for unity.
I don't know today how the new gui system will be. I'm a little perplex.
But I will continue to work with noesis for sure !
Thanks again.
I have a long learning curve with noesis but i really love this plugin, it is clearly a great addition for unity.
I don't know today how the new gui system will be. I'm a little perplex.
But I will continue to work with noesis for sure !
Thanks again.
Re: button binding command with parameter
Thanks for your comments!
By the way, you are right, we should improve our documentation/samples to include this scenario.
By the way, you are right, we should improve our documentation/samples to include this scenario.
Who is online
Users browsing this forum: Ahrefs [Bot], Google [Bot] and 5 guests