MSDN Magazine Launch Issue - February 15, 2008 - (Page 61) Figure 12 UpdateChart Method and CheckChanged Event private void UpdateChart() { if (showChart.Checked) { if ((currentXData != null) && (currentYData != null)) { salesChart1.UpdateWPFChart( currentCompany, currentXData, currentYData); salesChart1.Visibility = System.Windows.Visibility.Visible; } else { salesChart1.Visibility = System.Windows.Visibility.Hidden; } } else { salesChart1.Visibility = System.Windows.Visibility.Hidden; } } private void checkBox1_CheckedChanged(object sender, EventArgs e) { UpdateChart(); } Second, in the RecentSales_FormRegionShowing method (which essentially invokes whatever code you add to it when Outlook loads the custom form region) I’ve set the visibility of the WPF sales chart to hidden by default when Outlook loads the form region: private void RecentSales_FormRegionShowing(object sender, System.EventArgs e) { salesChart1.Visibility = System.Windows.Visibility.Hidden; } essentially takes a chart title (company name) and two string arrays representing sales data as parameters, and it scales the chart according to this data and updates the chart’s text and bar indicators, as shown in Figure 11. At this point, all of the controls for the form region are finished, so you can now return to the Outlook Replacement form region designer, where we will add the controls just created and wire them up to our custom form region. Next, the UpdateChart method (remember this method from above) uses the sales and company data to call the UpdateWPFChart method and update the data that’s presented in the sales chart— the WPF-based bars that indicate sales amounts. Note that we’ve also got an event handler, which responds to the click events from the checkbox and calls the UpdateChart method. Figure 12 shows the code for both the UpdateChart method and the checkbox’s CheckChanged event. Lastly, I have a method to handle data changed events on the SalesSearch control. My method updates the sales and company data and then it calls UpdateChart: private void salesSearch1_SalesDataChangeEvent(object sender, SalesControlLibrary.SalesSearchEventArgs e) { currentCompany = e.CompanyName; currentXData = e.XValues; currentYData = e.YValues; UpdateChart(); } Adding the Final Piece Building and Running the Custom Replacement Form Region The last step is to add the controls to the form region and then connect the code in the custom Outlook Replacement form region to our SalesSearch control and WPF chart control. To add the SalesSearch control and the WPF control to the form region, build all of the components in your project—this action will add the controls to your toolbox so that you can drag them onto the designer surface. Drag both the SalesSearch control and the WPF chart control to where you want them on the designer surface of your form region. With the controls in place, I can now create the code that will connect these controls with the form region and with each other. First, in the RecentSales class I’ve added some important variable declarations representing the sales (year and amount of sales) and company data: partial class RecentSales { string[] currentXData; double[] currentYData; string currentCompany; } With the code now in place, let’s build and run the project. To build and run Outlook add-ins, you’ll need to close all running instances of Outlook. If you open the Designer view for the custom form region, you should see something similar to Figure 13. You can Figure 13 Final Custom Replacement Form Region Office Business Applications launch2008 61
For optimal viewing of this digital publication, please enable JavaScript and then refresh the page. If you would like to try to load the digital publication without using Flash Player detection, please click here.