This project is read-only.

Exceute code behind help

Mar 16, 2010 at 10:07 AM

Hi

Just starting out on my first WPF app (coming from asp.net) and had a couple of simple (if not daft) questions:

1. If a create a ribbonbuttoon for printing (<Fluent:Button Name="buttonPrint" Text="Green" Icon="Images\Print.png" LargeIcon="Images\PrintLarge.png" />) how to I get it excute a code behind procedure (any examples e.g. onclick="Print:abel")?

2. If I make the button inactive how can I then make it active from code behind - so that the label is only printed when there is data to print (similar to buttonPrint.enabled = true)?

Thanks

Chooch

 

Mar 16, 2010 at 10:34 AM
Edited Mar 16, 2010 at 10:37 AM

Hello, Chooch.

1) Use Click event, for example, in XAML:

<Fluent.Button Text="Print" Click="OnPrintClick"/>

In code:

void OnPrintClick(object sender, RoutedEventArgs e)
{
       MessageBox.Show("Print");
}

2) I'm not sure I get you right. Set buttonPrint.IsEnabled in code behind

Daniel

Mar 16, 2010 at 10:51 AM

Hi Daniel

Wow, fast reply, much appreciated.

For 2.  the scenario is : I need to print a barcode label but only if there is data present in a datable. So by default I would like the printbutton to be inactive, when application loads. Once the datatable is populated, the "printbutton"  then becomes active to the user to press.

Thanks

Chooch

 

Mar 16, 2010 at 11:24 AM

I would use MVVM way and just bind buttonPrint IsEnabled to one of ViewModel property.
In your case you can just write something like:

<Fluent.Button x:Name="buttonPrint" Text="Print" Click="OnPrintClick" IsEnabled="False"/>

In code:

void LoadDatatable()
{
    ...
    buttonPrint.IsEnabled = true;
}

Daniel

 

Mar 16, 2010 at 2:08 PM

Hi Daniel

Thanks very much.

Chooch