01-13-2013 01:19 PM
Does anyone know what magic is required to get the WPF LED control to take a click? I have added a click handler to the XAML file and the handler in the .cs file. But this never fires!
Measurement Studio 2012 12.0.0.318
Visual Studio 2010
Here is the XAML code:
<Window x:Class="TestNILedControl.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:ni="http://schemas.ni.com/controls/2009/xaml/presentation" Title="MainWindow" Height="480" Width="640" > <DockPanel > <Button Content="Button" Height="23" Name="button1" Width="75" DockPanel.Dock="Top" Margin="30" Click="button1_Click" /> <ni:LED Click="led1_Click" FalseContent="Off" Height="23" Name="led1" TrueContent="On" Width="23" DockPanel.Dock="Top" Padding="0" Margin="30" ValueChanged="led1_ValueChanged" /> <TextBlock Height="26" Name="textBlock1" Text="Control clicked:" Width="208" /> </DockPanel> </Window>
And the sample code:
using NationalInstruments;
using NationalInstruments.NI4882;
using NationalInstruments.Controls;
using NationalInstruments.Controls.Rendering;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace TestNILedControl
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void button1_Click(object sender, RoutedEventArgs e)
{
textBlock1.Text = "Control Clicked: Button";
}
private void led1_ValueChanged(object sender, RoutedPropertyChangedEventArgs<bool> e)
{
textBlock1.Text = "Control Clicked: LED";
}
private void led1_Click(object sender, RoutedEventArgs e)
{
textBlock1.Text = "Control Clicked: LED";
}
}
}
Any help would be really appreciated. I have 100 LEDs on a DockPanel in my app and they need to be clickable.
Also if anyone knows how to include the WinForm LedArray into a WPF application I would love to know.
Thanks!
Doug
01-14-2013 09:37 AM
By default, the LED functions as a pure indicator and does not have interaction enabled. You can set the IsReadOnly property to false to enable interaction.
Regarding the LedArray, one option would be to use a WPF ItemsControl with an ItemTemplate containing an LED. Otherwise, I would suggest the Hosting a Windows Forms Control in WPF walkthrough.
01-14-2013 10:34 AM
Thank you, Paul! So simple. So very simple. Crud.
Doug