private void LoadDevice() { foreach (ChannelInfoControl child in Channels.Children.OfType <ChannelInfoControl>()) { child.ToggleStateClicked -= ChannelControl_ToggleStateClicked; } Channels.Children.Clear(); IRelayDeviceInfo device = GetCurrentDevice(); if (device == null) { return; } using (var relayController = new RelayController()) { relayController.ConnectDevice(device); List <IRelayChannelInfo> channels = relayController.ListChannels(device); foreach (var channel in channels) { var channelControl = new ChannelInfoControl(device, channel); channelControl.ToggleStateClicked += ChannelControl_ToggleStateClicked; Channels.Children.Add(channelControl); } } }